diff --git a/src/layout/color.rs b/src/layout/color.rs index 01f0457..c7d9ea6 100644 --- a/src/layout/color.rs +++ b/src/layout/color.rs @@ -44,8 +44,7 @@ impl Color { } } -#[const_trait] -pub trait F32Conversion { +pub const trait F32Conversion { fn to(self) -> f32; fn from(x: f32) -> Self; } diff --git a/src/layout/data.rs b/src/layout/data.rs new file mode 100644 index 0000000..3c85abc --- /dev/null +++ b/src/layout/data.rs @@ -0,0 +1,27 @@ +use std::any::{Any, TypeId}; + +use crate::util::{HashMap, Id}; + +#[derive(Default)] +pub struct UiData { + map: HashMap>, +} + +impl UiData { + pub fn get(&self) -> Option<&T> { + self.map + .get(&TypeId::of::()) + .map(|d| d.downcast_ref().unwrap()) + } + pub fn get_mut(&mut self) -> Option<&mut T> { + self.map + .get_mut(&TypeId::of::()) + .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(); + } + } +} diff --git a/src/layout/num.rs b/src/layout/num.rs index 571f728..c46b013 100644 --- a/src/layout/num.rs +++ b/src/layout/num.rs @@ -1,5 +1,4 @@ -#[const_trait] -pub trait UiNum { +pub const trait UiNum { fn to_f32(self) -> f32; } diff --git a/src/util/math.rs b/src/util/math.rs index 744889b..e4e6600 100644 --- a/src/util/math.rs +++ b/src/util/math.rs @@ -1,13 +1,11 @@ use std::ops::*; -#[const_trait] -pub trait LerpUtil { +pub const trait LerpUtil { fn lerp(self, from: Self, to: Self) -> Self; fn lerp_inv(self, from: Self, to: Self) -> Self; } -#[const_trait] -pub trait DivOr { +pub const trait DivOr { fn div_or(self, rhs: Self, other: Self) -> Self; }