Skip to main content

Module theme_switcher

Module theme_switcher 

Source
Expand description

ThemeSwitcher — a drop-in app-theme picker for settings screens & toolbars.

A thin ComboBox preset that switches the application theme. By default it offers three entries — Light, Dark, and System — where System follows the native OS theme live: it adopts the OS’s actual colours (GNOME / KDE / Cinnamon on Linux) and tracks OS light/dark changes at runtime, falling back to the built-in light/dark presets on platforms without OS-colour support.

Zero-config: drop ThemeSwitcher::new() into a settings panel or toolbar and it

  • shows the active theme as the current selection (matched by the theme’s stable [ThemeId]),
  • switches the app theme on selection via EventContext::set_theme (fixed themes) or EventContext::follow_system_theme (System),
  • and stays in sync if the theme changes elsewhere (a menu, the inspector, or an OS light/dark toggle).
// In a settings panel or toolbar:
Toolbar::new().child(HStack::new().child(Spacer::new()).child(ThemeSwitcher::new()))

Labels are translated via the framework Fluent bundle (tr_widget!), with an English literal fallback so a host app that hasn’t installed an I18nManager still reads “Light / Dark / System” rather than raw keys.

Custom themes: .themes([(label, theme), …]) replaces Light/Dark with an app-supplied set (e.g. the teksilo-theme-{fluent,macos,material3} presets); .system(false) drops the System entry.

Structs§

ThemeSwitcher
A drop-in app-theme picker built on ComboBox. See the module docs.