Skip to main content

Theme

Struct Theme 

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

Which base this was built from. Unknown means the host never said, and the dark base stands — see Theme::derive.

§bg: Color

The window behind everything.

§surface: Color

A card, panel or list sitting on bg.

§raised: Color

A 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: Color

A well cut into a surface: a text field, a code block, a track.

§border: Color

The hairline between two surfaces.

§border_strong: Color

A border that has to be seen — a float’s edge, a focused field.

§fg: Color

Body text. What a TextStyle with no colour of its own resolves to, which is what makes <text>hello</text> legible on both bases.

§muted: Color

Secondary text: captions, hints, an accelerator beside a label.

§faint: Color

Text that is barely there: a placeholder, a gutter number.

§accent: Color

The 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: Color

accent under a pointer, and under a press.

§accent_pressed: Color§on_accent: Color

Black or white — whichever a reader can see on accent.

§accent_soft: Color

The 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: Color

What a text selection is painted under. Translucent: the glyphs under it keep their own colour.

§focus_ring: Color

The default keyboard focus ring.

§hover: Color

A 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: f32

What a disabled control’s opacity is multiplied by.

§success: Color§warning: Color§danger: Color§scrollbar: Color

The scrollbar thumb at rest, and while hovered or dragged.

§scrollbar_active: Color

Implementations§

Source§

impl Theme

Source

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.

Source

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.

Source

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.

Source

pub fn from_system(sys: &SystemEnv) -> Self

derive from a whole SystemEnv, which is how the core does it every frame.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn on(self, bg: Color) -> Color

Black or white, whichever a reader can see on bg (crate::widgets::readable_on).

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Theme

Source§

impl Debug for Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

The dark base with kui’s own accent: what this crate painted before themes existed.

Source§

impl PartialEq for Theme

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.