Skip to main content

ContainerStyle

Struct ContainerStyle 

Source
pub struct ContainerStyle {
Show 24 fields pub border: Option<Border>, pub border_sides: Option<BorderSides>, pub border_style: Option<Style>, pub bg: Option<Color>, pub text_color: Option<Color>, pub dark_bg: Option<Color>, pub dark_border_style: Option<Style>, pub padding: Option<Padding>, pub margin: Option<Margin>, pub gap: Option<u32>, pub row_gap: Option<u32>, pub col_gap: Option<u32>, pub grow: Option<u16>, pub align: Option<Align>, pub align_self: Option<Align>, pub justify: Option<Justify>, pub w: Option<u32>, pub h: Option<u32>, pub min_w: Option<u32>, pub max_w: Option<u32>, pub min_h: Option<u32>, pub max_h: Option<u32>, pub w_pct: Option<u8>, pub h_pct: Option<u8>,
}
Expand description

Reusable container style recipe.

Define once, apply anywhere with crate::ContainerBuilder::apply. All fields are optional — only set fields override the builder’s current values. Styles compose: apply multiple recipes in sequence, last write wins.

§Example

use slt::{ContainerStyle, Border, Color};

const CARD: ContainerStyle = ContainerStyle::new()
    .border(Border::Rounded)
    .p(1)
    .bg(Color::Indexed(236));

const DANGER: ContainerStyle = ContainerStyle::new()
    .bg(Color::Red);

// Apply one or compose multiple:
ui.container().apply(&CARD).col(|ui| { ... });
ui.container().apply(&CARD).apply(&DANGER).col(|ui| { ... });

Fields§

§border: Option<Border>

Border style for the container.

§border_sides: Option<BorderSides>

Which sides of the border are visible.

§border_style: Option<Style>

Style (color and modifiers) for the border.

§bg: Option<Color>

Background color.

§text_color: Option<Color>

Foreground (text) color.

§dark_bg: Option<Color>

Background color in dark mode.

§dark_border_style: Option<Style>

Border style in dark mode.

§padding: Option<Padding>

Padding inside the container.

§margin: Option<Margin>

Margin outside the container.

§gap: Option<u32>

Gap between children (both row and column).

§row_gap: Option<u32>

Gap between rows.

§col_gap: Option<u32>

Gap between columns.

§grow: Option<u16>

Flex grow factor.

§align: Option<Align>

Cross-axis alignment.

§align_self: Option<Align>

Self alignment (overrides parent align).

§justify: Option<Justify>

Main-axis content distribution.

§w: Option<u32>

Fixed width.

§h: Option<u32>

Fixed height.

§min_w: Option<u32>

Minimum width.

§max_w: Option<u32>

Maximum width.

§min_h: Option<u32>

Minimum height.

§max_h: Option<u32>

Maximum height.

§w_pct: Option<u8>

Width as percentage of parent.

§h_pct: Option<u8>

Height as percentage of parent.

Implementations§

Source§

impl ContainerStyle

Source

pub const fn new() -> Self

Create an empty container style with no overrides.

Source

pub const fn border(self, border: Border) -> Self

Set the border style.

Source

pub const fn border_sides(self, sides: BorderSides) -> Self

Set which border sides to render.

Source

pub const fn bg(self, color: Color) -> Self

Set the background color.

Source

pub const fn text_color(self, color: Color) -> Self

Set default text color inherited by child text widgets.

Source

pub const fn dark_bg(self, color: Color) -> Self

Set the dark-mode background color.

Source

pub const fn p(self, value: u32) -> Self

Set uniform padding on all sides.

Source

pub const fn px(self, value: u32) -> Self

Set horizontal padding.

Source

pub const fn py(self, value: u32) -> Self

Set vertical padding.

Source

pub const fn m(self, value: u32) -> Self

Set uniform margin on all sides.

Source

pub const fn gap(self, value: u32) -> Self

Set the gap between children.

Source

pub const fn row_gap(self, value: u32) -> Self

Set row gap for column layouts.

Source

pub const fn col_gap(self, value: u32) -> Self

Set column gap for row layouts.

Source

pub const fn grow(self, value: u16) -> Self

Set the flex-grow factor.

Source

pub const fn w(self, value: u32) -> Self

Set fixed width.

Source

pub const fn h(self, value: u32) -> Self

Set fixed height.

Source

pub const fn min_w(self, value: u32) -> Self

Set minimum width.

Source

pub const fn max_w(self, value: u32) -> Self

Set maximum width.

Source

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

Set cross-axis alignment.

Source

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

Set per-child cross-axis alignment override.

Source

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

Set main-axis justification.

Source

pub const fn min_h(self, value: u32) -> Self

Set minimum height.

Source

pub const fn max_h(self, value: u32) -> Self

Set maximum height.

Source

pub const fn w_pct(self, value: u8) -> Self

Set width as percentage of parent (1-100).

Source

pub const fn h_pct(self, value: u8) -> Self

Set height as percentage of parent (1-100).

Trait Implementations§

Source§

impl Clone for ContainerStyle

Source§

fn clone(&self) -> ContainerStyle

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 ContainerStyle

Source§

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

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

impl Default for ContainerStyle

Source§

fn default() -> ContainerStyle

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

impl Copy for ContainerStyle

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.