fix(container/grow_size): children should never grow larger then parents
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:
@@ -54,7 +54,6 @@ pub fn main() !void {
|
||||
.layout = .{
|
||||
.gap = 2,
|
||||
.padding = .{ .top = 5, .bottom = 3, .left = 3, .right = 3 },
|
||||
.direction = .horizontal,
|
||||
},
|
||||
}, element);
|
||||
for (0..3) |i| {
|
||||
|
||||
@@ -343,7 +343,6 @@ pub const Layout = packed struct {
|
||||
|
||||
pub fn contents(this: @This(), comptime C: type, cells: []Cell, origin: Point, size: Point, children: []const C) void {
|
||||
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
_ = origin;
|
||||
|
||||
if (this.separator.enabled and children.len > 1) {
|
||||
const line_cps: [2]u21 = switch (this.separator.line) {
|
||||
@@ -356,8 +355,8 @@ pub const Layout = packed struct {
|
||||
for (0..children.len - 1) |idx| {
|
||||
const child = children[idx];
|
||||
const anchor = switch (this.direction) {
|
||||
.horizontal => (@as(usize, child.origin.y) * @as(usize, size.x)) + @as(usize, child.origin.x) + @as(usize, child.size.x) + gap,
|
||||
.vertical => ((@as(usize, child.origin.y) + @as(usize, child.size.y) + gap) * @as(usize, size.x)) + @as(usize, child.origin.x),
|
||||
.horizontal => ((@as(usize, child.origin.y) - @as(usize, origin.y)) * @as(usize, size.x)) + @as(usize, child.origin.x) + @as(usize, child.size.x) + gap - @as(usize, origin.x),
|
||||
.vertical => ((@as(usize, child.origin.y) + @as(usize, child.size.y) + gap - @as(usize, origin.y)) * @as(usize, size.x)) + @as(usize, child.origin.x) - @as(usize, origin.x),
|
||||
};
|
||||
|
||||
switch (this.direction) {
|
||||
@@ -370,6 +369,10 @@ pub const Layout = packed struct {
|
||||
cells[anchor + col].style.fg = this.separator.color;
|
||||
},
|
||||
}
|
||||
|
||||
// DEBUG render corresponding beginning of the separator for this `Container` *red*
|
||||
// cells[anchor].style.fg = .red;
|
||||
// cells[anchor].style.bg = .red;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -739,12 +742,10 @@ pub fn Container(comptime Event: type) type {
|
||||
},
|
||||
}
|
||||
|
||||
for (this.elements.items) |child| {
|
||||
remainder -|= switch (layout.direction) {
|
||||
for (this.elements.items) |child| remainder -|= switch (layout.direction) {
|
||||
.horizontal => child.size.x,
|
||||
.vertical => child.size.y,
|
||||
};
|
||||
}
|
||||
|
||||
var growable_children: usize = 0;
|
||||
var first_growable_child: *@This() = undefined;
|
||||
@@ -829,7 +830,7 @@ pub fn Container(comptime Event: type) type {
|
||||
}
|
||||
|
||||
this.element.resize(this.size);
|
||||
for (this.elements.items) |*child| child.grow_resize(this.size);
|
||||
for (this.elements.items) |*child| child.grow_resize(child.size);
|
||||
}
|
||||
|
||||
pub fn resize(this: *@This(), origin: Point, size: Point) void {
|
||||
@@ -877,6 +878,10 @@ pub fn Container(comptime Event: type) type {
|
||||
|
||||
try this.element.content(cells, this.origin, this.size);
|
||||
|
||||
// DEBUG render corresponding top left corner of this `Container` *red*
|
||||
// cells[0].style.fg = .red;
|
||||
// cells[0].style.bg = .red;
|
||||
|
||||
return cells;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user