fix(element/scrollable): support deriving Container size of scrollable
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 13s

This commit is contained in:
2025-03-04 21:54:07 +01:00
parent fc72cf4abb
commit 466e00c16c
4 changed files with 25 additions and 36 deletions

View File

@@ -633,14 +633,13 @@ pub fn Container(comptime Event: type) type {
}
}
fn fit_resize(this: *@This()) Point {
pub fn fit_resize(this: *@This()) Point {
// NOTE this is supposed to be a simple and easy to understand alogrithm, there are currently no optimizations done
const layout = this.properties.layout;
var size: Point = switch (layout.direction) {
.horizontal => .{ .x = layout.gap * @as(u16, @truncate(this.elements.items.len -| 1)) },
.vertical => .{ .y = layout.gap * @as(u16, @truncate(this.elements.items.len -| 1)) },
};
size = Point.add(size, this.properties.size);
if (this.elements.items.len > 0) switch (layout.direction) {
.horizontal => size.x += layout.padding.left + layout.padding.right,
@@ -671,8 +670,8 @@ pub fn Container(comptime Event: type) type {
}
// assign currently calculated size
this.size = size;
return size;
this.size = Point.max(size, this.properties.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
@@ -818,6 +817,7 @@ pub fn Container(comptime Event: type) type {
}
pub fn contents(this: *const @This()) ![]const Cell {
if (this.size.x == 0 or this.size.y == 0) return Error.TooSmall;
const cells = try this.allocator.alloc(Cell, @as(usize, this.size.x) * @as(usize, this.size.y));
@memset(cells, .{});
errdefer this.allocator.free(cells);