pub trait ThemeRegistry: Send + Sync {
// Required methods
fn register(
&self,
name: ElementName,
owner: ElementOwner,
default: StyleSpec,
doc: &'static str,
) -> ElementId;
fn id(&self, name: &ElementName) -> Option<ElementId>;
fn resolved(&self) -> Arc<ResolvedTheme> ⓘ;
fn set_override(&self, name: ElementName, spec: StyleSpec);
fn set_theme(
&self,
palette: Palette,
overrides: Vec<(ElementName, StyleSpec)>,
);
fn describe(&self, name: &ElementName) -> Option<ElementInfo>;
fn element_names(&self) -> Vec<String>;
fn unregister_element(&self, name: &ElementName) -> bool;
fn register_theme(&self, theme: NamedTheme);
fn theme_names(&self) -> Vec<String>;
fn apply_theme(&self, name: &str) -> bool;
fn active_theme(&self) -> (Palette, Vec<(ElementName, StyleSpec)>);
}Expand description
Registration + resolution surface. Lives as a ServiceRegistry
service (T.3); modes reach it through the handle, never through
&mut Editor.
Required Methods§
Sourcefn 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.
Sourcefn id(&self, name: &ElementName) -> Option<ElementId>
fn id(&self, name: &ElementName) -> Option<ElementId>
The interned id for a name, if registered.
Sourcefn resolved(&self) -> Arc<ResolvedTheme> ⓘ
fn resolved(&self) -> Arc<ResolvedTheme> ⓘ
The current resolved read table (rebuilt lazily if a registration / palette change left it dirty).
Sourcefn 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()).
Sourcefn 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.
Sourcefn 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.
Sourcefn 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.
Sourcefn 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).
The slot is tombstoned, not deleted. ElementId is an index into
the element vector, so removing an entry would silently re-point every
later id at the wrong element — a far worse failure than a retained
slot. Withdrawing therefore drops the NAME binding only: id,
describe and element_names all resolve through by_name, so the
element disappears from every observable surface (lookup, :customize,
:describe-element) while ids already handed out stay valid and keep
resolving to their last style.
Any theme override the user set for the name is left in place: a plugin reload should not silently discard the user’s customisation, and a dangling override for an element that never comes back resolves to nothing.
Sourcefn 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.
Sourcefn 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.
Sourcefn 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).
Sourcefn 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".