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*.