♻️ Rename smart pointers components for clarity

This commit is contained in:
Manuel Cillero 2024-03-04 22:21:40 +01:00
parent 9a5618ef4b
commit d80a594cf5
18 changed files with 151 additions and 155 deletions

View file

@ -1,4 +1,4 @@
use crate::core::component::{AnyComponents, ArcAnyComponent, ArcAnyOp};
use crate::core::component::{MixedComponents, OneComponent, OneOp};
use crate::core::theme::ThemeRef;
use crate::{AutoDefault, LazyStatic, TypeId};
@ -12,29 +12,29 @@ static COMMON_REGIONS: LazyStatic<RwLock<ComponentsInRegions>> =
LazyStatic::new(|| RwLock::new(ComponentsInRegions::default()));
#[derive(AutoDefault)]
pub struct ComponentsInRegions(HashMap<&'static str, AnyComponents>);
pub struct ComponentsInRegions(HashMap<&'static str, MixedComponents>);
impl ComponentsInRegions {
pub fn new(region: &'static str, arc: ArcAnyComponent) -> Self {
pub fn new(region: &'static str, one: OneComponent) -> Self {
let mut regions = ComponentsInRegions::default();
regions.add_component_in(region, arc);
regions.add_in(region, one);
regions
}
pub fn add_component_in(&mut self, region: &'static str, arc: ArcAnyComponent) {
pub fn add_in(&mut self, region: &'static str, one: OneComponent) {
if let Some(region) = self.0.get_mut(region) {
region.alter_value(ArcAnyOp::Add(arc));
region.alter_value(OneOp::Add(one));
} else {
self.0.insert(region, AnyComponents::new(arc));
self.0.insert(region, MixedComponents::new(one));
}
}
pub fn get_components(&self, theme: ThemeRef, region: &str) -> AnyComponents {
pub fn get_components(&self, theme: ThemeRef, region: &str) -> MixedComponents {
let common = COMMON_REGIONS.read().unwrap();
if let Some(r) = THEME_REGIONS.read().unwrap().get(&theme.type_id()) {
AnyComponents::merge(&[common.0.get(region), self.0.get(region), r.0.get(region)])
MixedComponents::merge(&[common.0.get(region), self.0.get(region), r.0.get(region)])
} else {
AnyComponents::merge(&[common.0.get(region), self.0.get(region)])
MixedComponents::merge(&[common.0.get(region), self.0.get(region)])
}
}
}
@ -46,23 +46,20 @@ pub enum InRegion {
}
impl InRegion {
pub fn add_component(&self, arc: ArcAnyComponent) -> &Self {
pub fn add(&self, one: OneComponent) -> &Self {
match self {
InRegion::Content => {
COMMON_REGIONS
.write()
.unwrap()
.add_component_in("content", arc);
COMMON_REGIONS.write().unwrap().add_in("content", one);
}
InRegion::Named(name) => {
COMMON_REGIONS.write().unwrap().add_component_in(name, arc);
COMMON_REGIONS.write().unwrap().add_in(name, one);
}
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);
r.add_in(region, one);
} else {
regions.insert(theme.type_id(), ComponentsInRegions::new(region, arc));
regions.insert(theme.type_id(), ComponentsInRegions::new(region, one));
}
}
}