pub enum Dimension {
Px(f32),
Percent(f32),
Em(f32),
Rem(f32),
Vw(f32),
Vh(f32),
Vmin(f32),
Vmax(f32),
Auto,
MinContent,
MaxContent,
FitContent,
}Expand description
A length value that may be absolute, relative, or intrinsic.
This is the building block of the style system — widths, heights,
margins, paddings, font sizes, and many other properties are all
expressed as Dimension values that get resolved to concrete pixels
during style resolution and layout.
Absolute values (Px) are ready to use immediately.
Relative values (Percent, Em,
Rem) need a reference value from the parent or root.
Viewport values (Vw, Vh) need
the viewport size. Intrinsic values (Auto,
MinContent, etc.) are resolved by the
layout algorithm itself.
Variants§
Px(f32)
Absolute pixels (after DPI scaling).
Percent(f32)
Percentage of the parent’s corresponding dimension.
Em(f32)
Relative to the element’s computed font-size.
Rem(f32)
Relative to the root element’s computed font-size.
Vw(f32)
Percentage of the viewport width.
Vh(f32)
Percentage of the viewport height.
Vmin(f32)
The smaller of vw and vh.
Vmax(f32)
The larger of vw and vh.
Auto
Size determined by the layout algorithm.
MinContent
The smallest size that fits the content without overflow.
MaxContent
The largest size the content can fill without wrapping.
FitContent
Clamp between min-content and max-content, or the available space if it’s between those bounds.
Implementations§
Source§impl Dimension
impl Dimension
pub fn is_auto(self) -> bool
Sourcepub fn is_definite(self) -> bool
pub fn is_definite(self) -> bool
True for any value that resolves to a concrete number (not auto/min-content/max-content/fit-content).
Sourcepub fn is_intrinsic(self) -> bool
pub fn is_intrinsic(self) -> bool
True for values that the layout algorithm determines.
Sourcepub fn resolve(self, parent: f32) -> Option<f32>
pub fn resolve(self, parent: f32) -> Option<f32>
Resolve an absolute or parent-relative value to pixels.
Only resolves Px and Percent.
For font-relative and viewport-relative values, use
resolve_full.
Sourcepub fn resolve_full(self, ctx: &ResolveContext) -> Option<f32>
pub fn resolve_full(self, ctx: &ResolveContext) -> Option<f32>
Resolve with all context values available.
Sourcepub fn resolve_or(self, parent: f32, fallback: f32) -> f32
pub fn resolve_or(self, parent: f32, fallback: f32) -> f32
Resolve, falling back to a default for unresolvable values.