pub struct Theme {
pub meta: ThemeMeta,
/* private fields */
}Expand description
A fully resolved theme ready for use.
Contains resolved palette colors, semantic tokens, composed styles, and
gradients. Access colors by token name with color(),
styles by name with style(), and gradients with
gradient().
Fields§
§meta: ThemeMetaImplementations§
Source§impl Theme
impl Theme
Sourcepub fn from_resolved(meta: ThemeMeta, resolved: ResolvedTheme) -> Self
pub fn from_resolved(meta: ThemeMeta, resolved: ResolvedTheme) -> Self
Construct a Theme from pre-resolved data.
For most use cases, prefer load_from_str
or load_from_file. Use this when you
have already run the resolution pipeline yourself.
Sourcepub fn builder(name: impl Into<String>) -> ThemeBuilder
pub fn builder(name: impl Into<String>) -> ThemeBuilder
Start building a theme programmatically.
See ThemeBuilder for the full builder API.
Sourcepub fn color(&self, token: &str) -> OpalineColor
pub fn color(&self, token: &str) -> OpalineColor
Look up a color by token name, falling back to palette, then FALLBACK.
Sourcepub fn try_color(&self, token: &str) -> Option<OpalineColor>
pub fn try_color(&self, token: &str) -> Option<OpalineColor>
Strict color lookup — returns None if the token doesn’t exist.
Sourcepub fn token_names(&self) -> Vec<&str>
pub fn token_names(&self) -> Vec<&str>
All token names defined in this theme.
Sourcepub fn palette_names(&self) -> Vec<&str>
pub fn palette_names(&self) -> Vec<&str>
All palette color names defined in this theme.
Sourcepub fn style(&self, name: &str) -> OpalineStyle
pub fn style(&self, name: &str) -> OpalineStyle
Look up a style by name, returning Default if missing.
Sourcepub fn try_style(&self, name: &str) -> Option<&OpalineStyle>
pub fn try_style(&self, name: &str) -> Option<&OpalineStyle>
Strict style lookup — returns None if the style doesn’t exist.
Sourcepub fn style_names(&self) -> Vec<&str>
pub fn style_names(&self) -> Vec<&str>
All style names defined in this theme.
Sourcepub fn gradient(&self, name: &str, t: f32) -> OpalineColor
pub fn gradient(&self, name: &str, t: f32) -> OpalineColor
Sample a named gradient at position t. Returns FALLBACK if the
gradient doesn’t exist or the feature is disabled.
Sourcepub fn try_gradient(&self, name: &str, t: f32) -> Option<OpalineColor>
pub fn try_gradient(&self, name: &str, t: f32) -> Option<OpalineColor>
Strict gradient sampling — returns None if the gradient doesn’t exist.
Sourcepub fn get_gradient(&self, name: &str) -> Option<&Gradient>
pub fn get_gradient(&self, name: &str) -> Option<&Gradient>
Get a reference to a named gradient for manual sampling.
Sourcepub fn has_gradient(&self, name: &str) -> bool
pub fn has_gradient(&self, name: &str) -> bool
Check whether a named gradient exists.
Sourcepub fn gradient_names(&self) -> Vec<&str>
pub fn gradient_names(&self) -> Vec<&str>
All gradient names defined in this theme.
Sourcepub fn register_default_token(
&mut self,
name: impl Into<String>,
color: OpalineColor,
)
pub fn register_default_token( &mut self, name: impl Into<String>, color: OpalineColor, )
Register a token only if the theme doesn’t already define it.
Use this for app-level derived tokens — TOML-defined values take priority so theme authors can override derivations.
Sourcepub fn register_token(&mut self, name: impl Into<String>, color: OpalineColor)
pub fn register_token(&mut self, name: impl Into<String>, color: OpalineColor)
Register a token, overwriting any existing value.
Sourcepub fn register_default_style(
&mut self,
name: impl Into<String>,
style: OpalineStyle,
)
pub fn register_default_style( &mut self, name: impl Into<String>, style: OpalineStyle, )
Register a style only if the theme doesn’t already define it.
Sourcepub fn register_style(&mut self, name: impl Into<String>, style: OpalineStyle)
pub fn register_style(&mut self, name: impl Into<String>, style: OpalineStyle)
Register a style, overwriting any existing value.
Source§impl Theme
impl Theme
Sourcepub fn span<'a>(
&self,
style_name: &str,
content: impl Into<Cow<'a, str>>,
) -> Span<'a>
pub fn span<'a>( &self, style_name: &str, content: impl Into<Cow<'a, str>>, ) -> Span<'a>
Create a styled Span from a named style.
Sourcepub fn line<'a>(
&self,
style_name: &str,
content: impl Into<Cow<'a, str>>,
) -> Line<'a>
pub fn line<'a>( &self, style_name: &str, content: impl Into<Cow<'a, str>>, ) -> Line<'a>
Create a styled Line from a named style.
Trait Implementations§
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,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more