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 {
|
} 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,
|
||||||
},
|
},
|
||||||
}, .{}));
|
}, .{}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
switch (child.properties.size.grow) {
|
||||||
|
.fixed => continue,
|
||||||
|
.both => {
|
||||||
if (growable_children == 0) first_growable_child = child;
|
if (growable_children == 0) first_growable_child = child;
|
||||||
growable_children += 1;
|
growable_children += 1;
|
||||||
|
|
||||||
switch (layout.direction) {
|
|
||||||
.horizontal => if (child.properties.size.grow != .vertical) {
|
|
||||||
child.size.y = available;
|
|
||||||
},
|
},
|
||||||
.vertical => if (child.properties.size.grow != .horizontal) {
|
.horizontal => if (layout.direction == .horizontal) {
|
||||||
child.size.x = available;
|
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