From 836d7669e58581af72b98fa802962a597fd66a13 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sun, 18 Jan 2026 13:36:03 +0100 Subject: [PATCH] feat: introduce growth options `.horizontal_only` and `.vertical_only` Growing containers only in one specific direction while fixing the other dimension (which is then required to be provided - just like before). --- src/container.zig | 28 +++++++++++++++++++--------- src/element.zig | 4 ++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/container.zig b/src/container.zig index e773fa5..1a0b069 100644 --- a/src/container.zig +++ b/src/container.zig @@ -599,9 +599,11 @@ pub const Layout = packed struct { /// Sizing options which should be used by the `Container` pub const Size = packed struct { dim: Point = .{}, - grow: enum(u2) { + grow: enum(u3) { both, fixed, + vertical_only, + horizontal_only, vertical, horizontal, } = .both, @@ -732,11 +734,11 @@ pub fn Container(Model: type, Event: type) type { assert(this.properties.size.dim.y > 0 or size.y > 0); break :blk .max(size, this.properties.size.dim); }, - .horizontal => blk: { + .horizontal, .horizontal_only => blk: { assert(this.properties.size.dim.y > 0 or size.y > 0); break :blk .max(size, this.properties.size.dim); }, - .vertical => blk: { + .vertical, .vertical_only => blk: { assert(this.properties.size.dim.x > 0 or size.x > 0); break :blk .max(size, this.properties.size.dim); }, @@ -799,21 +801,21 @@ pub fn Container(Model: type, Event: type) type { if (growable_children == 0) first_growable_child = child; growable_children += 1; }, - .horizontal => if (layout.direction == .horizontal) { + .horizontal, .horizontal_only => if (layout.direction == .horizontal) { if (growable_children == 0) first_growable_child = child; growable_children += 1; }, - .vertical => if (layout.direction == .vertical) { + .vertical, .vertical_only => if (layout.direction == .vertical) { if (growable_children == 0) first_growable_child = child; growable_children += 1; }, } // non layout direction side growth switch (layout.direction) { - .horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .both) { + .horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .vertical_only or child.properties.size.grow == .both) { child.size.y = available; }, - .vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .both) { + .vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .vertical_only or child.properties.size.grow == .both) { child.size.x = available; }, } @@ -831,8 +833,8 @@ pub fn Container(Model: type, Event: type) type { if (child.properties.size.grow == .fixed) continue; switch (layout.direction) { - .horizontal => if (child.properties.size.grow == .vertical) continue, - .vertical => if (child.properties.size.grow == .horizontal) continue, + .horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .vertical_only) continue, + .vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .horizontal_only) continue, } const size = switch (layout.direction) { @@ -898,6 +900,14 @@ pub fn Container(Model: type, Event: type) type { this.size = switch (this.properties.size.grow) { .both => .max(size, fit_size), .fixed => fit_size, + .horizontal_only => .{ + .x = size.x, + .y = fit_size.y, + }, + .vertical_only => .{ + .x = fit_size.x, + .y = size.y, + }, .horizontal => .{ .x = @max(size.x, fit_size.x), .y = size.y, diff --git a/src/element.zig b/src/element.zig index 6d9e580..fcda7ee 100644 --- a/src/element.zig +++ b/src/element.zig @@ -219,8 +219,8 @@ pub fn Alignment(Model: type, Event: type) type { outer: for (0..csize.y) |row| { inner: for (0..csize.x) |col| { // do not read/write out of bounce - if (this.size.x < row) break :outer; - if (this.size.y < col) break :inner; + if (this.size.y < row) break :outer; + if (this.size.x < col) break :inner; cells[((row + origin.y) * size.x) + col + origin.x] = container_cells[(row * csize.x) + col]; }