pub struct ContainerStyle {Show 28 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>,
pub theme_bg: Option<ThemeColor>,
pub theme_text_color: Option<ThemeColor>,
pub theme_border_fg: Option<ThemeColor>,
pub extends: Option<&'static ContainerStyle>,
}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.
theme_bg: Option<ThemeColor>Theme-aware background color. Takes precedence over Self::bg when set.
theme_text_color: Option<ThemeColor>Theme-aware text color. Takes precedence over Self::text_color when set.
theme_border_fg: Option<ThemeColor>Theme-aware border foreground color. Takes precedence over
Self::border_style’s foreground when set.
extends: Option<&'static ContainerStyle>Base style to inherit from. Fields in the base are applied first,
then overridden by any Some fields in this style.
Use ContainerStyle::extending to create a style that inherits.
Implementations§
Source§impl ContainerStyle
impl ContainerStyle
Sourcepub const fn extending(base: &'static ContainerStyle) -> Self
pub const fn extending(base: &'static ContainerStyle) -> Self
Create a style that inherits all fields from a base style.
Only the fields you set on the returned style will override the base.
The base must be a &'static ContainerStyle (typically a const).
§Example
use slt::{ContainerStyle, Border, ThemeColor};
const BUTTON: ContainerStyle = ContainerStyle::new()
.border(Border::Rounded)
.p(1);
const BUTTON_DANGER: ContainerStyle = ContainerStyle::extending(&BUTTON)
.theme_bg(ThemeColor::Error);Sourcepub const fn border_sides(self, sides: BorderSides) -> Self
pub const fn border_sides(self, sides: BorderSides) -> Self
Set which border sides to render.
Sourcepub const fn text_color(self, color: Color) -> Self
pub const fn text_color(self, color: Color) -> Self
Set default text color inherited by child text widgets.
Sourcepub const fn mx(self, value: u32) -> Self
pub const fn mx(self, value: u32) -> Self
Set horizontal margin (left + right). Top and bottom are preserved if margin was previously set, otherwise default to 0.
use slt::ContainerStyle;
let s = ContainerStyle::new().mx(2).py(1);
assert_eq!(s.margin.unwrap().left, 2);
assert_eq!(s.margin.unwrap().right, 2);
assert_eq!(s.margin.unwrap().top, 0);Sourcepub const fn my(self, value: u32) -> Self
pub const fn my(self, value: u32) -> Self
Set vertical margin (top + bottom). Left and right are preserved if margin was previously set, otherwise default to 0.
Sourcepub const fn align_self(self, value: Align) -> Self
pub const fn align_self(self, value: Align) -> Self
Set per-child cross-axis alignment override.
Sourcepub const fn theme_bg(self, color: ThemeColor) -> Self
pub const fn theme_bg(self, color: ThemeColor) -> Self
Set a theme-aware background color that resolves at apply time.
Takes precedence over Self::bg when set. The color is resolved
against the active theme when crate::ContainerBuilder::apply is called.
Sourcepub const fn theme_text_color(self, color: ThemeColor) -> Self
pub const fn theme_text_color(self, color: ThemeColor) -> Self
Set a theme-aware text color that resolves at apply time.
Takes precedence over Self::text_color when set.
Sourcepub const fn theme_border_fg(self, color: ThemeColor) -> Self
pub const fn theme_border_fg(self, color: ThemeColor) -> Self
Set a theme-aware border foreground color that resolves at apply time.
Takes precedence over Self::border_style’s foreground when set.
Trait Implementations§
Source§impl Clone for ContainerStyle
impl Clone for ContainerStyle
Source§fn clone(&self) -> ContainerStyle
fn clone(&self) -> ContainerStyle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more