fix(layout): remove upper bound of while loop
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
The upper loop was incorrect and therefore removed to create correct layouts. I should be able to calculate the bound correctly, but for now).
This commit is contained in:
@@ -343,6 +343,7 @@ 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) {
|
||||
@@ -352,15 +353,12 @@ pub const Layout = packed struct {
|
||||
};
|
||||
const gap: u16 = (this.gap + 1) / 2;
|
||||
|
||||
log.debug("origin: {any}, size: {any}", .{ origin, size });
|
||||
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),
|
||||
};
|
||||
log.debug("child.origin: {any}, child.size: {any}", .{ child.origin, child.size });
|
||||
log.debug("anchor: {d}", .{anchor});
|
||||
|
||||
switch (this.direction) {
|
||||
.horizontal => for (0..child.size.y) |row| {
|
||||
@@ -696,11 +694,13 @@ pub fn Container(comptime Event: type) type {
|
||||
.y = @max(size.y, this.properties.size.dim.y),
|
||||
},
|
||||
};
|
||||
log.debug("fit_size returning: {any}", .{this.size});
|
||||
return this.size;
|
||||
}
|
||||
|
||||
// growable implicitly requires the root `Container` to have a set a size property to the size of the available terminal screen
|
||||
fn grow_resize(this: *@This(), max_size: Point) void {
|
||||
log.debug("grow_size: {any}", .{this.size});
|
||||
const layout = this.properties.layout;
|
||||
var remainder = switch (layout.direction) {
|
||||
.horizontal => max_size.x -| (layout.padding.left + layout.padding.right),
|
||||
@@ -764,8 +764,7 @@ pub fn Container(comptime Event: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
var count: usize = this.elements.items.len;
|
||||
while (growable_children > 0 and remainder > 0 and count > 0) : (count -|= 1) {
|
||||
while (growable_children > 0 and remainder > 0) {
|
||||
var smallest_size = switch (layout.direction) {
|
||||
.horizontal => first_growable_child.size.x,
|
||||
.vertical => first_growable_child.size.y,
|
||||
@@ -836,7 +835,6 @@ pub fn Container(comptime Event: type) type {
|
||||
pub fn resize(this: *@This(), origin: Point, size: Point) void {
|
||||
// NOTE assume that this function is only called for the root `Container`
|
||||
const fit_size = this.fit_resize();
|
||||
log.debug("fit_size: {any}; size: {any}", .{ fit_size, size });
|
||||
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
|
||||
switch (this.properties.size.grow) {
|
||||
.both => this.size = Point.max(size, fit_size),
|
||||
@@ -850,7 +848,6 @@ pub fn Container(comptime Event: type) type {
|
||||
.y = @max(size.y, fit_size.y),
|
||||
},
|
||||
}
|
||||
log.debug("this.size: {any}", .{this.size});
|
||||
this.grow_resize(this.size);
|
||||
this.reposition(origin);
|
||||
}
|
||||
@@ -874,7 +871,6 @@ pub fn Container(comptime Event: type) type {
|
||||
@memset(cells, .{});
|
||||
errdefer this.allocator.free(cells);
|
||||
|
||||
log.debug("contents: this.size: {any}", .{this.size});
|
||||
this.properties.layout.contents(@This(), cells, this.origin, this.size, this.elements.items);
|
||||
this.properties.border.contents(cells, this.size);
|
||||
this.properties.rectangle.contents(cells, this.size);
|
||||
|
||||
Reference in New Issue
Block a user