#[non_exhaustive]pub enum WidthSpec {
Auto,
Fixed(u32),
Pct(u8),
Ratio(u16, u16),
MinMax {
min: u32,
max: u32,
},
}Expand description
Width specification for a flexbox item.
Replaces the previous trio of Option-typed fields (min_width,
max_width, width_pct) with a single tagged enum. Resolution at
layout time dispatches on the variant.
Constraints::default() produces WidthSpec::Auto.
§Variant semantics
Auto— no width constraint; the element sizes from content and available space.Fixed(n)— exact cell width. Equivalent toMinMax { min: Some(n), max: Some(n) }.Pct(p)— percentage of parent width (clamped to 0..=100).Ratio(num, den)— exact integer fraction. For exampleRatio(1, 3)producesarea / 3. Floor division:area = 80, num = 1, den = 3→26. Adenof0is treated as no constraint.MinMax { min, max }— bounds on each side independently.
§Example
use slt::{Constraints, WidthSpec};
let c = Constraints::default().w_ratio(1, 3);
assert_eq!(c.width, WidthSpec::Ratio(1, 3));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Auto
Unconstrained — sizes from content and available space.
Fixed(u32)
Exact cell width.
Pct(u8)
Percentage of parent width (0..=100).
Ratio(u16, u16)
Exact integer fraction of parent (numerator, denominator).
Ratio(1, 3) produces area / 3. Floor division — for
area = 80, num = 1, den = 3 → 26. A den of 0 is treated as
no constraint.
MinMax
Min and/or max bounds. Sentinels are used so that the variant fits
in 12 bytes (24 bytes total for the two-axis Constraints struct):
min = 0means “no minimum” (equivalent toOption::None); since a min of 0 is the same as no minimum, using0as the sentinel does not lose any expressible state.max = u32::MAXmeans “no maximum” (the naturalinfinity).
Use the Constraints::min_w / Constraints::max_w /
Constraints::w_minmax builders to construct this variant
without thinking about sentinels.