Enum Units

Source
pub enum Units {
    Pixels(f32),
    Percentage(f32),
    Stretch(f32),
    Auto,
}
Expand description

Units which describe spacing and size.

Variants§

§

Pixels(f32)

A number of logical pixels.

§

Percentage(f32)

A percentage of the parent dimension.

A percentage of the parent’s width when applied to left, width, right properties. A percentage of the parent’s height when applied to top, height, bottom properties.

§

Stretch(f32)

A factor of the remaining free space.

The remaining free space is the parent space minus the space and size of any fixed-size nodes in that axis. The remaining free space is then shared between any stretch nodes based on the ratio of their stretch factors.

For example, given two stretch nodes with factors of 1.0 and 2.0 respectively. The first will occupy 1/3 of the remaining free space while the second will occupy 2/3 of the remaining free space.

§

Auto

Automatically determine the value.

When applied to space (left, right, top, bottom) the spacing may be overridden by the parent’s child-space on the same side. For example, a node in a column with Auto left space, with a parent which has Pixel(100.0) child-left space, will get a left spacing of 100px.

When applied to size (width, height) Auto will either size to fit its children, or if there are no children the node will be sized based on the content_size property of the node.

Implementations§

Source§

impl Units

Source

pub fn to_px(&self, parent_value: f32, default: f32) -> f32

Returns the units converted to pixels or a provided default.

Source

pub fn to_px_clamped( &self, parent_value: f32, default: f32, min: Units, max: Units, ) -> f32

Source

pub fn clamp(&self, min: Units, max: Units) -> Self

Source

pub fn is_pixels(&self) -> bool

Returns true if the value is in pixels.

Source

pub fn is_percentage(&self) -> bool

Returns true if the value is a percentage.

Source

pub fn is_stretch(&self) -> bool

Returns true if the value is a stretch factor.

Source

pub fn is_auto(&self) -> bool

Returns true if the value is auto.

Trait Implementations§

Source§

impl Clone for Units

Source§

fn clone(&self) -> Units

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 Units

Source§

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

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

impl Default for Units

Source§

fn default() -> Units

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

impl Display for Units

Source§

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

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

impl PartialEq for Units

Source§

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

Source§

impl StructuralPartialEq for Units

Auto Trait Implementations§

§

impl Freeze for Units

§

impl RefUnwindSafe for Units

§

impl Send for Units

§

impl Sync for Units

§

impl Unpin for Units

§

impl UnwindSafe for Units

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.