Skip to main content

Dimension

Enum Dimension 

Source
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

Source

pub fn is_auto(self) -> bool

Source

pub fn is_definite(self) -> bool

True for any value that resolves to a concrete number (not auto/min-content/max-content/fit-content).

Source

pub fn is_intrinsic(self) -> bool

True for values that the layout algorithm determines.

Source

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.

Source

pub fn resolve_full(self, ctx: &ResolveContext) -> Option<f32>

Resolve with all context values available.

Source

pub fn resolve_or(self, parent: f32, fallback: f32) -> f32

Resolve, falling back to a default for unresolvable values.

Trait Implementations§

Source§

impl Clone for Dimension

Source§

fn clone(&self) -> Dimension

Returns a duplicate 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 Dimension

Source§

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

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

impl Default for Dimension

Source§

fn default() -> Dimension

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

impl PartialEq for Dimension

Source§

fn eq(&self, other: &Dimension) -> 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 Dimension

Source§

impl StructuralPartialEq for Dimension

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> 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.