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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 29s
This commit is contained in:
@@ -73,8 +73,8 @@ pub fn main() !void {
|
||||
} else {
|
||||
try column.append(try App.Container.init(allocator, .{
|
||||
.size = .{
|
||||
.dim = .{ .y = 5 },
|
||||
// .grow = .horizontal,
|
||||
.dim = .{ .y = 4 },
|
||||
.grow = .horizontal,
|
||||
},
|
||||
}, .{}));
|
||||
}
|
||||
|
||||
@@ -750,18 +750,30 @@ pub fn Container(comptime Event: type) type {
|
||||
var growable_children: usize = 0;
|
||||
var first_growable_child: *@This() = undefined;
|
||||
for (this.elements.items) |*child| {
|
||||
if (child.properties.size.grow != .fixed) {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
growable_children += 1;
|
||||
|
||||
switch (layout.direction) {
|
||||
.horizontal => if (child.properties.size.grow != .vertical) {
|
||||
child.size.y = available;
|
||||
},
|
||||
.vertical => if (child.properties.size.grow != .horizontal) {
|
||||
child.size.x = available;
|
||||
},
|
||||
}
|
||||
// layout direction side growth
|
||||
switch (child.properties.size.grow) {
|
||||
.fixed => continue,
|
||||
.both => {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
growable_children += 1;
|
||||
},
|
||||
.horizontal => if (layout.direction == .horizontal) {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
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;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user