#[non_exhaustive]pub struct Theme {Show 17 fields
pub primary: Color,
pub secondary: Color,
pub accent: Color,
pub text: Color,
pub text_dim: Color,
pub border: Color,
pub bg: Color,
pub success: Color,
pub warning: Color,
pub error: Color,
pub selected_bg: Color,
pub selected_fg: Color,
pub surface: Color,
pub surface_hover: Color,
pub surface_text: Color,
pub is_dark: bool,
pub spacing: Spacing,
}Expand description
A color theme that flows through all widgets automatically.
Construct with Theme::dark() or Theme::light(), or use
Theme::builder() for custom themes. Pass via crate::RunConfig
and every widget picks up the colors without any extra wiring.
§Example
use slt::{Color, Theme};
let theme = Theme::builder()
.primary(Color::Rgb(255, 107, 107))
.build();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.primary: ColorPrimary accent color, used for focused borders and highlights.
secondary: ColorSecondary accent color, used for less prominent highlights.
accent: ColorAccent color for decorative elements.
text: ColorDefault foreground text color.
text_dim: ColorDimmed text color for secondary labels and hints.
border: ColorBorder color for unfocused containers.
bg: ColorBackground color. Typically Color::Reset to inherit the terminal background.
success: ColorColor for success states (e.g., toast notifications).
warning: ColorColor for warning states.
error: ColorColor for error states.
selected_bg: ColorBackground color for selected list/table rows.
selected_fg: ColorForeground color for selected list/table rows.
surface: ColorSubtle surface color for card backgrounds and elevated containers.
surface_hover: ColorHover/active surface color, one step brighter than surface.
Used for interactive element hover states. Should be visually
distinguishable from both surface and border.
surface_text: ColorSecondary text color guaranteed readable on surface backgrounds.
Use this instead of text_dim when rendering on surface-colored
containers. text_dim is tuned for the main bg; on surface it
may lack contrast.
is_dark: boolWhether this theme is a dark theme. Used to initialize dark mode in Context.
spacing: SpacingSpacing scale for consistent padding, margin, and gap values.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn resolve(&self, token: ThemeColor) -> Color
pub fn resolve(&self, token: ThemeColor) -> Color
Resolve a ThemeColor token to a concrete Color.
Sourcepub fn contrast_text_on(&self, bg: Color) -> Color
pub fn contrast_text_on(&self, bg: Color) -> Color
Return a text color with guaranteed contrast against the given background.
Delegates to Color::contrast_fg.
Sourcepub fn overlay(&self, color: Color, alpha: f32) -> Color
pub fn overlay(&self, color: Color, alpha: f32) -> Color
Blend a color with the theme’s background at the given alpha.
alpha = 0.0 returns self.bg, alpha = 1.0 returns color unchanged.
Sourcepub const fn light() -> Self
pub const fn light() -> Self
Create a light theme with high-contrast dark text on light backgrounds.
Sourcepub const fn builder() -> ThemeBuilder
pub const fn builder() -> ThemeBuilder
Create a ThemeBuilder for configuring a custom theme.
Unset fields fall back to Theme::dark() defaults. Use
Theme::builder_from to start from a different base, or
Theme::light_builder for a light-base shorthand.
§Example
use slt::{Color, Theme};
let theme = Theme::builder()
.primary(Color::Rgb(255, 107, 107))
.accent(Color::Cyan)
.build();Sourcepub const fn builder_from(base: Theme) -> ThemeBuilder
pub const fn builder_from(base: Theme) -> ThemeBuilder
Create a ThemeBuilder pre-filled with every field from base.
Only fields explicitly overridden via builder methods will differ
from base; unset fields keep base’s value (rather than falling
back to Theme::dark() defaults as plain Theme::builder
does). Useful for deriving variants from any preset.
§Example
use slt::{Color, Theme};
// Nord variant: keep all Nord colors but override primary.
let custom_nord = Theme::builder_from(Theme::nord())
.primary(Color::Rgb(255, 0, 0))
.build();
assert_eq!(custom_nord.bg, Theme::nord().bg);
assert_eq!(custom_nord.primary, Color::Rgb(255, 0, 0));Sourcepub const fn light_builder() -> ThemeBuilder
pub const fn light_builder() -> ThemeBuilder
Convenience: builder pre-filled with all Theme::light() fields.
Equivalent to Theme::builder_from(Theme::light()).
§Example
use slt::{Color, Theme};
let my_light = Theme::light_builder()
.primary(Color::Rgb(0, 100, 200))
.build();
assert!(!my_light.is_dark);
assert_eq!(my_light.primary, Color::Rgb(0, 100, 200));
// bg stays light (not dark()'s Reset)
assert_eq!(my_light.bg, Theme::light().bg);Sourcepub fn catppuccin() -> Self
pub fn catppuccin() -> Self
Catppuccin Mocha theme — lavender primary on dark base.
Sourcepub fn solarized_dark() -> Self
pub fn solarized_dark() -> Self
Solarized Dark theme — blue primary on dark base.
Sourcepub fn solarized_light() -> Self
pub fn solarized_light() -> Self
Solarized Light theme — warm ochre primary on light base.
Sourcepub fn tokyo_night() -> Self
pub fn tokyo_night() -> Self
Tokyo Night theme — blue primary on dark storm base.
Sourcepub fn gruvbox_dark() -> Self
pub fn gruvbox_dark() -> Self
Gruvbox Dark theme — warm, retro tones on dark background.
Sourcepub const fn compact() -> Self
pub const fn compact() -> Self
Compact density preset — base spacing = 1 (matches v0.19 default behavior).
Use when terminal space is tight or you want maximum information
density. Built on Theme::dark() colors with Spacing::new(1).
§Example
use slt::Theme;
let theme = Theme::compact();
assert_eq!(theme.spacing.xs(), 1);Sourcepub const fn comfortable() -> Self
pub const fn comfortable() -> Self
Comfortable density preset — base spacing = 2.
Widgets use roughly twice the padding/margin of Theme::compact,
improving readability in spacious terminals at the cost of fitting
less content per screen.
§Example
use slt::Theme;
let theme = Theme::comfortable();
assert_eq!(theme.spacing.xs(), 2);
assert_eq!(theme.spacing.sm(), 4);Sourcepub const fn spacious() -> Self
pub const fn spacious() -> Self
Spacious density preset — base spacing = 3.
Tripled padding/margin compared to Theme::compact — best for
presentations, demos, or very wide terminals where “breathing room”
matters more than density.
§Example
use slt::Theme;
let theme = Theme::spacious();
assert_eq!(theme.spacing.xs(), 3);
assert_eq!(theme.spacing.sm(), 6);Sourcepub const fn with_spacing(self, spacing: Spacing) -> Self
pub const fn with_spacing(self, spacing: Spacing) -> Self
Apply a Spacing scale on top of the current theme, returning a new theme.
All other fields are preserved. Useful to adapt any preset (Nord, Dracula, custom) to a new density without rebuilding the colors.
§Example
use slt::{Spacing, Theme};
let dense_nord = Theme::nord().with_spacing(Spacing::new(2));
assert_eq!(dense_nord.spacing.xs(), 2);
// Nord colors preserved.
assert_eq!(dense_nord.bg, Theme::nord().bg);