rectFor
Parameters
- self:*BasicLayout
- *BasicLayout
- contentRect:Rect
- Rect
- id:Id
- Id
- min_size:Size
- Size
- e:Options.Expand
- Options.Expand
- g:Options.Gravity
- Options.Gravity
Source
Implementation
pub fn rectFor(self: *BasicLayout, contentRect: Rect, id: Id, min_size: Size, e: Options.Expand, g: Options.Gravity) Rect {
if (self.seen_expanded) {
// A single vertically expanded child can take the rest of the
// space, but it should be the last (usually only) child.
//
// Here we have a child after an expanded one, so it will get no space.
//
// If you want that to work, wrap the children in a vertical box.
const cw = dvui.currentWindow();
dvui.log.err("{s}:{d} rectFor() got child {x} after expanded child", .{ @src().file, @src().line, id });
var iter = cw.current_parent.data().iterator();
while (iter.next()) |wd| {
dvui.log.debug(" {s}:{d} {s} {x}", .{
wd.src.file,
wd.src.line,
wd.options.name orelse "???",
wd.id,
});
dvui.Debug.errorOutline(wd.rectScale().r);
}
}
var r = contentRect;
switch (self.dir) {
.vertical => {
if (e.isVertical()) {
self.seen_expanded = true;
}
r.y += self.pos;
r.h = @max(0, r.h - self.pos);
},
.horizontal => {
if (e.isHorizontal()) {
self.seen_expanded = true;
}
r.x += self.pos;
r.w = @max(0, r.w - self.pos);
},
}
const ret = dvui.placeIn(r, min_size, e, g);
switch (self.dir) {
.vertical => self.pos += ret.h,
.horizontal => self.pos += ret.w,
}
return ret;
}