diff --git a/src/layout/ui.rs b/src/layout/ui.rs index 0cb28cb..834c0ac 100644 --- a/src/layout/ui.rs +++ b/src/layout/ui.rs @@ -31,8 +31,12 @@ impl From for UIBuilder { } impl UIBuilder { - pub fn add(&mut self, w: W) -> WidgetRef { - WidgetRef::new(self.clone(), [self.push(w)]) + pub fn add(&mut self, w: impl WidgetLike) -> WidgetRef { + WidgetRef::new([w.add(self).erase_type()]) + } + + pub fn add_widget(&mut self, w: W) -> WidgetRef { + WidgetRef::new([self.push(w)]) } pub fn push(&mut self, w: W) -> WidgetId { diff --git a/src/layout/widget.rs b/src/layout/widget.rs index 9700dac..417b115 100644 --- a/src/layout/widget.rs +++ b/src/layout/widget.rs @@ -15,21 +15,19 @@ impl Widget for (W,) { } } +pub struct AnyWidget; + #[derive(Eq, Hash, PartialEq, Debug)] -pub struct WidgetId { +pub struct WidgetId { pub(super) ty: TypeId, pub(super) id: ID, _pd: PhantomData, } // TODO: temp -impl Clone for WidgetId { +impl Clone for WidgetId { fn clone(&self) -> Self { - Self { - ty: self.ty, - id: self.id.duplicate(), - _pd: self._pd, - } + Self::new(self.id.duplicate(), self.ty) } } @@ -41,7 +39,7 @@ impl WidgetId { _pd: PhantomData, } } - pub fn erase_type(self) -> WidgetId<()> { + pub fn erase_type(self) -> WidgetId { self.cast_type() } @@ -66,14 +64,14 @@ impl W> WidgetLike for WidgetFn { type Widget = W; fn add(self, ui: &mut UIBuilder) -> WidgetId { let w = (self.0)(ui); - ui.add(w).to_id() + ui.add_widget(w).to_id() } } impl WidgetLike for W { type Widget = W; fn add(self, ui: &mut UIBuilder) -> WidgetId { - ui.add(self).to_id() + ui.add_widget(self).to_id() } } @@ -93,15 +91,13 @@ impl WidgetLike for WidgetArr<1, (W,)> { } pub struct WidgetArr { - pub ui: UIBuilder, - pub arr: [WidgetId<()>; LEN], + pub arr: [WidgetId; LEN], _pd: PhantomData, } impl WidgetArr { - pub fn new(ui: UIBuilder, arr: [WidgetId<()>; LEN]) -> Self { + pub fn new(arr: [WidgetId; LEN]) -> Self { Self { - ui, arr, _pd: PhantomData, } @@ -138,12 +134,10 @@ macro_rules! impl_widget_arr { ($n:expr;$($T:tt)*) => { impl<$($T: WidgetLike,)*> WidgetArrLike<$n> for ($($T,)*) { type Ws = ($($T::Widget,)*); - #[allow(unused_variables)] fn ui(self, ui: &mut UIBuilder) -> WidgetArr<$n, ($($T::Widget,)*)> { #[allow(non_snake_case)] let ($($T,)*) = self; WidgetArr::new( - ui.clone(), [$($T.add(ui).cast_type(),)*], ) } diff --git a/src/lib.rs b/src/lib.rs index c19b5bd..89d2b0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ #![feature(const_trait_impl)] #![feature(const_from)] #![feature(trait_alias)] -#![feature(generic_const_exprs)] mod layout; mod render; diff --git a/src/util/id.rs b/src/util/id.rs index ad6fc08..cca6616 100644 --- a/src/util/id.rs +++ b/src/util/id.rs @@ -27,6 +27,7 @@ impl IDTracker { id } + #[allow(dead_code)] pub fn free(&mut self, id: ID) { self.free.push(id); }