remove state generic from a lot of things
This commit is contained in:
@@ -1,36 +1,38 @@
|
||||
use crate::HasUi;
|
||||
|
||||
use super::*;
|
||||
use std::marker::Unsize;
|
||||
|
||||
pub trait WidgetLike<State: 'static, Tag>: Sized {
|
||||
type Widget: Widget<State> + ?Sized + Unsize<dyn Widget<State>> + 'static;
|
||||
pub trait WidgetLike<State: 'static + HasUi, Tag>: Sized {
|
||||
type Widget: Widget + ?Sized + Unsize<dyn Widget> + 'static;
|
||||
|
||||
fn add(self, ui: &mut Ui<State>) -> WidgetHandle<State, Self::Widget>;
|
||||
fn add(self, state: &mut State) -> WidgetHandle<Self::Widget>;
|
||||
|
||||
fn with_id<W2>(
|
||||
self,
|
||||
f: impl FnOnce(&mut Ui<State>, WidgetHandle<State, Self::Widget>) -> WidgetHandle<State, W2>,
|
||||
f: impl FnOnce(&mut State, WidgetHandle<Self::Widget>) -> WidgetHandle<W2>,
|
||||
) -> impl WidgetIdFn<State, W2> {
|
||||
move |ui| {
|
||||
let id = self.add(ui);
|
||||
f(ui, id)
|
||||
move |state| {
|
||||
let id = self.add(state);
|
||||
f(state, id)
|
||||
}
|
||||
}
|
||||
|
||||
fn set_root(self, ui: &mut Ui<State>) {
|
||||
ui.set_root(self);
|
||||
fn set_root(self, state: &mut State) {
|
||||
state.ui().root = Some(self.add(state));
|
||||
}
|
||||
|
||||
fn handles(self, ui: &mut Ui<State>) -> WidgetHandles<State, Self::Widget> {
|
||||
self.add(ui).handles()
|
||||
fn handles(self, state: &mut State) -> WidgetHandles<Self::Widget> {
|
||||
self.add(state).handles()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetArrLike<State, const LEN: usize, Tag> {
|
||||
fn ui(self, ui: &mut Ui<State>) -> WidgetArr<State, LEN>;
|
||||
fn add(self, state: &mut State) -> WidgetArr<LEN>;
|
||||
}
|
||||
|
||||
impl<State, const LEN: usize> WidgetArrLike<State, LEN, ArrTag> for WidgetArr<State, LEN> {
|
||||
fn ui(self, _: &mut Ui<State>) -> WidgetArr<State, LEN> {
|
||||
impl<State, const LEN: usize> WidgetArrLike<State, LEN, ArrTag> for WidgetArr<LEN> {
|
||||
fn add(self, _: &mut State) -> WidgetArr<LEN> {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -41,12 +43,12 @@ macro_rules! impl_widget_arr {
|
||||
impl_widget_arr!($n;$($W)*;$(${concat($W,Tag)})*);
|
||||
};
|
||||
($n:expr;$($W:ident)*;$($Tag:ident)*) => {
|
||||
impl<State: 'static, $($W: WidgetLike<State, $Tag>,$Tag,)*> WidgetArrLike<State, $n, ($($Tag,)*)> for ($($W,)*) {
|
||||
fn ui(self, ui: &mut Ui<State>) -> WidgetArr<State, $n> {
|
||||
impl<State: 'static + HasUi, $($W: WidgetLike<State, $Tag>,$Tag,)*> WidgetArrLike<State, $n, ($($Tag,)*)> for ($($W,)*) {
|
||||
fn add(self, state: &mut State) -> WidgetArr<$n> {
|
||||
#[allow(non_snake_case)]
|
||||
let ($($W,)*) = self;
|
||||
WidgetArr::new(
|
||||
[$($W.add(ui),)*],
|
||||
[$($W.add(state),)*],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user