Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Theming

Vizia supports light and dark mode theming through CSS custom properties (variables). The built-in theme exposes a set of tokens that can be overridden to create custom themes.

Theme modes

Switch between light and dark mode by emitting an EnvironmentEvent:

cx.emit(EnvironmentEvent::SetThemeMode(ThemeMode::DarkMode));
cx.emit(EnvironmentEvent::SetThemeMode(ThemeMode::LightMode));

Vizia reads the system preference by default, so no setup is needed for automatic dark/light mode support.

Built-in CSS variables

The default theme exposes these tokens:

VariableDescription
--backgroundRoot background color.
--foregroundDefault text color.
--cardCard surface background color.
--card-foregroundText color on card surfaces.
--popoverPopover/menu surface background color.
--popover-foregroundText color on popover surfaces.
--primaryPrimary action/button color.
--primary-hoverHover state color for primary actions.
--primary-activeActive/pressed state color for primary actions.
--primary-foregroundText color on primary surfaces.
--secondarySecondary accent color.
--secondary-hoverHover state color for secondary actions.
--secondary-activeActive/pressed state color for secondary actions.
--secondary-foregroundText on secondary surfaces.
--mutedMuted background.
--muted-foregroundMuted text.
--accentHighlight accent color.
--accent-foregroundText on accent surfaces.
--borderBorder color.
--inputInput surface/border tone.
--ringFocus ring color.
--destructiveDanger/destructive action color.
--chart-1Chart series color 1.
--chart-2Chart series color 2.
--chart-3Chart series color 3.
--chart-4Chart series color 4.
--chart-5Chart series color 5.
--sidebarSidebar background color.
--sidebar-foregroundSidebar default text color.
--sidebar-primarySidebar primary accent color.
--sidebar-primary-foregroundText color on sidebar primary surfaces.
--sidebar-accentSidebar hover/selection accent color.
--sidebar-accent-foregroundText color on sidebar accent surfaces.
--sidebar-borderSidebar border color.
--sidebar-ringSidebar focus ring color.

These tokens are defined for both light (:root) and dark (.dark) modes in the default theme.

Overriding token values

Supply a stylesheet that redefines tokens:

:root {
    --primary: #7c3aed;
    --primary-foreground: #ffffff;
    --ring: #7c3aed;
}

:root.dark {
    --background: #0f0f0f;
    --foreground: #f5f5f5;
    --primary: #a78bfa;
}

Add the stylesheet before building views:

cx.add_stylesheet(include_style!("theme_override.css")).unwrap();

Ignoring the default theme

To build a fully custom theme from scratch, set ignore_default_theme before building the app:

Application::new(|cx| {
    cx.add_stylesheet(include_style!("my_theme.css")).unwrap();
    // ...
})
.ignore_default_theme()
.run()

See also