pub struct ThemeVariant {Show 29 fields
pub defaults: ThemeDefaults,
pub text_scale: TextScale,
pub window: WindowTheme,
pub button: ButtonTheme,
pub input: InputTheme,
pub checkbox: CheckboxTheme,
pub menu: MenuTheme,
pub tooltip: TooltipTheme,
pub scrollbar: ScrollbarTheme,
pub slider: SliderTheme,
pub progress_bar: ProgressBarTheme,
pub tab: TabTheme,
pub sidebar: SidebarTheme,
pub toolbar: ToolbarTheme,
pub status_bar: StatusBarTheme,
pub list: ListTheme,
pub popover: PopoverTheme,
pub splitter: SplitterTheme,
pub separator: SeparatorTheme,
pub switch: SwitchTheme,
pub dialog: DialogTheme,
pub spinner: SpinnerTheme,
pub combo_box: ComboBoxTheme,
pub segmented_control: SegmentedControlTheme,
pub card: CardTheme,
pub expander: ExpanderTheme,
pub link: LinkTheme,
pub icon_set: Option<IconSet>,
pub icon_theme: Option<String>,
}Expand description
A single light or dark theme variant containing all visual properties.
Composes defaults, per-widget structs, and optional text scale into one coherent set. Empty sub-structs are omitted from serialization to keep TOML files clean.
§Examples
use native_theme::{ThemeVariant, Rgba};
let mut variant = ThemeVariant::default();
variant.defaults.accent = Some(Rgba::rgb(0, 120, 215));
variant.defaults.font.family = Some("Inter".into());
assert!(!variant.is_empty());Fields§
§defaults: ThemeDefaultsGlobal defaults inherited by all widgets.
text_scale: TextScalePer-role text scale overrides.
window: WindowThemeWindow chrome: background, title bar, radius, shadow.
Push button: colors, sizing, spacing, geometry.
input: InputThemeSingle-line and multi-line text input fields.
checkbox: CheckboxThemeCheckbox and radio button indicator geometry.
Popup and context menu appearance.
tooltip: TooltipThemeTooltip popup appearance.
scrollbar: ScrollbarThemeScrollbar colors and geometry.
slider: SliderThemeSlider control colors and geometry.
progress_bar: ProgressBarThemeProgress bar colors and geometry.
tab: TabThemeTab bar colors and sizing.
Sidebar panel background and foreground colors.
toolbar: ToolbarThemeToolbar sizing, spacing, and font.
status_bar: StatusBarThemeStatus bar font.
list: ListThemeList and table colors and row geometry.
popover: PopoverThemePopover / dropdown panel appearance.
splitter: SplitterThemeSplitter handle width.
separator: SeparatorThemeSeparator line color.
switch: SwitchThemeToggle switch track, thumb, and geometry.
dialog: DialogThemeDialog sizing, spacing, button order, and title font.
spinner: SpinnerThemeSpinner / indeterminate progress indicator.
combo_box: ComboBoxThemeComboBox / dropdown trigger sizing.
segmented_control: SegmentedControlThemeSegmented control sizing.
card: CardThemeCard / container colors and geometry.
expander: ExpanderThemeExpander / disclosure row geometry.
link: LinkThemeHyperlink colors and underline setting.
icon_set: Option<IconSet>Which icon loading mechanism to use (Freedesktop, Material, Lucide,
SfSymbols, SegoeIcons). Determines how icons are looked up — e.g.
freedesktop theme directories vs. bundled SVG tables.
When None, filled by resolve() from
system_icon_set().
icon_theme: Option<String>The name of the visual icon theme that provides the actual icon files
(e.g. "breeze", "Adwaita", "Lucide"). For Freedesktop this
selects the theme directory; for bundled sets it is a display label.
When None, filled by resolve_platform_defaults()
from system_icon_theme().
Implementations§
Source§impl ThemeVariant
impl ThemeVariant
Sourcepub fn merge(&mut self, overlay: &ThemeVariant)
pub fn merge(&mut self, overlay: &ThemeVariant)
Merge an overlay into this value. Some fields in the overlay
replace the corresponding fields in self; None fields are
left unchanged. Nested structs are merged recursively.
Source§impl ThemeVariant
impl ThemeVariant
Sourcepub fn resolve(&mut self)
pub fn resolve(&mut self)
Apply all ~91 inheritance rules in 5-phase order (pure data transform).
After calling resolve(), most Option fields that were None will be filled from defaults or related widget fields. Calling resolve() twice produces the same result (idempotent).
This method is a pure data transform: it does not perform any OS detection
or I/O. For full resolution including platform defaults (icon theme from
the system), use resolve_all().
§Phases
- Defaults internal chains – accent derives selection, focus_ring_color; selection derives selection_inactive.
- Safety nets – platform-divergent fields get a reasonable fallback.
- Widget-from-defaults – colors, geometry, fonts, text scale entries all inherit from defaults.
- Widget-to-widget – inactive title bar fields fall back to active.
- Icon set – fills icon_set from the compile-time system default.
Sourcepub fn resolve_platform_defaults(&mut self)
pub fn resolve_platform_defaults(&mut self)
Fill platform-detected defaults that require OS interaction.
Currently fills icon_theme from the system icon theme if not already set.
This is separated from resolve() because it performs
runtime OS detection (reading desktop environment settings), unlike the
pure inheritance rules in resolve().
Sourcepub fn resolve_all(&mut self)
pub fn resolve_all(&mut self)
Apply all inheritance rules and platform defaults.
Convenience method that calls resolve() followed by
resolve_platform_defaults().
This is equivalent to the full resolution that
into_resolved() performs before validation.
Sourcepub fn into_resolved(self) -> Result<ResolvedThemeVariant, Error>
pub fn into_resolved(self) -> Result<ResolvedThemeVariant, Error>
Resolve all inheritance rules and validate in one step.
This is the recommended way to convert a ThemeVariant into a
ResolvedThemeVariant. It calls resolve_all()
followed by validate(), ensuring no fields are left
unresolved.
§Errors
Returns crate::Error::Resolution if any fields remain None after
resolution (e.g., when accent color is missing and cannot be derived).
§Examples
use native_theme::ThemeSpec;
let theme = ThemeSpec::preset("dracula").unwrap();
let variant = theme.dark.unwrap();
let resolved = variant.into_resolved().unwrap();
// All fields are now guaranteed populated
let accent = resolved.defaults.accent;Sourcepub fn validate(&self) -> Result<ResolvedThemeVariant, Error>
pub fn validate(&self) -> Result<ResolvedThemeVariant, Error>
Convert this ThemeVariant into a ResolvedThemeVariant with all fields guaranteed.
Should be called after resolve(). Walks every field
and collects missing (None) field paths, then validates that numeric values
are within legal ranges (e.g., spacing >= 0, opacity 0..=1, font weight
100..=900). Returns Ok(ResolvedThemeVariant) if all fields are populated
and in range.
§Errors
Returns crate::Error::Resolution containing a ThemeResolutionError
with all missing field paths and out-of-range diagnostics.
Trait Implementations§
Source§impl Clone for ThemeVariant
impl Clone for ThemeVariant
Source§fn clone(&self) -> ThemeVariant
fn clone(&self) -> ThemeVariant
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more