DVUI

deinit

Parameters

#
self:*BoxWidget
*BoxWidget

Source

Implementation

#
pub fn deinit(self: *BoxWidget) void {
    defer if (dvui.widgetIsAllocated(self)) dvui.widgetFree(self);
    defer self.* = undefined;
    const extra_space = (if (self.init_opts.dir == .horizontal) self.child_rect.w else self.child_rect.h) > 0.001;
    const ms: Size = if (self.init_opts.dir == .horizontal) .{
        .w = if (self.init_opts.equal_space)
            self.max_space * self.packed_children
        else
            self.min_space_taken,
        .h = self.max_thick,
    } else .{
        .h = if (self.init_opts.equal_space)
            self.max_space * self.packed_children
        else
            self.min_space_taken,
        .w = self.max_thick,
    };

    if ((self.init_opts.equal_space and self.packed_children > 0) or self.total_weight > 0) {
        if (extra_space) {
            // we have expanded children, but didn't use all the space:
            // - maybe lost a child
            // - maybe one is no longer expanded
            // - maybe one's min size shrunk (label changing text)
            // equal_space could mean we don't exactly use all the space (due to floating point)
            dvui.refresh(null, @src(), self.data().id);
        }

        if (!self.init_opts.equal_space and self.pixels_per_w > 0 and self.ran_off) {
            // we have expanded children, thought we had extra space, but ran
            // off the end:
            // - maybe one's min size got bigger (label changing text)
            dvui.refresh(null, @src(), self.data().id);
        }

        // if total_weight is 0, we are tight around all children, so our min
        // size will be sensitive to theirs and handle normal changes in
        // minSizeSetAndRefresh()
    }

    self.data().minSizeMax(self.data().options.padSize(ms));

    self.data().minSizeSetAndRefresh();
    self.data().minSizeReportToParent();

    dvui.dataSet(null, self.data().id, "_data", Data{ .packed_children = self.packed_children, .total_weight = self.total_weight, .min_space_taken = self.min_space_taken });

    dvui.parentReset(self.data().id, self.data().parent);
}