pub struct ThemeContext { /* private fields */ }Expand description
Runtime theme context shared across all windows.
This struct manages theme state including:
- The currently active theme
- All loaded themes from theme.dampen
- System preference detection
- User preference persistence
§Examples
ⓘ
use dampen_core::{parse_theme_document, ThemeContext};
let xml = r#"<dampen><themes><theme name="light">...</theme></themes></dampen>"#;
let doc = parse_theme_document(xml).unwrap();
let ctx = ThemeContext::from_document(doc, Some("dark"));
assert_eq!(ctx.active().name, "dark");Implementations§
Source§impl ThemeContext
impl ThemeContext
Sourcepub fn from_document(
document: ThemeDocument,
system_preference: Option<&str>,
) -> Result<Self, ThemeError>
pub fn from_document( document: ThemeDocument, system_preference: Option<&str>, ) -> Result<Self, ThemeError>
Create a ThemeContext from a parsed ThemeDocument.
The active theme is determined by:
- User preference (if set)
- Document’s default_theme (if set)
- System preference (if follow_system is true)
- “light” fallback
§Arguments
document- The parsed theme documentsystem_preference- Optional detected system theme preference
§Errors
Returns ThemeError if the document is invalid or has no themes.
Sourcepub fn active_name(&self) -> &str
pub fn active_name(&self) -> &str
Get the name of the currently active theme.
Sourcepub fn update_system_preference(&mut self, preference: &str)
pub fn update_system_preference(&mut self, preference: &str)
Update the system preference and potentially switch theme.
If the document is configured to follow system preference, this will switch to the system theme if it exists.
§Arguments
preference- The new system preference (“light” or “dark”)
Sourcepub fn set_follow_system(&mut self, follow: bool)
pub fn set_follow_system(&mut self, follow: bool)
Set whether to follow system preference.
Sourcepub fn follow_system(&self) -> bool
pub fn follow_system(&self) -> bool
Check if currently following system preference.
Sourcepub fn reload(&mut self, document: ThemeDocument)
pub fn reload(&mut self, document: ThemeDocument)
Reload themes from a new document (for hot-reload).
Preserves the current active theme if it exists in the new document, otherwise falls back to the new document’s default.
§Arguments
document- The new parsed theme document
Sourcepub fn available_themes(&self) -> Vec<&str>
pub fn available_themes(&self) -> Vec<&str>
Get all available theme names.
Trait Implementations§
Source§impl Clone for ThemeContext
impl Clone for ThemeContext
Source§fn clone(&self) -> ThemeContext
fn clone(&self) -> ThemeContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ThemeContext
impl RefUnwindSafe for ThemeContext
impl Send for ThemeContext
impl Sync for ThemeContext
impl Unpin for ThemeContext
impl UnwindSafe for ThemeContext
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