🔥 Refactor TypeId/Any use, drop own Handle
This commit is contained in:
parent
8402b7946e
commit
169e562488
59 changed files with 137 additions and 289 deletions
|
|
@ -118,10 +118,11 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.handle() {
|
||||
BLOCK_COMPONENT => {
|
||||
let block = component_as_mut::<Block>(component);
|
||||
block.alter_title("New title");
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
if let Some(b) = component_as_mut::<Block>(component) {
|
||||
b.alter_title("New title");
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
|
@ -138,10 +139,11 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.handle() {
|
||||
BLOCK_COMPONENT => {
|
||||
let block = component_as_mut::<Block>(component);
|
||||
block.alter_title("New title");
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
if let Some(b) = component_as_mut::<Block>(component) {
|
||||
b.alter_title("New title");
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
|
@ -159,13 +161,9 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.handle() {
|
||||
BLOCK_COMPONENT => {
|
||||
let block = component_as_ref::<Block>(component);
|
||||
match block.template() {
|
||||
"default" => Some(block_default(block)),
|
||||
_ => None,
|
||||
}
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
Some(block_default(block))
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::core::component::{AnyComponents, ArcAnyComponent, ArcAnyOp};
|
||||
use crate::core::theme::ThemeRef;
|
||||
use crate::{Handle, LazyStatic, SmartDefault};
|
||||
use crate::{LazyStatic, SmartDefault, TypeId};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
|
||||
static THEME_REGIONS: LazyStatic<RwLock<HashMap<Handle, ComponentsInRegions>>> =
|
||||
static THEME_REGIONS: LazyStatic<RwLock<HashMap<TypeId, ComponentsInRegions>>> =
|
||||
LazyStatic::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
static COMMON_REGIONS: LazyStatic<RwLock<ComponentsInRegions>> =
|
||||
|
|
@ -31,7 +31,7 @@ impl ComponentsInRegions {
|
|||
|
||||
pub fn get_components(&self, theme: ThemeRef, region: &str) -> AnyComponents {
|
||||
let common = COMMON_REGIONS.read().unwrap();
|
||||
if let Some(r) = THEME_REGIONS.read().unwrap().get(&theme.handle()) {
|
||||
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)])
|
||||
} else {
|
||||
AnyComponents::merge(&[common.0.get(region), self.0.get(region)])
|
||||
|
|
@ -51,10 +51,10 @@ pub fn add_component_in(region: Region, arc: ArcAnyComponent) {
|
|||
}
|
||||
Region::OfTheme(theme, region) => {
|
||||
let mut regions = THEME_REGIONS.write().unwrap();
|
||||
if let Some(r) = regions.get_mut(&theme.handle()) {
|
||||
if let Some(r) = regions.get_mut(&theme.type_id()) {
|
||||
r.add_component_in(region, arc);
|
||||
} else {
|
||||
regions.insert(theme.handle(), ComponentsInRegions::new(region, arc));
|
||||
regions.insert(theme.type_id(), ComponentsInRegions::new(region, arc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue