From 7cd1fb139fbf45a3d99f8359dda0d198a283249a Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sat, 1 Nov 2025 14:37:14 +0100 Subject: [PATCH] mod(element/scrollable): ensure `minSize` returns correct dimensions Enforce that `minSize` returns a `Point` with corresponding minimal dimensions with respect to the provided available size. This means that an `Element` implementation that provides a `minSize` function may even return a too small dimension, which would automatically be resized to be at least as big as the provided size. --- src/element.zig | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/element.zig b/src/element.zig index bdb5679..75c3af1 100644 --- a/src/element.zig +++ b/src/element.zig @@ -23,15 +23,26 @@ pub fn Element(Model: type, Event: type) type { }; /// Request the minimal size required for this `Element` the provided - /// available *size* can be used as a fallback. This is currently only - /// used for `Scrollable` elements, such that the nested element in - /// the `Scrollable`'s `Container` can request a minimal size for its - /// contents. + /// available *size* can be used as a fallback. This function ensures + /// that the minimal size returned has at least the dimensions of the + /// available *size*. + /// + /// If the associated `Container`'s size is known at compile time (and + /// does not change) the size can be directly provided through the + /// `.size` Property for the `Container` instead. In this case you + /// should not implement / use this function. + /// + /// Currently only used for `Scrollable` elements, such that the + /// directly nested element in the `Scrollable`'s `Container` can + /// request a minimal size for its contents. pub inline fn minSize(this: @This(), size: Point) Point { - return if (this.vtable.minSize) |minSize_fn| - minSize_fn(this.ptr, size) - else - size; + if (this.vtable.minSize) |minSize_fn| { + const min_size = minSize_fn(this.ptr, size); + return .{ + .x = @max(size.x, min_size.x), + .y = @max(size.y, min_size.y), + }; + } else return size; } /// Resize the corresponding `Element` with the given *size*.