Skip to main content

Style

Struct Style 

Source
#[non_exhaustive]
pub struct Style {
Show 22 fields pub hidden: bool, pub direction: Direction, pub wrap: bool, pub width: Length, pub height: Length, pub min_width: Length, pub min_height: Length, pub max_width: Length, pub max_height: Length, pub grow: f32, pub shrink: f32, pub basis: Length, pub padding: Edges<f32>, pub margin: Edges<Length>, pub gap: f32, pub align_items: Align, pub align_self: Option<Align>, pub justify: Justify, pub position: Position, pub inset: Edges<Length>, pub overflow: Overflow, pub aspect_ratio: Option<f32>,
}
Expand description

A widget’s layout style: its size, spacing, and how it lays out its children (flexbox). Lengths are in logical pixels.

use densa_ui::{Align, Length, Style};

let toolbar = Style::row().gap(4.0).padding(6.0).align_items(Align::Center);
let content = Style::column().grow(1.0).height(Length::Auto);

The default is Style::row: CSS’s defaults (flex-shrink: 1, items stretched).

As in CSS, a widget is never laid out smaller than its content unless its minimum size says so (min-width: auto): a region meant to shrink and scroll its content, and every container between it and the window, needs min_size(Length::Px(0.0), Length::Px(0.0)) (or Overflow::Clip or Overflow::Scroll, which imply it for the widget itself).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§hidden: bool

Not shown and taking no space.

§direction: Direction

The axis children are laid out along.

§wrap: bool

Whether children wrap onto more lines when they do not fit.

§width: Length

Width.

§height: Length

Height.

§min_width: Length

Smallest width.

§min_height: Length

Smallest height.

§max_width: Length

Largest width.

§max_height: Length

Largest height.

§grow: f32

Share of free space along the parent’s main axis.

§shrink: f32

Share of missing space given up when the parent is too small.

§basis: Length

Size along the parent’s main axis before growing or shrinking.

§padding: Edges<f32>

Space between the edges and the content.

§margin: Edges<Length>

Space outside the edges; Auto takes free space (pushing siblings away).

§gap: f32

Space between children.

§align_items: Align

Where children sit across the main axis.

§align_self: Option<Align>

Where this widget sits across its parent’s main axis, instead of the parent’s align_items.

§justify: Justify

How free space along the main axis is shared out.

§position: Position

In the flow of its siblings, or placed by inset.

§inset: Edges<Length>

Distances from the parent’s edges, for Position::Absolute.

§overflow: Overflow

What happens to content larger than the widget.

§aspect_ratio: Option<f32>

Width divided by height, kept when one of them is decided by layout.

Implementations§

Source§

impl Style

Source

pub fn row() -> Self

Children left to right.

Source

pub fn column() -> Self

Children top to bottom.

Source

pub fn width(self, width: Length) -> Self

The style with width.

Source

pub fn height(self, height: Length) -> Self

The style with height.

Source

pub fn size(self, width: f32, height: f32) -> Self

The style with a fixed size in logical pixels.

Source

pub fn min_size(self, width: Length, height: Length) -> Self

The style with smallest sizes.

Source

pub fn max_size(self, width: Length, height: Length) -> Self

The style with largest sizes.

Source

pub fn grow(self, grow: f32) -> Self

The style taking a grow share of free space.

Source

pub fn shrink(self, shrink: f32) -> Self

The style giving up a shrink share of missing space.

Source

pub fn basis(self, basis: Length) -> Self

The style with a size along the main axis before growing or shrinking.

Source

pub fn padding(self, padding: f32) -> Self

The style with padding on every side.

Source

pub fn padding_edges(self, padding: Edges<f32>) -> Self

The style with these paddings.

Source

pub fn margin(self, margin: Edges<Length>) -> Self

The style with these margins.

Source

pub fn gap(self, gap: f32) -> Self

The style with gap between children.

Source

pub fn align_items(self, align: Align) -> Self

The style placing children across the main axis.

Source

pub fn align_self(self, align: Align) -> Self

The style placing this widget across its parent’s main axis.

Source

pub fn justify(self, justify: Justify) -> Self

The style sharing out free space along the main axis.

Source

pub fn absolute(self, inset: Edges<Length>) -> Self

The style placed at inset from the parent’s edges, over its siblings.

Source

pub fn overflow(self, overflow: Overflow) -> Self

The style with overflow.

Source

pub fn wrap(self, wrap: bool) -> Self

The style wrapping children onto more lines, or not.

Source

pub fn hidden(self, hidden: bool) -> Self

The style hidden (taking no space), or not.

Source

pub fn aspect_ratio(self, ratio: f32) -> Self

The style keeping width divided by height at ratio.

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 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> Brush for T
where T: Clone + PartialEq + Default + Debug,

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> ErasedDestructor for T
where T: 'static,

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.