💄 Change to THEME_DEFAULT name & improve regions

This commit is contained in:
Manuel Cillero 2024-02-27 17:48:40 +01:00
parent 2cd1d1332c
commit 470223e684
4 changed files with 28 additions and 18 deletions

View file

@ -1,5 +1,5 @@
use crate::base::component::add_base_assets; use crate::base::component::add_base_assets;
use crate::core::theme::all::{theme_by_single_name, THEME}; use crate::core::theme::all::{theme_by_single_name, THEME_DEFAULT};
use crate::core::theme::ThemeRef; use crate::core::theme::ThemeRef;
use crate::html::{html, Assets, HeadScript, HeadStyles, JavaScript, Markup, StyleSheet}; use crate::html::{html, Assets, HeadScript, HeadStyles, JavaScript, Markup, StyleSheet};
use crate::locale::{LanguageIdentifier, LANGID_DEFAULT}; use crate::locale::{LanguageIdentifier, LANGID_DEFAULT};
@ -47,7 +47,7 @@ impl Context {
Context { Context {
request, request,
langid : &LANGID_DEFAULT, langid : &LANGID_DEFAULT,
theme : *THEME, theme : *THEME_DEFAULT,
stylesheet: Assets::<StyleSheet>::new(), // Stylesheets. stylesheet: Assets::<StyleSheet>::new(), // Stylesheets.
headstyles: Assets::<HeadStyles>::new(), // Styles in head. headstyles: Assets::<HeadStyles>::new(), // Styles in head.
javascript: Assets::<JavaScript>::new(), // JavaScripts. javascript: Assets::<JavaScript>::new(), // JavaScripts.
@ -64,7 +64,7 @@ impl Context {
self.langid = langid; self.langid = langid;
} }
ContextOp::Theme(theme_name) => { ContextOp::Theme(theme_name) => {
self.theme = theme_by_single_name(theme_name).unwrap_or(*THEME); self.theme = theme_by_single_name(theme_name).unwrap_or(*THEME_DEFAULT);
} }
// Stylesheets. // Stylesheets.

View file

@ -3,6 +3,6 @@ pub use definition::{ThemeRef, ThemeTrait};
mod regions; mod regions;
pub(crate) use regions::ComponentsInRegions; pub(crate) use regions::ComponentsInRegions;
pub use regions::{add_component_in, Region}; pub use regions::InRegion;
pub(crate) mod all; pub(crate) mod all;

View file

@ -10,7 +10,7 @@ pub static THEMES: LazyStatic<RwLock<Vec<ThemeRef>>> = LazyStatic::new(|| RwLock
// DEFAULT THEME *********************************************************************************** // DEFAULT THEME ***********************************************************************************
pub static THEME: LazyStatic<ThemeRef> = pub static THEME_DEFAULT: LazyStatic<ThemeRef> =
LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) { LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) {
Some(theme) => theme, Some(theme) => theme,
None => &crate::base::theme::Inception, None => &crate::base::theme::Inception,

View file

@ -39,23 +39,33 @@ impl ComponentsInRegions {
} }
} }
pub enum Region { pub enum InRegion {
Content,
Named(&'static str), Named(&'static str),
OfTheme(ThemeRef, &'static str), OfTheme(&'static str, ThemeRef),
} }
pub fn add_component_in(region: Region, arc: ArcAnyComponent) { impl InRegion {
match region { pub fn add_component(&self, arc: ArcAnyComponent) -> &Self {
Region::Named(name) => { match self {
COMMON_REGIONS.write().unwrap().add_component_in(name, arc); InRegion::Content => {
} COMMON_REGIONS
Region::OfTheme(theme, region) => { .write()
let mut regions = THEME_REGIONS.write().unwrap(); .unwrap()
if let Some(r) = regions.get_mut(&theme.type_id()) { .add_component_in("content", arc);
r.add_component_in(region, arc); }
} else { InRegion::Named(name) => {
regions.insert(theme.type_id(), ComponentsInRegions::new(region, arc)); COMMON_REGIONS.write().unwrap().add_component_in(name, arc);
}
InRegion::OfTheme(region, theme) => {
let mut regions = THEME_REGIONS.write().unwrap();
if let Some(r) = regions.get_mut(&theme.type_id()) {
r.add_component_in(region, arc);
} else {
regions.insert(theme.type_id(), ComponentsInRegions::new(region, arc));
}
} }
} }
self
} }
} }