DVUI

rectFor

Parameters

#
self:*PanedWidget
*PanedWidget
id:dvui.Id
dvui.Id
min_size:Size
Size
e:Options.Expand
Options.Expand
g:Options.Gravity
Options.Gravity

Source

Implementation

#
pub fn rectFor(self: *PanedWidget, id: dvui.Id, min_size: Size, e: Options.Expand, g: Options.Gravity) dvui.Rect {
    const handle_gap = self.handleGap();
    var r = self.data().contentRect().justSize();
    switch (self.init_opts.direction) {
        .horizontal => r.w -= handle_gap,
        .vertical => r.h -= handle_gap,
    }

    switch (self.active_side) {
        .none => {
            dvui.log.err("{s}:{d}: Paned widget {x} cannot add child widget {x} outside a first/second side", .{ self.data().src.file, self.data().src.line, self.data().id, id });
            // Highlight the widget in red
            dvui.Debug.errorOutline(self.data().rectScale().r);
            // Place within the entire content rect just so that the widget shows up on screen
            // (probably covered by the panes, but the red outline will show)
        },
        .first => if (self.collapsed()) {
            if (self.split_ratio.* == 0.0) {
                r.w = 0;
                r.h = 0;
            } else switch (self.init_opts.direction) {
                .horizontal => r.x -= (r.w - (r.w * self.split_ratio.*)),
                .vertical => r.y -= (r.h - (r.h * self.split_ratio.*)),
            }
        } else switch (self.init_opts.direction) {
            .horizontal => r.w = @max(0, r.w * self.split_ratio.*),
            .vertical => r.h = @max(0, r.h * self.split_ratio.*),
        },
        .second => if (self.collapsed()) {
            if (self.split_ratio.* == 1.0) {
                r.w = 0;
                r.h = 0;
            } else switch (self.init_opts.direction) {
                .horizontal => r.x = r.w * self.split_ratio.*,
                .vertical => r.y = r.h * self.split_ratio.*,
            }
        } else switch (self.init_opts.direction) {
            .horizontal => {
                const first = r.w * self.split_ratio.*;
                r.w = @max(0, r.w - first);
                r.x += first + handle_gap;
            },
            .vertical => {
                const first = r.h * self.split_ratio.*;
                r.h = @max(0, r.h - first);
                r.y += first + handle_gap;
            },
        },
    }

    return self.layout.rectFor(r, id, min_size, e, g);
}