abuse macros..
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
use crate::HasUi;
|
||||
use crate::{HasUi, Ui};
|
||||
|
||||
use super::*;
|
||||
use std::marker::Unsize;
|
||||
|
||||
pub trait WidgetLike<State: 'static + HasUi, Tag>: Sized {
|
||||
type Widget: Widget + ?Sized + Unsize<dyn Widget> + 'static;
|
||||
pub trait StateLike<State> {
|
||||
fn as_state(&mut self) -> &mut State;
|
||||
}
|
||||
|
||||
fn add(self, state: &mut State) -> WidgetHandle<Self::Widget>;
|
||||
impl StateLike<Ui> for Ui {
|
||||
fn as_state(&mut self) -> &mut Ui {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetLike<State: HasUi + StateLike<State>, Tag>: Sized {
|
||||
type Widget: Widget + ?Sized + Unsize<dyn Widget>;
|
||||
|
||||
fn add(self, state: &mut impl StateLike<State>) -> WidgetHandle<Self::Widget>;
|
||||
|
||||
fn with_id<W2>(
|
||||
self,
|
||||
@@ -18,21 +28,21 @@ pub trait WidgetLike<State: 'static + HasUi, Tag>: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_root(self, state: &mut State) {
|
||||
state.get_mut().root = Some(self.add(state));
|
||||
fn set_root(self, state: &mut impl StateLike<State>) {
|
||||
state.as_state().get_mut().root = Some(self.add(state));
|
||||
}
|
||||
|
||||
fn handles(self, state: &mut State) -> WidgetHandles<Self::Widget> {
|
||||
fn handles(self, state: &mut impl StateLike<State>) -> WidgetHandles<Self::Widget> {
|
||||
self.add(state).handles()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetArrLike<State, const LEN: usize, Tag> {
|
||||
fn add(self, state: &mut State) -> WidgetArr<LEN>;
|
||||
fn add(self, state: &mut impl StateLike<State>) -> WidgetArr<LEN>;
|
||||
}
|
||||
|
||||
impl<State, const LEN: usize> WidgetArrLike<State, LEN, ArrTag> for WidgetArr<LEN> {
|
||||
fn add(self, _: &mut State) -> WidgetArr<LEN> {
|
||||
fn add(self, _: &mut impl StateLike<State>) -> WidgetArr<LEN> {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -43,8 +53,8 @@ macro_rules! impl_widget_arr {
|
||||
impl_widget_arr!($n;$($W)*;$(${concat($W,Tag)})*);
|
||||
};
|
||||
($n:expr;$($W:ident)*;$($Tag:ident)*) => {
|
||||
impl<State: 'static + HasUi, $($W: WidgetLike<State, $Tag>,$Tag,)*> WidgetArrLike<State, $n, ($($Tag,)*)> for ($($W,)*) {
|
||||
fn add(self, state: &mut State) -> WidgetArr<$n> {
|
||||
impl<State: HasUi + StateLike<State>, $($W: WidgetLike<State, $Tag>,$Tag,)*> WidgetArrLike<State, $n, ($($Tag,)*)> for ($($W,)*) {
|
||||
fn add(self, state: &mut impl StateLike<State>) -> WidgetArr<$n> {
|
||||
#[allow(non_snake_case)]
|
||||
let ($($W,)*) = self;
|
||||
WidgetArr::new(
|
||||
|
||||
Reference in New Issue
Block a user