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
impl Length
Sourcepub fn px(value: f32) -> Self
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));Sourcepub fn fill() -> Self
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);Sourcepub fn percent(value: f32) -> Self
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));Sourcepub fn is_auto(self) -> bool
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());Sourcepub fn resolve(self, available: f32) -> Option<f32>
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));