From 41229c13d3e8bcbfef7678ddada4eb92b68071f1 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Fri, 28 Nov 2025 14:27:41 +0100 Subject: [PATCH] mod(container): provide `minSize` function for `Element` implementation to refer for nested structures --- src/container.zig | 18 ++++++++++++++++++ src/element.zig | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/container.zig b/src/container.zig index 11f37d4..9880acf 100644 --- a/src/container.zig +++ b/src/container.zig @@ -906,6 +906,24 @@ pub fn Container(Model: type, Event: type) type { this.grow_resize(model, this.size); } + pub fn minSize(this: *const @This(), model: *const Model, size: Point) Point { + var min_size = this.element.minSize(model, size); + for (this.elements.items) |child| { + const child_size = child.minSize(model, child.properties.size.dim); + min_size = switch (this.properties.layout.direction) { + .horizontal => .{ + .x = child_size.x + min_size.x, + .y = @max(child_size.y, min_size.y), + }, + .vertical => .{ + .x = @max(child_size.x, min_size.x), + .y = child_size.y + min_size.y, + }, + }; + } + return min_size; + } + pub fn handle(this: *const @This(), model: *Model, event: Event) !void { switch (event) { .mouse => |mouse| if (mouse.in(this.origin, this.size)) { diff --git a/src/element.zig b/src/element.zig index ca4d723..74b4769 100644 --- a/src/element.zig +++ b/src/element.zig @@ -303,7 +303,7 @@ pub fn Scrollable(Model: type, Event: type) type { const last_max_anchor_y = this.container_size.y -| this.size.y; // NOTE `container_size` denotes the `size` required for the container contents - var container_size = this.container.element.minSize(model, size); + var container_size = this.container.minSize(model, size); if (this.configuration.scrollbar) { this.configuration.y_axis = this.container.properties.size.dim.x > size.x or container_size.x > size.x; this.configuration.x_axis = this.container.properties.size.dim.y > size.y or container_size.y > size.y;