mod(element/scrollable): ensure minSize returns correct dimensions
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 56s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 56s
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.
This commit is contained in:
@@ -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*.
|
||||
|
||||
Reference in New Issue
Block a user