Skip to main content

Module theme

Module theme 

Source
Expand description

Theme: the named colours a view and the stock widgets paint with, derived from the OS’s appearance and accent.

The core never repaints an app’s own colours when the OS goes dark; the view decides, because only it knows which of its colours is the background. A Theme is what it decides with: plain Copy data with a role per colour (bg, surface, fg, muted, accent, …), read off ui.theme() each frame.

use kui_core::{Appearance, Color, NodeSpec, Theme, ThemeSource};

// What the core derives by default: the OS's base and accent.
let t = Theme::derive(Appearance::Light, Some(Color::hex(0xd45b3bff)));
assert!(!t.is_dark());
let card = NodeSpec::column().bg(t.surface).border(1.0, t.border).radius(8.0);
let hint = t.muted; // secondary text that reads on `surface`

// An app with a brand colour that should still follow light/dark:
let source = ThemeSource::DerivedWithAccent(Color::hex(0xd45b3bff));
// ...handed to `Core::set_theme_source`. A fully pinned palette is
// `ThemeSource::Pinned(Theme::dark().with_accent(..))`.

Three ways to have one, which is ThemeSource:

  • Derived (the default): the OS’s appearance and the OS’s accent. A host that reports neither gets the dark base with kui’s blue.
  • Derived with an accent: the OS’s light/dark, the app’s brand colour. What most apps with a colour of their own want.
  • Pinned: a Theme the app built, following nothing.

Structs§

Theme
Every colour the stock widgets and the core’s own chrome paint with, as roles rather than values. Plain data and Copy: a view reads it off ui.theme() and may keep, mutate or replace its own copy.

Enums§

ThemeSource
Where a Core’s theme comes from, re-read at the start of every frame. Derived is the default.