feat: get desktop working with just creation
This commit is contained in:
1 parent
8caabb97d8
commit
e8ae830cf2
16 files changed
+1301
-329
No files matched your search
@@ -1,8 +1,9 @@
|
||||
use crate::{any_props::AnyProps, arena::ElementId, ScopeId, ScopeState};
|
||||
use crate::{any_props::AnyProps, arena::ElementId, ScopeId, ScopeState, UiEvent};
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
cell::{Cell, RefCell},
|
||||
hash::Hasher,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
pub type TemplateId = &'static str;
|
||||
@@ -154,6 +155,27 @@ pub enum AttributeValue<'a> {
|
||||
None,
|
||||
}
|
||||
|
||||
impl<'a> AttributeValue<'a> {
|
||||
pub fn new_listener<T: 'static>(
|
||||
cx: &'a ScopeState,
|
||||
mut f: impl FnMut(UiEvent<T>) + 'a,
|
||||
) -> AttributeValue<'a> {
|
||||
let f = cx.bump().alloc(move |a: &dyn Any| {
|
||||
a.downcast_ref::<UiEvent<T>>()
|
||||
.map(|a| f(a.clone()))
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Expected UiEvent<{}>, got {:?}",
|
||||
std::any::type_name::<T>(),
|
||||
a
|
||||
)
|
||||
})
|
||||
}) as &mut dyn FnMut(&dyn Any);
|
||||
|
||||
AttributeValue::Listener(RefCell::new(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::fmt::Debug for AttributeValue<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
Reference in new issue
Block a user