#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.Not shown and taking no space.
direction: DirectionThe axis children are laid out along.
wrap: boolWhether children wrap onto more lines when they do not fit.
width: LengthWidth.
height: LengthHeight.
min_width: LengthSmallest width.
min_height: LengthSmallest height.
max_width: LengthLargest width.
max_height: LengthLargest height.
grow: f32Share of free space along the parent’s main axis.
shrink: f32Share of missing space given up when the parent is too small.
basis: LengthSize 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: f32Space between children.
align_items: AlignWhere 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: JustifyHow free space along the main axis is shared out.
position: PositionIn the flow of its siblings, or placed by inset.
inset: Edges<Length>Distances from the parent’s edges, for Position::Absolute.
overflow: OverflowWhat 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
impl Style
Sourcepub fn size(self, width: f32, height: f32) -> Self
pub fn size(self, width: f32, height: f32) -> Self
The style with a fixed size in logical pixels.
Sourcepub fn basis(self, basis: Length) -> Self
pub fn basis(self, basis: Length) -> Self
The style with a size along the main axis before growing or shrinking.
Sourcepub fn padding_edges(self, padding: Edges<f32>) -> Self
pub fn padding_edges(self, padding: Edges<f32>) -> Self
The style with these paddings.
Sourcepub fn align_items(self, align: Align) -> Self
pub fn align_items(self, align: Align) -> Self
The style placing children across the main axis.
Sourcepub fn align_self(self, align: Align) -> Self
pub fn align_self(self, align: Align) -> Self
The style placing this widget across its parent’s main axis.
Sourcepub fn justify(self, justify: Justify) -> Self
pub fn justify(self, justify: Justify) -> Self
The style sharing out free space along the main axis.
Sourcepub fn absolute(self, inset: Edges<Length>) -> Self
pub fn absolute(self, inset: Edges<Length>) -> Self
The style placed at inset from the parent’s edges, over its siblings.
The style hidden (taking no space), or not.
Sourcepub fn aspect_ratio(self, ratio: f32) -> Self
pub fn aspect_ratio(self, ratio: f32) -> Self
The style keeping width divided by height at ratio.