pub struct Theme { /* private fields */ }Expand description
A mapping from SemanticRole to ResolvedStyle.
Themes provide a reusable appearance layer: the consumer assigns semantic roles, and the theme determines what each role looks like. This keeps style definitions shared across consumers instead of duplicated.
Missing roles fall back to ResolvedStyle::default().
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a theme with the given name and empty style map.
Sourcepub fn set_base_fonts(&mut self, families: Vec<String>)
pub fn set_base_fonts(&mut self, families: Vec<String>)
Set the base (body) font families.
Sourcepub fn set_mono_fonts(&mut self, families: Vec<String>)
pub fn set_mono_fonts(&mut self, families: Vec<String>)
Set the monospace font families.
Sourcepub fn base_fonts(&self) -> &[String]
pub fn base_fonts(&self) -> &[String]
Base font families.
Sourcepub fn mono_fonts(&self) -> &[String]
pub fn mono_fonts(&self) -> &[String]
Monospace font families.
Sourcepub fn set_style(&mut self, role: SemanticRole, style: ResolvedStyle)
pub fn set_style(&mut self, role: SemanticRole, style: ResolvedStyle)
Register a style for a semantic role.
Sourcepub fn style_for(&self, role: SemanticRole) -> ResolvedStyle
pub fn style_for(&self, role: SemanticRole) -> ResolvedStyle
Get the style for a semantic role, falling back to ResolvedStyle::default().
Sourcepub fn has_style(&self, role: SemanticRole) -> bool
pub fn has_style(&self, role: SemanticRole) -> bool
Check whether a style is registered for the given role.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&SemanticRole, &ResolvedStyle)>
pub fn iter(&self) -> impl Iterator<Item = (&SemanticRole, &ResolvedStyle)>
Iterate all registered (role, style) pairs.
Sourcepub fn merge(&mut self, overlay: &Theme)
pub fn merge(&mut self, overlay: &Theme)
Merge another theme on top of this one.
Styles from overlay replace styles in self for the same role.
Styles in self that are not in overlay are preserved.
Font families from overlay replace those in self if non-empty.
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, ThemeLoadError>
pub fn load(path: impl AsRef<Path>) -> Result<Self, ThemeLoadError>
Load a theme from a TOML file.
The loaded theme is merged on top of the default theme, so only overridden roles need to be specified.
Sourcepub fn from_toml(toml_str: &str) -> Result<Self, ThemeLoadError>
pub fn from_toml(toml_str: &str) -> Result<Self, ThemeLoadError>
Parse a theme from a TOML string.
The parsed theme is merged on top of the default theme, so only overridden roles need to be specified.