pub struct InMemoryThemeRegistry { /* private fields */ }Expand description
In-memory ThemeRegistry. Holds the element table + active
palette behind an RwLock, and the resolved read table behind an
ArcSwap for lock-free reads.
Implementations§
Source§impl InMemoryThemeRegistry
impl InMemoryThemeRegistry
Sourcepub fn new(palette: Palette) -> Self
pub fn new(palette: Palette) -> Self
Empty registry with the given palette. Register elements, then
resolved() builds the table on first read.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Registry seeded with the default palette + all builtin core elements, resolved and ready. The T.3 boot path + tests use this.
Sourcepub fn set_palette(&self, palette: Palette)
pub fn set_palette(&self, palette: Palette)
Replace the active palette (a :colorscheme / :set ui.*
path lands in T.9). Marks the table dirty.
Sourcepub fn rebuild(&self)
pub fn rebuild(&self)
Re-resolve every element into a fresh ResolvedTheme and
publish it. Called on dirty reads; O(elements), theme-build
time only (never on the hot path).
Trait Implementations§
Source§impl ThemeRegistry for InMemoryThemeRegistry
impl ThemeRegistry for InMemoryThemeRegistry
Source§fn register(
&self,
name: ElementName,
owner: ElementOwner,
default: StyleSpec,
doc: &'static str,
) -> ElementId
fn register( &self, name: ElementName, owner: ElementOwner, default: StyleSpec, doc: &'static str, ) -> ElementId
Register an element with its owner-supplied default. Idempotent
by name — re-registering an existing name returns the existing
id and leaves its default unchanged.
Source§fn id(&self, name: &ElementName) -> Option<ElementId>
fn id(&self, name: &ElementName) -> Option<ElementId>
The interned id for a name, if registered.
Source§fn unregister_element(&self, name: &ElementName) -> bool
fn unregister_element(&self, name: &ElementName) -> bool
TC.4: withdraw an element by name — the reverse of
Self::register,
used when a plugin unloads. Returns whether a name was removed
(idempotent: a second unload removes nothing). Read moreSource§fn resolved(&self) -> Arc<ResolvedTheme> ⓘ
fn resolved(&self) -> Arc<ResolvedTheme> ⓘ
The current resolved read table (rebuilt lazily if a
registration / palette change left it dirty).
Source§fn set_override(&self, name: ElementName, spec: StyleSpec)
fn set_override(&self, name: ElementName, spec: StyleSpec)
T.9: set (or replace) the theme-global override for an element
(
:set ui.*, user TOML, a theme’s override list). Overlays the
override’s set fields on the element’s resolved default. Marks
the table dirty (re-resolved on next resolved()).Source§fn set_theme(&self, palette: Palette, overrides: Vec<(ElementName, StyleSpec)>)
fn set_theme(&self, palette: Palette, overrides: Vec<(ElementName, StyleSpec)>)
T.9: swap the active theme — replace the palette AND the full
override set atomically (
:colorscheme). Prior overrides are
cleared. Marks the table dirty.Source§fn register_theme(&self, theme: NamedTheme)
fn register_theme(&self, theme: NamedTheme)
T.11.1: register (or replace, by name) a named theme in the
catalog. Idempotent by name — re-registering a name replaces its
palette + overrides. This is the seam
init.rs (and, later, a
WASM plugin via WIT) uses to contribute a palette; the builtin
themes are seeded here at boot. Does NOT change the active theme —
only apply_theme does that.Source§fn theme_names(&self) -> Vec<String>
fn theme_names(&self) -> Vec<String>
T.11.1: the names of every registered theme, in registration
order (builtins first, then user/plugin additions). Drives
:colorscheme completion + the T.12 picker.Source§fn element_names(&self) -> Vec<String>
fn element_names(&self) -> Vec<String>
T.9.d follow-up: the names of every registered theme element, sorted.
Drives
:describe-element / :describe-face <Tab> completion (the
gen:elements host generator). Sorted so popup ordering is stable
across runs; a theme-build-time read, never on the hot path.Source§fn apply_theme(&self, name: &str) -> bool
fn apply_theme(&self, name: &str) -> bool
T.11.1: swap the active theme to the registered theme
name
(:colorscheme <name>). Returns false (active theme untouched)
if name is not registered — the caller echoes an error, never a
panic. On a hit, equivalent to set_theme with the registered
theme’s palette + overrides (marks the table dirty).Source§fn active_theme(&self) -> (Palette, Vec<(ElementName, StyleSpec)>)
fn active_theme(&self) -> (Palette, Vec<(ElementName, StyleSpec)>)
T.12a: snapshot the active palette + the active theme-global
override set as a
(Palette, Vec<(ElementName, StyleSpec)>)
pair. The colorscheme picker captures this on the first live
preview so <Esc> can restore the theme active when the picker
opened via Self::set_theme. Cheap clone of the inner state
under a read lock; no resolution.Source§fn describe(&self, name: &ElementName) -> Option<ElementInfo>
fn describe(&self, name: &ElementName) -> Option<ElementInfo>
T.9.d: element metadata for introspection (
:describe-element
/ :describe-face). Returns the element’s identity + owner +
authoring default + doc + concrete resolved style, or None if
name is not a registered element. Reads the resolved table
(rebuilding it lazily if dirty) so the resolved field reflects
the active theme — a theme-build-time read, never on the hot
path.Auto Trait Implementations§
impl !Freeze for InMemoryThemeRegistry
impl RefUnwindSafe for InMemoryThemeRegistry
impl Send for InMemoryThemeRegistry
impl Sync for InMemoryThemeRegistry
impl Unpin for InMemoryThemeRegistry
impl UnsafeUnpin for InMemoryThemeRegistry
impl UnwindSafe for InMemoryThemeRegistry
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
Mutably borrows from an owned value. Read more