#[non_exhaustive]pub struct ThemeSpec {
pub base: String,
pub density: Density,
pub accent: Option<String>,
pub reduced_motion: bool,
pub overrides: BTreeMap<String, Value>,
pub counterpart: Counterpart,
pub counterpart_overrides: Option<BTreeMap<String, Value>>,
pub text_size: f32,
pub font_ui: Option<String>,
pub font_mono: Option<String>,
pub scroll_bars: ScrollBars,
}Expand description
What to resolve: a base theme (mode and contrast), a density, an accent,
reduced motion and the user’s own overrides, composed in that order.
The base theme’s counterpart (Counterpart), when it has one, is
resolved with the same density, accent, reduced motion and overrides
(Themes::resolve_counterpart), or with overrides of its own
(ThemeSpec::counterpart_overrides).
use egui_pop_tokens::{Density, ThemeSpec, Themes};
let spec = ThemeSpec::new("pop-light").density(Density::Compact).accent("blue");
let tokens = Themes::default().resolve(&spec);
assert!(tokens.problems().is_empty());
assert_eq!(tokens.dimension("space.m"), Some(4.0));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.base: StringThe base theme’s name (pop-dark, pop-light, …).
density: Density§accent: Option<String>A colour scale whose steps become the accent roles; None keeps
the base theme’s accent.
reduced_motion: boolSets motion.duration to zero.
overrides: BTreeMap<String, Value>Raw DTCG values by token path, applied last; values may be aliases.
counterpart: CounterpartThe other variant of the base theme, light or dark.
counterpart_overrides: Option<BTreeMap<String, Value>>The counterpart’s own overrides, in place of overrides: a pair
whose two variants are edited apart (the theme editor’s). None:
overrides apply to both.
text_size: f32The user’s text size: a factor of the size scale (font.size.*),
one of TEXT_SIZES; 1 keeps the theme’s sizes
(ThemeSpec::text_size).
font_ui: Option<String>A family the user puts first in font.family.ui, before the
theme’s own (which stay its fallbacks).
font_mono: Option<String>A family the user puts first in font.family.mono.
scroll_bars: ScrollBarsThe user’s choice over the theme’s scroll bars
(ThemeSpec::scroll_bars).
Implementations§
Source§impl ThemeSpec
impl ThemeSpec
pub fn new(base: impl Into<String>) -> ThemeSpec
Sourcepub fn pair(dark: impl Into<String>, light: impl Into<String>) -> ThemeSpec
pub fn pair(dark: impl Into<String>, light: impl Into<String>) -> ThemeSpec
A pair of themes, a dark one and a light one: dark is the base
(shown when nothing asks for light), light its counterpart.
use egui_pop_tokens::{ThemeSpec, Themes};
let spec = ThemeSpec::pair("github-dark", "pop-light");
let light = Themes::default().resolve_counterpart(&spec).unwrap();
assert_eq!(light.spec().base, "pop-light");
assert!(!light.is_dark());Sourcepub fn counterpart(self, theme: impl Into<String>) -> Self
pub fn counterpart(self, theme: impl Into<String>) -> Self
Names the base theme’s counterpart, whatever the token files say.
Sourcepub fn variant(&self, base: impl Into<String>) -> ThemeSpec
pub fn variant(&self, base: impl Into<String>) -> ThemeSpec
The same spec over another base theme, alone, with the same overrides.
Sourcepub fn counterpart_variant(&self, other: impl Into<String>) -> ThemeSpec
pub fn counterpart_variant(&self, other: impl Into<String>) -> ThemeSpec
What the counterpart other is resolved from: the same spec over
it, alone, with the counterpart’s own overrides when the spec
gives them (ThemeSpec::counterpart_overrides).
use egui_pop_tokens::{Color, ThemeSpec, Themes};
use serde_json::json;
let spec = ThemeSpec::new("pop-dark")
.override_token("danger", json!("#ff0000"))
.counterpart_override("danger", json!("#00ff00"));
let light = Themes::default().resolve_counterpart(&spec).unwrap();
assert_eq!(light.color("danger"), Color::from_hex("#00ff00"));
let dark = Themes::default().resolve(&spec);
assert_eq!(dark.color("danger"), Color::from_hex("#ff0000"));pub fn density(self, density: Density) -> Self
Sourcepub fn accent(self, scale: impl Into<String>) -> Self
pub fn accent(self, scale: impl Into<String>) -> Self
The accent: a colour scale of the theme by name ("blue"), or a
seed colour ("#3a7bd5") the scale is generated from
(ThemeSpec::accent_color).
Sourcepub fn accent_color(self, seed: Color) -> Self
pub fn accent_color(self, seed: Color) -> Self
An accent generated from a seed colour: the SEED_SCALE scale
(palette::Ramp), for the theme’s light
or dark scheme, the seed clamped to what gives a usable ramp. A
counterpart gets the ramp of its own scheme from the same seed.
use egui_pop_tokens::{Color, ThemeSpec, Themes, contrast};
let spec = ThemeSpec::new("pop-light").accent_color(Color::from_hex("#c0392b").unwrap());
assert_eq!(spec.accent.as_deref(), Some("#c0392b"));
let tokens = Themes::default().resolve(&spec);
assert_eq!(tokens.get("accent.default").unwrap().alias.as_deref(), Some("custom.9"));
assert!(contrast::check(&tokens, contrast::Level::Normal).is_empty());Sourcepub fn accent_seed(&self) -> Option<Color>
pub fn accent_seed(&self) -> Option<Color>
The accent’s seed colour, when the accent is one (#rrggbb).
pub fn reduced_motion(self, reduced: bool) -> Self
Sourcepub fn text_size(self, factor: f32) -> Self
pub fn text_size(self, factor: f32) -> Self
The user’s text size, a factor of the theme’s size scale, rounded
to the nearest of TEXT_SIZES: each step of font.size.* is
multiplied and rounded to half a point, and every text style and
component token aliasing a step follows. Only the text grows:
spacing does not (the interface zoom scales everything), and
size.control.height grows to at least 1.6 times the body text,
so a larger label is not clipped.
use egui_pop_tokens::{ThemeSpec, Themes};
let themes = Themes::default();
let base = themes.resolve(&ThemeSpec::new("pop-dark"));
let large = themes.resolve(&ThemeSpec::new("pop-dark").text_size(1.3));
assert_eq!(base.dimension("font.size.m"), Some(13.0));
assert_eq!(large.dimension("font.size.m"), Some(17.0));
assert_eq!(large.dimension("font.text-style.body"), Some(17.0));
assert_eq!(large.dimension("space.m"), base.dimension("space.m"));Sourcepub fn scroll_bars(self, choice: ScrollBars) -> Self
pub fn scroll_bars(self, choice: ScrollBars) -> Self
The user’s choice over the theme’s scroll bars: scroll-bar.visibility
and placement take it when the theme resolves, for the theme and its
counterpart. Auto leaves the theme’s.
use egui_pop_tokens::{ScrollBars, ThemeSpec, Themes, Value};
let themes = Themes::default();
let full = themes.resolve(&ThemeSpec::new("pop-dark").scroll_bars(ScrollBars::Always));
let visibility = &full.get("scroll-bar.visibility").unwrap().value;
assert_eq!(visibility, &Value::Other("always".into()));Sourcepub fn font_ui(self, family: Option<String>) -> Self
pub fn font_ui(self, family: Option<String>) -> Self
A family drawn first for interface text (font.family.ui), the
theme’s own families after it; None keeps the theme’s.
Sourcepub fn font_mono(self, family: Option<String>) -> Self
pub fn font_mono(self, family: Option<String>) -> Self
A family drawn first for numbers and code (font.family.mono).
Sourcepub fn override_token(self, path: impl Into<String>, value: Json) -> Self
pub fn override_token(self, path: impl Into<String>, value: Json) -> Self
Overrides one token with a raw DTCG value (json!("#3080ff"),
json!("{blue.9}")).
Sourcepub fn counterpart_override(self, path: impl Into<String>, value: Json) -> Self
pub fn counterpart_override(self, path: impl Into<String>, value: Json) -> Self
Overrides one token of the counterpart only: from the first one,
the counterpart has overrides of its own
(ThemeSpec::counterpart_overrides), starting empty.