Skip to main content

ThemeVariant

Struct ThemeVariant 

Source
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: ThemeDefaults

Global defaults inherited by all widgets.

§text_scale: TextScale

Per-role text scale overrides.

§window: WindowTheme

Window chrome: background, title bar, radius, shadow.

§button: ButtonTheme

Push button: colors, sizing, spacing, geometry.

§input: InputTheme

Single-line and multi-line text input fields.

§checkbox: CheckboxTheme

Checkbox and radio button indicator geometry.

§menu: MenuTheme

Popup and context menu appearance.

§tooltip: TooltipTheme

Tooltip popup appearance.

§scrollbar: ScrollbarTheme

Scrollbar colors and geometry.

§slider: SliderTheme

Slider control colors and geometry.

§progress_bar: ProgressBarTheme

Progress bar colors and geometry.

§tab: TabTheme

Tab bar colors and sizing.

§sidebar: SidebarTheme

Sidebar panel background and foreground colors.

§toolbar: ToolbarTheme

Toolbar sizing, spacing, and font.

§status_bar: StatusBarTheme

Status bar font.

§list: ListTheme

List and table colors and row geometry.

§popover: PopoverTheme

Popover / dropdown panel appearance.

§splitter: SplitterTheme

Splitter handle width.

§separator: SeparatorTheme

Separator line color.

§switch: SwitchTheme

Toggle switch track, thumb, and geometry.

§dialog: DialogTheme

Dialog sizing, spacing, button order, and title font.

§spinner: SpinnerTheme

Spinner / indeterminate progress indicator.

§combo_box: ComboBoxTheme

ComboBox / dropdown trigger sizing.

§segmented_control: SegmentedControlTheme

Segmented control sizing.

§card: CardTheme

Card / container colors and geometry.

§expander: ExpanderTheme

Expander / disclosure row geometry.

§link: LinkTheme

Hyperlink 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

Source

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

pub fn is_empty(&self) -> bool

Returns true if all fields are at their default (None/empty) state.

Source§

impl ThemeVariant

Source

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
  1. Defaults internal chains – accent derives selection, focus_ring_color; selection derives selection_inactive.
  2. Safety nets – platform-divergent fields get a reasonable fallback.
  3. Widget-from-defaults – colors, geometry, fonts, text scale entries all inherit from defaults.
  4. Widget-to-widget – inactive title bar fields fall back to active.
  5. Icon set – fills icon_set from the compile-time system default.
Source

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().

Source

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.

Source

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;
Source

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

Source§

fn clone(&self) -> ThemeVariant

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 ThemeVariant

Source§

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

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

impl Default for ThemeVariant

Source§

fn default() -> ThemeVariant

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

impl<'de> Deserialize<'de> for ThemeVariant

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ThemeVariant, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ThemeVariant

Source§

fn eq(&self, other: &ThemeVariant) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ThemeVariant

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ThemeVariant

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,