pub struct Constraints {
pub min_w: f32,
pub max_w: f32,
pub min_h: f32,
pub max_h: f32,
}Expand description
Min/max size bounds passed from parent to child during layout.
§Examples
use ailloli_ui_core::{Constraints, Size};
assert_eq!(Constraints::loose(100.0, 80.0).constrain(Size::new(120.0, 20.0)), Size::new(100.0, 20.0));Fields§
§min_w: f32Minimum width in logical pixels.
max_w: f32Maximum width in logical pixels; infinity represents an unbounded axis.
min_h: f32Minimum height in logical pixels.
max_h: f32Maximum height in logical pixels; infinity represents an unbounded axis.
Implementations§
Source§impl Constraints
impl Constraints
Sourcepub fn tight(w: f32, h: f32) -> Self
pub fn tight(w: f32, h: f32) -> Self
Creates fixed bounds on both axes (min == max).
Values are stored verbatim; callers should provide non-negative finite dimensions for an ordinary tight layout constraint.
§Examples
use ailloli_ui_core::Constraints;
let c = Constraints::tight(40.0, 20.0);
assert_eq!((c.min_w, c.max_w), (40.0, 40.0));Sourcepub fn loose(max_w: f32, max_h: f32) -> Self
pub fn loose(max_w: f32, max_h: f32) -> Self
Creates zero minimums and caller-supplied maximums.
Despite the name, an axis is truly unbounded only when its maximum is
f32::INFINITY.
§Examples
use ailloli_ui_core::Constraints;
let c = Constraints::loose(40.0, 20.0);
assert_eq!((c.min_w, c.max_w), (0.0, 40.0));Sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Returns bounds with each axis ordered as min <= max.
Infinities participate in the ordering. If exactly one bound on an axis
is NaN, floating-point min/max replace both results with the other
bound; two NaN bounds remain NaN.
§Examples
use ailloli_ui_core::Constraints;
let c = Constraints { min_w: 20.0, max_w: 10.0, min_h: 0.0, max_h: 30.0 }.normalized();
assert_eq!((c.min_w, c.max_w), (10.0, 20.0));Sourcepub fn constrain(&self, size: Size) -> Size
pub fn constrain(&self, size: Size) -> Size
Clamps size to this normalized constraint box.
§Panics
Panics if either normalized interval contains NaN, because
f32::clamp requires ordered non-NaN bounds.
§Examples
use ailloli_ui_core::{Constraints, Size};
assert_eq!(Constraints::loose(10.0, 20.0).constrain(Size::new(40.0, 5.0)), Size::new(10.0, 5.0));Sourcepub fn max_size(&self) -> Size
pub fn max_size(&self) -> Size
Returns the stored maximum dimensions without normalizing them.
§Examples
use ailloli_ui_core::{Constraints, Size};
assert_eq!(Constraints::loose(10.0, 20.0).max_size(), Size::new(10.0, 20.0));Sourcepub fn loosen(&self) -> Self
pub fn loosen(&self) -> Self
Returns the stored maximums with both minimums reset to zero.
§Examples
use ailloli_ui_core::Constraints;
assert_eq!(Constraints::tight(10.0, 20.0).loosen().min_w, 0.0);Sourcepub fn tighten(&self, size: Size) -> Self
pub fn tighten(&self, size: Size) -> Self
Narrows constraints to exactly size after clamping it to current bounds.
§Examples
use ailloli_ui_core::{Constraints, Size};
let c = Constraints::loose(10.0, 20.0).tighten(Size::new(40.0, 5.0));
assert_eq!((c.min_w, c.max_w), (10.0, 10.0));Sourcepub fn deflate(&self, by: EdgeInsets) -> Self
pub fn deflate(&self, by: EdgeInsets) -> Self
Subtracts horizontal and vertical insets from every matching bound.
Results are floored at zero. Negative insets expand rather than shrink the bounds. A NaN or negative-infinite subtraction result becomes zero, while positive infinity remains infinite.
§Examples
use ailloli_ui_core::{Constraints, EdgeInsets};
let c = Constraints::tight(100.0, 80.0).deflate(EdgeInsets::all(10.0));
assert_eq!((c.max_w, c.max_h), (80.0, 60.0));Trait Implementations§
Source§impl Clone for Constraints
impl Clone for Constraints
Source§fn clone(&self) -> Constraints
fn clone(&self) -> Constraints
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more