28 lines
680 B
Rust
28 lines
680 B
Rust
use std::any::{Any, TypeId};
|
|
|
|
use crate::util::{HashMap, Id};
|
|
|
|
#[derive(Default)]
|
|
pub struct UiData {
|
|
map: HashMap<TypeId, Box<dyn Any>>,
|
|
}
|
|
|
|
impl UiData {
|
|
pub fn get<T: 'static>(&self) -> Option<&T> {
|
|
self.map
|
|
.get(&TypeId::of::<T>())
|
|
.map(|d| d.downcast_ref().unwrap())
|
|
}
|
|
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
|
self.map
|
|
.get_mut(&TypeId::of::<T>())
|
|
.map(|d| d.downcast_mut().unwrap())
|
|
}
|
|
|
|
pub fn emit_remove(&mut self, id: &Id) {
|
|
for (tid, f) in &mut self.on_remove {
|
|
let data = self.map.get_mut(tid).unwrap().downcast_ref().unwrap();
|
|
}
|
|
}
|
|
}
|