pub struct BoxConstraints { /* private fields */ }Expand description
Immutable min/max size bounds passed down during layout.
Invariant: both min and max are non-negative and min <= max
component-wise. This is enforced unconditionally by every constructor —
there is no way to construct a BoxConstraints that violates it, so
constrain can never panic.
Implementations§
Source§impl BoxConstraints
impl BoxConstraints
Sourcepub fn new(min: Size, max: Size) -> Self
pub fn new(min: Size, max: Size) -> Self
Construct constraints from explicit min/max bounds.
Both bounds are clamped to be non-negative. If max is smaller than
min on either axis (an inverted/inconsistent input), max is
widened up to min on that axis — min is authoritative — so the
resulting constraints always satisfy min <= max. Inverted input
usually indicates an upstream layout bug (e.g. padding subtraction
underflow), so debug builds print a diagnostic when this correction
fires; release builds correct silently.
Sourcepub fn tight(size: Size) -> Self
pub fn tight(size: Size) -> Self
Tight constraints that force an exact size (min == max == size).
Sourcepub fn constrain(&self, size: Size) -> Size
pub fn constrain(&self, size: Size) -> Size
Clamp size so it lies within [min, max] on both axes.