Skip to main content

Style

Struct Style 

Source
pub struct Style {
Show 24 fields pub width: Dimension, pub height: Dimension, pub min_width: Dimension, pub min_height: Dimension, pub max_width: Dimension, pub max_height: Dimension, pub flex_grow: f32, pub flex_shrink: f32, pub flex_basis: Dimension, pub flex_direction: FlexDirection, pub justify: Justify, pub align: Align, pub align_content: AlignContent, pub align_self: Option<Align>, pub padding: Insets, pub margin: Insets, pub aspect_ratio: Option<f32>, pub gap: f32, pub row_gap: Option<f32>, pub column_gap: Option<f32>, pub flex_wrap: bool, pub grid_columns: Option<usize>, pub grid_row_height: Option<f32>, pub overlap: bool,
}
Expand description

A layout node’s style.

Fields§

§width: Dimension

Width.

§height: Dimension

Height.

§min_width: Dimension

Minimum width: a floor the layout never goes below. Useful for a box that grows with its content and never squashes (Auto = no floor).

§min_height: Dimension

Minimum height: a floor the layout never goes below — for instance a row that grows with tall content and never shrinks (Auto = no floor).

§max_width: Dimension

Maximum width: a ceiling the layout never goes above, whatever the content or the space on offer asks for (Auto = no ceiling).

§max_height: Dimension

Maximum height: the same ceiling on the vertical axis (Auto = none).

§flex_grow: f32

The main-axis grow factor (flexbox): the share of spare room this item takes.

§flex_shrink: f32

The main-axis shrink factor: the share of a deficit this item absorbs when the children do not fit. 1.0 — the flexbox default — means everything squashes together, in proportion to its basis; 0.0 means not me, and is what fixed chrome wants: an icon button at the end of a row keeps its 40 px however long the label beside it is. See Style::flex_basis for the other half.

§flex_basis: Dimension

The main-axis basis: the size an item starts from, before growing or shrinking. Auto — the default — means use the content, so a long label starts long and drags the whole row with it. Length(0.0) means start from nothing and take what is left, which is the shape of the reference’s expanding child.

§flex_direction: FlexDirection

The main-axis direction, for a container.

§justify: Justify

Distribution along the main axis.

§align: Align

Alignment on the cross axis, for a container: what it does to its children.

§align_content: AlignContent

How a wrapping container’s lines are distributed on the cross axis.

Silent unless the container wraps and has cross-axis room to spare, since one line has nowhere to go.

§align_self: Option<Align>

This item’s own cross-axis alignment, overriding whatever its parent asked for. None — the default — means “do as the others do”.

One box out of step with its row is a common enough shape that the alternative is a wrapper widget per exception, and flexbox already has the field.

§padding: Insets

Padding, per side, in logical pixels.

§margin: Insets

Margin, per side, in logical pixels: space reserved around the box, outside its decoration, which pushes siblings away.

§aspect_ratio: Option<f32>

When Some(r), the box keeps an aspect ratio of r (width / height): the free dimension is derived from the constrained one. None means no ratio constraint.

§gap: f32

Spacing between children, in logical pixels.

§row_gap: Option<f32>

Spacing between rows, when it differs from gap. None means gap.

A grid’s two spacings are separate in the reference — one along the axis it scrolls, one across it — and a tile grid usually wants them different.

§column_gap: Option<f32>

Spacing between columns, when it differs from gap. None means gap.

§flex_wrap: bool

When true, children wrap onto the next line (flex-wrap) once they overflow the main axis — automatic responsive reflow.

§grid_columns: Option<usize>

When Some(n), the container is a grid of n equal columns, with children placed automatically, row by row. None means flex.

§grid_row_height: Option<f32>

When Some(h), every grid row is exactly h logical pixels tall instead of following its content — the reference’s per-tile main-axis extent. Ignored outside a grid.

§overlap: bool

When true, the children overlap: all of them share one cell, which is as big as the largest, and each is placed in it by Style::align on both axes.

It is how a box sizes itself to the biggest of several things drawn on top of one another — a picture on its way out under the one coming in — which a flex line cannot say (it adds its children up) and a stack here does not (its layers are laid out apart from it, so an unsized stack is nothing). Handed a box by its parent, the cell fills it, as the reference’s stack fills a tight constraint.

Implementations§

Source§

impl Style

Source

pub fn layout_hash<H: Hasher>(&self, hasher: &mut H)

Mixes into hasher every field that affects layout geometry. Two styles with the same fingerprint produce the same arrangement — which is what makes a relayout cache possible, skipping taffy when nothing relevant has changed. The f32s are hashed by bit pattern, so equality is exact; colour and text do not enter into it, since they only affect painting.

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Style

Source§

impl Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Self

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

impl PartialEq for Style

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnsafeUnpin for Style

§

impl UnwindSafe for Style

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.