Struct Constraints

Source
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: f32

Minimum width in logical pixels.

§max_w: f32

Maximum width in logical pixels; infinity represents an unbounded axis.

§min_h: f32

Minimum height in logical pixels.

§max_h: f32

Maximum height in logical pixels; infinity represents an unbounded axis.

Implementations§

Source§

impl Constraints

Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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);
Source

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));
Source

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

Source§

fn clone(&self) -> Constraints

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Constraints

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Constraints

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.