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,
pub disabled: Color,
pub danger: Color,
pub success: 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::Theme;
let theme = Theme::DARK;
assert_eq!(theme.fg, Theme::DARK.fg);
assert_ne!(theme.bg, Theme::LIGHT.bg);Fields§
§bg: ColorThe window/screen background, behind every panel.
panel_bg: ColorA panel’s own background, layered over bg.
border: ColorPanel borders and dividers.
title_bg: ColorA panel title bar’s background.
fg: ColorDefault (non-emphasized) text.
accent: ColorEmphasis: selection, focus rings, primary actions.
hover_bg: ColorAn interactive widget’s background while hovered.
press_bg: ColorAn interactive widget’s background while pressed.
dim: ColorDe-emphasized text (hints, secondary labels).
disabled: ColorForeground for a disabled interactive widget. Distinct from dim: dim
marks idle-but-usable text as secondary, while disabled marks a widget the user
cannot interact with at all, and the two need to read differently at a glance.
danger: ColorDestructive/error emphasis: delete actions, validation failures, critical alerts.
success: ColorPositive/confirmation emphasis: completed states, successful actions.
Implementations§
Source§impl Theme
impl Theme
Sourcepub const LIGHT: Self
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.
Sourcepub const fn bg_for<Id>(&self, response: &Response<Id>, base: Color) -> Color
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. Delegates to WidgetState::of for the precedence order; see there for why
disabled now takes priority over everything else.
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::Theme;
use retroglyph_ui::interact::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);Sourcepub const fn fg_for<Id>(&self, response: &Response<Id>) -> Color
pub const fn fg_for<Id>(&self, response: &Response<Id>) -> Color
The foreground for an interactive widget in response’s current state. Delegates to
WidgetState::of for the precedence order.
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::Theme;
use retroglyph_ui::interact::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);Sourcepub fn style_for<Id>(&self, response: &Response<Id>, base: Color) -> Style
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. Delegates to WidgetState::of for the precedence order.
Resolves both channels at once against a single, shared precedence order, rather than
composing bg_for and fg_for independently: that’s 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 disabled for the disabled foreground, distinct from
dim’s idle look.
§Examples
use retroglyph_ui::theme::Theme;
use retroglyph_ui::interact::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§
impl Copy for Theme
Source§impl<'de> Deserialize<'de> for Theme
impl<'de> Deserialize<'de> for Theme
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Theme
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).