From 315cd8d23e32cb8d423733fc0a377784b2301ca9 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Wed, 5 Mar 2025 23:14:54 +0100 Subject: [PATCH] fix(layout): remove upper bound of while loop The upper loop was incorrect and therefore removed to create correct layouts. I should be able to calculate the bound correctly, but for now). --- src/container.zig | 12 ++++-------- src/element.zig | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/container.zig b/src/container.zig index d7934e5..e5bf581 100644 --- a/src/container.zig +++ b/src/container.zig @@ -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); diff --git a/src/element.zig b/src/element.zig index 0a6eddb..98a6d6e 100644 --- a/src/element.zig +++ b/src/element.zig @@ -94,7 +94,9 @@ pub fn Scrollable(Event: type) type { this.size = size; // TODO scrollbar space - depending on configuration and only if necessary? + std.log.debug("----", .{}); this.container.resize(.{}, this.size); + std.log.debug("----", .{}); this.container_size = this.container.size; }