Enum Length

Source
pub enum Length {
    Auto,
    Px(f32),
    Fill,
    Percent(f32),
}
Expand description

CSS-like length for layout axes (width, height, min/max).

Possible values are intrinsic Length::Auto, fixed Length::Px, parent fill, and Length::Percent.

§Examples

use ailloli_ui_core::style::Length;
assert_eq!(Length::percent(50.0).resolve(200.0), Some(100.0));

Variants§

§

Auto

Intrinsic size (children, text measure).

§

Px(f32)

Fixed logical pixels; resolution floors negative values and NaN at zero. Positive infinity remains infinite.

§

Fill

Fill the parent on this axis when resolved via Length::resolve.

In a flex main axis, parent layout treats Fill as remaining space (grow participant) instead of calling resolve with the full parent max.

§

Percent(f32)

Fraction of parent available space.

Direct construction stores the fraction verbatim; Length::percent accepts either fractional or percentage-style input.

Implementations§

Source§

impl Length

Source

pub fn px(value: f32) -> Self

Creates a fixed logical-pixel length without immediate normalization.

§Examples
use ailloli_ui_core::style::Length;
assert_eq!(Length::px(24.0), Length::Px(24.0));
Source

pub fn fill() -> Self

Fill parent on this axis (see Length::Fill).

§Examples
use ailloli_ui_core::style::Length;
assert_eq!(Length::fill(), Length::Fill);
Source

pub fn percent(value: f32) -> Self

Creates a percentage/fraction of parent available space.

Values with absolute magnitude at most 1.0 are treated as fractions, so 0.5 and 1.0 mean 50% and 100%. Larger magnitudes are divided by 100, so 50.0 also means 50%. Negative fractions resolve to zero.

§Examples
use ailloli_ui_core::style::Length;
assert_eq!(Length::percent(50.0), Length::Percent(0.5));
assert_eq!(Length::percent(0.5), Length::Percent(0.5));
Source

pub fn is_auto(self) -> bool

true when this axis uses intrinsic sizing.

§Examples
use ailloli_ui_core::style::Length;
assert!(Length::Auto.is_auto());
assert!(!Length::Fill.is_auto());
Source

pub fn resolve(self, available: f32) -> Option<f32>

Resolves against parent available logical pixels.

Self::Auto returns None. Fixed, fill, and percentage results are floored at zero; they are not capped to available. Non-finite results follow floating-point max semantics.

§Examples
use ailloli_ui_core::style::Length;

assert_eq!(Length::Auto.resolve(200.0), None);
assert_eq!(Length::px(24.0).resolve(200.0), Some(24.0));
assert_eq!(Length::percent(50.0).resolve(200.0), Some(100.0));
assert_eq!(Length::fill().resolve(200.0), Some(200.0));
assert_eq!(Length::px(-1.0).resolve(200.0), Some(0.0));

Trait Implementations§

Source§

impl Clone for Length

Source§

fn clone(&self) -> Length

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 Length

Source§

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

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

impl Default for Length

Source§

fn default() -> Length

Returns the “default value” for a type. Read more
Source§

impl From<f32> for Length

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Length

Source§

fn eq(&self, other: &Length) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Length

Source§

impl StructuralPartialEq for Length

Auto Trait Implementations§

§

impl Freeze for Length

§

impl RefUnwindSafe for Length

§

impl Send for Length

§

impl Sync for Length

§

impl Unpin for Length

§

impl UnwindSafe for Length

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.