pub struct Theme {Show 25 fields
pub appearance: Appearance,
pub bg: Color,
pub surface: Color,
pub raised: Color,
pub sunken: Color,
pub border: Color,
pub border_strong: Color,
pub fg: Color,
pub muted: Color,
pub faint: Color,
pub accent: Color,
pub accent_hover: Color,
pub accent_pressed: Color,
pub on_accent: Color,
pub accent_soft: Color,
pub selection: Color,
pub focus_ring: Color,
pub hover: Color,
pub pressed: Color,
pub disabled_opacity: f32,
pub success: Color,
pub warning: Color,
pub danger: Color,
pub scrollbar: Color,
pub scrollbar_active: Color,
}Expand description
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.
Roles, not a ramp. surface is not “grey 800” — it is the colour a
card is, and under a light theme it is nearly white. A view that
wants “one step lighter than this” has Color::mix and
Theme::raise for that, and nothing here promises an ordering
beyond the one the names carry.
Fields§
§appearance: AppearanceWhich base this was built from. Unknown means the host never
said, and the dark base stands — see Theme::derive.
bg: ColorThe window behind everything.
surface: ColorA card, panel or list sitting on bg.
raised: ColorA surface that floats above content: a menu, a tooltip, a
popover. Separate from surface because it has to read as
nearer, and under a light theme “nearer” is not “lighter” — a
float on a white page separates by its border.
sunken: ColorA well cut into a surface: a text field, a code block, a track.
border: ColorThe hairline between two surfaces.
border_strong: ColorA border that has to be seen — a float’s edge, a focused field.
fg: ColorBody text. What a TextStyle with no colour of its own resolves
to, which is what makes <text>hello</text> legible on both bases.
muted: ColorSecondary text: captions, hints, an accelerator beside a label.
faint: ColorText that is barely there: a placeholder, a gutter number.
accent: ColorThe one saturated colour: the OS accent when the host reports one, the app’s when it pinned one, and kui’s blue otherwise.
accent_hover: Coloraccent under a pointer, and under a press.
accent_pressed: Color§on_accent: ColorBlack or white — whichever a reader can see on accent.
accent_soft: ColorThe accent as a wash rather than a fill: what a selected menu row, a chosen tab or a highlighted list item is painted with.
Translucent on purpose. A row filled with the solid accent needs
its label to flip to on_accent in the same frame the fill lands,
and hover_bg is resolved by the core after the view has already
chosen that label — so on a light theme the row would spend a
frame as dark-on-blue. A wash keeps fg readable over both bases
and stays declarative.
selection: ColorWhat a text selection is painted under. Translucent: the glyphs under it keep their own colour.
focus_ring: ColorThe default keyboard focus ring.
hover: ColorA translucent wash over a neutral control that is hovered, and one
over a pressed one. Overlays, not fills: they go on whatever
surface the control sits on, so one pair works for every surface.
pressed is the firmer of the two on both bases.
pressed: Color§disabled_opacity: f32What a disabled control’s opacity is multiplied by.
success: Color§warning: Color§danger: Color§scrollbar: ColorThe scrollbar thumb at rest, and while hovered or dragged.
scrollbar_active: ColorImplementations§
Source§impl Theme
impl Theme
Sourcepub const DEFAULT_FG: Color
pub const DEFAULT_FG: Color
The text colour kui painted before it could ask the OS anything,
and the dark base’s fg. What an unresolved style falls back to.
Sourcepub const ACCENT: Color
pub const ACCENT: Color
kui’s own accent, and the stock button’s background since there was a stock button. Stands in wherever no accent is known.
Sourcepub fn derive(appearance: Appearance, accent: Option<Color>) -> Self
pub fn derive(appearance: Appearance, accent: Option<Color>) -> Self
The theme for what the OS said: system.appearance picks the base,
system.accent recolours it.
An Unknown appearance takes the dark base. Not a guess about
the user — the honest answer to “what did kui paint before it could
ask” — and the reason a host that reports nothing sees no change at
all. A view that would rather guess light has Theme::light.
Sourcepub fn from_system(sys: &SystemEnv) -> Self
pub fn from_system(sys: &SystemEnv) -> Self
Sourcepub fn dark() -> Self
pub fn dark() -> Self
The dark base, with kui’s own accent. The accent family is
hand-picked rather than run through
with_accent, so that a host which reports no
accent paints exactly what kui always did. Hand an accent in and the
arithmetic takes over.
Sourcepub fn light() -> Self
pub fn light() -> Self
The light base: the same roles, mirrored rather than inverted.
Mirrored, because inverting is wrong twice. A float above content
is lighter than the page on a dark base and no lighter than
white on a light one, so it separates by border instead; and the
accent does not flip at all — a blue button is a blue button, and
only its ring and its selection tint have to move, because the
pale ring that reads on #14161e is invisible on #f7f8fa.
Sourcepub fn with_accent(self, accent: Color) -> Self
pub fn with_accent(self, accent: Color) -> Self
This theme with accent in place of its own, and everything that
comes off the accent recomputed with it: the two button shades,
the label that goes on top, the selection tint and the ring.
The shades are crate::widgets::button_palette’s arithmetic, so
an accent-painted button reads as the same control in a different
colour rather than as a different control. The ring keeps each
base’s habit and is then held to Theme::ring_for’s promise.
Sourcepub fn ring_for(self, accent: Color) -> Color
pub fn ring_for(self, accent: Color) -> Color
A focus ring in accent that can actually be seen on this
theme’s bg: the accent moved toward the front of the base —
white on a dark one, black on a light one — until it clears the
3:1 a focus indicator needs.
Each base’s habit is where it starts: the dark one lifts a
saturated ring that would otherwise sink into the page, and the
light one takes the accent as it is, because most accents are
already dark enough on a near-white page. The loop is what turns
that from a hope into a promise — a light accent on the light
base is the case it exists for. macOS’s yellow taken verbatim is
1.49:1 on #f6f7f9, which is not a ring, it is a rumour.
Sourcepub fn ink_for(self, accent: Color) -> Color
pub fn ink_for(self, accent: Color) -> Color
accent as ink on surface — strokes, borders, short labels —
held to 3:1, the UI-edge grade, and painted verbatim when it
already reads. The devtools panel’s accent; the same
promise as ring_for with a different start,
since a fill that reads has no reason to move.
Sourcepub fn is_dark(self) -> bool
pub fn is_dark(self) -> bool
Whether this is a dark theme — the question a view asks when it has
a decision of its own to make (which of two images, how heavy a
shadow). Unknown answers the way derive does.
Sourcepub fn front(self) -> Color
pub fn front(self) -> Color
The front of this theme’s base: white on a dark one, black on a
light one — what raise moves toward and what
clears any contrast on the base by itself. The one fact about
contrast that is the theme’s rather than the colour’s.
Sourcepub fn raise(self, c: Color, t: f32) -> Color
pub fn raise(self, c: Color, t: f32) -> Color
c moved t of the way toward the front of this theme: lighter
on a dark one, darker on a light one. The arithmetic behind
“one step up from this surface”, written once so a view does not
have to branch on the appearance to get it right.
Sourcepub fn on(self, bg: Color) -> Color
pub fn on(self, bg: Color) -> Color
Black or white, whichever a reader can see on bg
(crate::widgets::readable_on).