pub struct BoxConstraints { /* private fields */ }Expand description
Constraints for layout.
The layout strategy for Masonry is strongly inspired by Flutter, and this struct is similar to the Flutter BoxConstraints class.
At the moment, it represents simply a minimum and maximum size.
A widget’s layout method should choose an appropriate size that
meets these constraints.
Further, a container widget should compute appropriate constraints for each of its child widgets, and pass those down when recursing.
Implementations§
Source§impl BoxConstraints
impl BoxConstraints
Sourcepub const UNBOUNDED: Self
pub const UNBOUNDED: Self
An unbounded box constraints object.
Can be satisfied by any nonnegative size.
Sourcepub fn new(min: Size, max: Size) -> Self
pub fn new(min: Size, max: Size) -> Self
Create a new box constraints object.
Create constraints based on minimum and maximum size.
Sourcepub fn tight(size: Size) -> Self
pub fn tight(size: Size) -> Self
Create a “tight” box constraints object.
A “tight” constraint can only be satisfied by a single size.
Sourcepub fn loosen(&self) -> Self
pub fn loosen(&self) -> Self
Create a “loose” version of the constraints.
Make a version with zero minimum size, but the same maximum size.
Sourcepub fn constrain(&self, size: impl Into<Size>) -> Size
pub fn constrain(&self, size: impl Into<Size>) -> Size
Clamp a given size so that it fits within the constraints.
Sourcepub fn is_width_bounded(&self) -> bool
pub fn is_width_bounded(&self) -> bool
Whether there is an upper bound on the width.
Sourcepub fn is_height_bounded(&self) -> bool
pub fn is_height_bounded(&self) -> bool
Whether there is an upper bound on the height.
Sourcepub fn bounded_or(&self, size: Size) -> Size
pub fn bounded_or(&self, size: Size) -> Size
Return the max in each axis if bounded, else the value given in size.
Sourcepub fn debug_check(&self, name: &str)
pub fn debug_check(&self, name: &str)
Check to see if these constraints are legit.
In Debug mode, logs a warning if BoxConstraints are invalid.
Sourcepub fn contains(&self, size: impl Into<Size>) -> bool
pub fn contains(&self, size: impl Into<Size>) -> bool
Test whether these constraints contain the given Size.
Sourcepub fn constrain_aspect_ratio(&self, aspect_ratio: f64, width: f64) -> Size
pub fn constrain_aspect_ratio(&self, aspect_ratio: f64, width: f64) -> Size
Find the Size within these BoxConstraints that minimises the difference between the
returned Size’s aspect ratio and aspect_ratio, where aspect ratio is defined as
height / width.
If multiple Sizes give the optimal aspect_ratio, then the one with the width nearest
the supplied width will be used. Specifically, if width == 0.0 then the smallest possible
Size will be chosen, and likewise if width == f64::INFINITY, then the largest Size
will be chosen.
Use this function when maintaining an aspect ratio is more important than minimizing the distance between input and output size width and height.
§Panics
Panics if aspect_ratio or width are NaN, infinite or negative.