ThemeContext

Struct ThemeContext 

Source
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

Source

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:

  1. User preference (if set)
  2. Document’s default_theme (if set)
  3. System preference (if follow_system is true)
  4. “light” fallback
§Arguments
  • document - The parsed theme document
  • system_preference - Optional detected system theme preference
§Errors

Returns ThemeError if the document is invalid or has no themes.

Source

pub fn active(&self) -> &Theme

Get the currently active theme.

§Returns

Reference to the active Theme.

Source

pub fn active_name(&self) -> &str

Get the name of the currently active theme.

Source

pub fn set_theme(&mut self, name: &str) -> Result<(), ThemeError>

Switch to a different theme by name.

§Arguments
  • name - The name of the theme to switch to
§Errors

Returns ThemeError::ThemeNotFound if the theme doesn’t exist.

Source

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”)
Source

pub fn set_follow_system(&mut self, follow: bool)

Set whether to follow system preference.

Source

pub fn follow_system(&self) -> bool

Check if currently following system preference.

Source

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
Source

pub fn available_themes(&self) -> Vec<&str>

Get all available theme names.

Source

pub fn has_theme(&self, name: &str) -> bool

Check if a theme with the given name exists.

Trait Implementations§

Source§

impl Clone for ThemeContext

Source§

fn clone(&self) -> ThemeContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ThemeContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.