switch away from handles to refs that must be upgraded once
This commit is contained in:
@@ -16,11 +16,15 @@ impl StateLike<Ui> for Ui {
|
||||
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 add(self, state: &mut impl StateLike<State>) -> WidgetRef<Self::Widget>;
|
||||
|
||||
fn add_strong(self, state: &mut impl StateLike<State>) -> WidgetHandle<Self::Widget> {
|
||||
self.add(state).upgrade(state.as_state().ui_mut())
|
||||
}
|
||||
|
||||
fn with_id<W2>(
|
||||
self,
|
||||
f: impl FnOnce(&mut State, WidgetHandle<Self::Widget>) -> WidgetHandle<W2>,
|
||||
f: impl FnOnce(&mut State, WidgetRef<Self::Widget>) -> WidgetRef<W2>,
|
||||
) -> impl WidgetIdFn<State, W2> {
|
||||
move |state| {
|
||||
let id = self.add(state);
|
||||
@@ -29,15 +33,18 @@ pub trait WidgetLike<State: HasUi + StateLike<State>, Tag>: Sized {
|
||||
}
|
||||
|
||||
fn set_root(self, state: &mut impl StateLike<State>) {
|
||||
state.as_state().get_mut().root = Some(self.add(state));
|
||||
let id = self.add(state);
|
||||
let ui = state.as_state().ui_mut();
|
||||
ui.root = Some(id.upgrade(ui));
|
||||
}
|
||||
|
||||
fn handles(self, state: &mut impl StateLike<State>) -> WidgetHandles<Self::Widget> {
|
||||
self.add(state).handles()
|
||||
self.add(state).upgrade(state.as_state().ui_mut()).handles()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetArrLike<State, const LEN: usize, Tag> {
|
||||
#[track_caller]
|
||||
fn add(self, state: &mut impl StateLike<State>) -> WidgetArr<LEN>;
|
||||
}
|
||||
|
||||
@@ -58,7 +65,7 @@ macro_rules! impl_widget_arr {
|
||||
#[allow(non_snake_case)]
|
||||
let ($($W,)*) = self;
|
||||
WidgetArr::new(
|
||||
[$($W.add(state),)*],
|
||||
[$($W.add(state).upgrade(state.as_state().ui_mut()),)*],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user