Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
    pub bg: Color,
    pub panel_bg: Color,
    pub border: Color,
    pub title_bg: Color,
    pub fg: Color,
    pub accent: Color,
    pub hover_bg: Color,
    pub press_bg: Color,
    pub dim: Color,
}
Expand description

A palette of named color roles, rather than a CSS-style cascade: draw code picks the role it means (theme.accent, theme.border) and the active Theme decides what color that resolves to.

This crate has no opinion on how an app picks between DARK and LIGHT (a manual toggle key, a SystemTheme from Event::ThemeChanged, or just always the same one): it only owns the two palettes themselves, so an app doesn’t have to invent one from scratch.

§Examples

use retroglyph_ui::Theme;

let theme = Theme::DARK;
assert_eq!(theme.fg, Theme::DARK.fg);
assert_ne!(theme.bg, Theme::LIGHT.bg);

Fields§

§bg: Color

The window/screen background, behind every panel.

§panel_bg: Color

A panel’s own background, layered over bg.

§border: Color

Panel borders and dividers.

§title_bg: Color

A panel title bar’s background.

§fg: Color

Default (non-emphasized) text.

§accent: Color

Emphasis: selection, focus rings, primary actions.

§hover_bg: Color

An interactive widget’s background while hovered.

§press_bg: Color

An interactive widget’s background while pressed.

§dim: Color

De-emphasized text (hints, secondary labels, disabled-looking text).

Implementations§

Source§

impl Theme

Source

pub const DARK: Self

A dark palette: light text on a near-black background.

Source

pub const LIGHT: Self

A light palette: dark text on a near-white background. Same role relationships as DARK (accent stays a legible blue, hover_bg/press_bg stay a step apart from panel_bg), inverted for contrast against a light background rather than just flipping each channel.

Contrast is higher than a typical OS light theme: retroglyph’s pseudo-graphics (gauges, progress bars, log lines) draw with a 2-color paletted look where every panel-bg/border/text pair has to be distinct at a glance with no sub-pixel anti-aliasing to soften the edges.

Source

pub const fn bg_for<Id>(&self, response: &Response<Id>, base: Color) -> Color

The background for an interactive widget in response’s current state, over base when idle. Precedence: pressed, then hovered, then base.

base is caller-supplied rather than defaulted to panel_bg so this composes with widgets that already take a backdrop, e.g. a bar drawn over title_bg instead of a panel.

§Examples
use retroglyph_ui::Theme;
use retroglyph_ui::Interaction;
use retroglyph_core::grid::{Pos, Rect};

let theme = Theme::DARK;
let mut interaction = Interaction::<u32>::default();
let response = interaction.interact(Rect::new(0, 0, 1, 1), 1, Default::default());
assert_eq!(theme.bg_for(&response, theme.panel_bg), theme.panel_bg);
Source

pub const fn fg_for<Id>(&self, response: &Response<Id>) -> Color

The foreground for an interactive widget in response’s current state. Precedence: pressed or focused, then hovered, then dim.

Idle interactive text reads as dim rather than fg: an interactive widget that looks identical to static text at rest gives no visual hint that it’s interactive at all, so the state that actually needs fg’s full contrast is hover, not idle.

§Examples
use retroglyph_ui::Theme;
use retroglyph_ui::Interaction;
use retroglyph_core::grid::{Pos, Rect};

let theme = Theme::DARK;
let mut interaction = Interaction::<u32>::default();
let response = interaction.interact(Rect::new(0, 0, 1, 1), 1, Default::default());
assert_eq!(theme.fg_for(&response), theme.dim);
Source

pub fn style_for<Id>(&self, response: &Response<Id>, base: Color) -> Style

The resolved Style for an interactive widget in response’s current state, over base when idle. Precedence: disabled, then pressed, then focused, then hovered, then idle.

Unlike bg_for/fg_for, which resolve each channel independently, style_for resolves both at once against a single, shared precedence order: that’s the only place disabled can cleanly take priority over everything else, and the only place a press (accent on press_bg) and a focus ring (accent on base, no background change) can be told apart instead of both collapsing into the same accent foreground.

base is caller-supplied for the same reason as bg_for: so this composes with widgets that already have their own backdrop.

This uses dim for the disabled foreground, same as idle; retroglyph has no separate disabled color role yet.

§Examples
use retroglyph_ui::Theme;
use retroglyph_ui::Interaction;
use retroglyph_core::grid::{Pos, Rect};

let theme = Theme::DARK;
let mut interaction = Interaction::<u32>::default();
let response = interaction.interact(Rect::new(0, 0, 1, 1), 1, Default::default());
let style = theme.style_for(&response, theme.panel_bg);
assert_eq!(style.foreground(), theme.dim);
assert_eq!(style.background(), theme.panel_bg);

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

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 Debug for Theme

Source§

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

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

impl<'de> Deserialize<'de> for Theme

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Theme

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Theme

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Theme

Source§

impl Eq for Theme

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,