pub struct MaterialThemeContext {
pub theme_mode: ThemeMode,
pub contrast_level: ContrastLevel,
pub material_theme: Option<MaterialThemeFile>,
pub selected_colors: HashMap<String, Color32>,
}Expand description
Global theme context that can be shared across all Material components
Fields§
§theme_mode: ThemeMode§contrast_level: ContrastLevel§material_theme: Option<MaterialThemeFile>§selected_colors: HashMap<String, Color32>Implementations§
Source§impl MaterialThemeContext
impl MaterialThemeContext
pub fn setup_fonts(font_name: Option<&str>)
pub fn setup_local_fonts(font_path: Option<&str>)
Sourcepub fn setup_local_theme(theme_path: Option<&str>)
pub fn setup_local_theme(theme_path: Option<&str>)
Internal implementation for preparing local themes from JSON files
This function handles the loading and parsing of Material Design theme JSON files. It supports both runtime file loading and build-time constant inclusion.
§Arguments
theme_path- Optional path to theme JSON file. If None, uses build-time constants.
§Implementation Details
- First attempts to load from specified file path (if provided)
- Falls back to build-time included theme constants
- Finally falls back to default built-in theme
- Parses JSON and stores in static PREPARED_THEMES collection
- Replaces any existing theme with the same name
Sourcepub fn load_themes()
pub fn load_themes()
Internal implementation for loading prepared themes to the global theme context
This function applies the first prepared theme from the PREPARED_THEMES collection as the active global theme. It creates a new MaterialThemeContext with the theme data and updates the global theme state.
§Behavior
- Takes the first theme from prepared themes collection
- Creates a MaterialThemeContext with default settings (Light mode, Normal contrast)
- Updates the global GLOBAL_THEME with the new context
- If no themes were prepared, the global theme remains unchanged
Sourcepub fn load_fonts(ctx: &Context)
pub fn load_fonts(ctx: &Context)
Load all prepared fonts to the egui context
pub fn get_current_scheme(&self) -> Option<&MaterialScheme>
pub fn hex_to_color32(hex: &str) -> Option<Color32>
pub fn color32_to_hex(color: Color32) -> String
pub fn get_color_by_name(&self, name: &str) -> Color32
pub fn get_primary_color(&self) -> Color32
pub fn get_secondary_color(&self) -> Color32
pub fn get_tertiary_color(&self) -> Color32
pub fn get_surface_color(&self, _dark_mode: bool) -> Color32
pub fn get_on_primary_color(&self) -> Color32
Trait Implementations§
Source§impl Clone for MaterialThemeContext
impl Clone for MaterialThemeContext
Source§fn clone(&self) -> MaterialThemeContext
fn clone(&self) -> MaterialThemeContext
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 moreSource§impl Debug for MaterialThemeContext
impl Debug for MaterialThemeContext
Auto Trait Implementations§
impl Freeze for MaterialThemeContext
impl RefUnwindSafe for MaterialThemeContext
impl Send for MaterialThemeContext
impl Sync for MaterialThemeContext
impl Unpin for MaterialThemeContext
impl UnwindSafe for MaterialThemeContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.