fix(container): growth options to dynamically size Containers
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 29s

This commit is contained in:
2025-03-06 22:31:00 +01:00
parent 5457e91b37
commit 54c7e19939
2 changed files with 26 additions and 14 deletions

View File

@@ -73,8 +73,8 @@ pub fn main() !void {
} else { } else {
try column.append(try App.Container.init(allocator, .{ try column.append(try App.Container.init(allocator, .{
.size = .{ .size = .{
.dim = .{ .y = 5 }, .dim = .{ .y = 4 },
// .grow = .horizontal, .grow = .horizontal,
}, },
}, .{})); }, .{}));
} }

View File

@@ -750,18 +750,30 @@ pub fn Container(comptime Event: type) type {
var growable_children: usize = 0; var growable_children: usize = 0;
var first_growable_child: *@This() = undefined; var first_growable_child: *@This() = undefined;
for (this.elements.items) |*child| { for (this.elements.items) |*child| {
if (child.properties.size.grow != .fixed) { // layout direction side growth
if (growable_children == 0) first_growable_child = child; switch (child.properties.size.grow) {
growable_children += 1; .fixed => continue,
.both => {
switch (layout.direction) { if (growable_children == 0) first_growable_child = child;
.horizontal => if (child.properties.size.grow != .vertical) { growable_children += 1;
child.size.y = available; },
}, .horizontal => if (layout.direction == .horizontal) {
.vertical => if (child.properties.size.grow != .horizontal) { if (growable_children == 0) first_growable_child = child;
child.size.x = available; growable_children += 1;
}, },
} .vertical => if (layout.direction == .vertical) {
if (growable_children == 0) first_growable_child = child;
growable_children += 1;
},
}
// non layout direction side growth
switch (layout.direction) {
.horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .both) {
child.size.y = available;
},
.vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .both) {
child.size.x = available;
},
} }
} }