better global state structure?
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{marker::Unsize, mem::MaybeUninit, ops::CoerceUnsized, sync::mpsc::Sender};
|
||||
|
||||
use crate::{
|
||||
Widget,
|
||||
HasUi, Widget,
|
||||
util::{RefCounter, SlotId},
|
||||
};
|
||||
|
||||
@@ -143,3 +143,11 @@ impl<W> std::fmt::Debug for WidgetHandle<W> {
|
||||
self.id.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W: Widget + 'a, State: HasUi> FnOnce<(&'a mut State,)> for WidgetRef<W> {
|
||||
type Output = &'a mut W;
|
||||
|
||||
extern "rust-call" fn call_once(self, args: (&'a mut State,)) -> Self::Output {
|
||||
&mut args.0.ui_mut()[self]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub trait WidgetLike<State: 'static + HasUi, Tag>: Sized {
|
||||
}
|
||||
|
||||
fn set_root(self, state: &mut State) {
|
||||
state.ui().root = Some(self.add(state));
|
||||
state.get_mut().root = Some(self.add(state));
|
||||
}
|
||||
|
||||
fn handles(self, state: &mut State) -> WidgetHandles<Self::Widget> {
|
||||
|
||||
@@ -7,15 +7,15 @@ use super::*;
|
||||
pub struct ArrTag;
|
||||
|
||||
pub struct WidgetTag;
|
||||
impl<State: HasUi, W: Widget> WidgetLike<State, WidgetTag> for W {
|
||||
impl<State: HasUi + 'static, W: Widget> WidgetLike<State, WidgetTag> for W {
|
||||
type Widget = W;
|
||||
fn add(self, state: &mut State) -> WidgetHandle<W> {
|
||||
state.ui().add_widget(self)
|
||||
state.get_mut().add_widget(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FnTag;
|
||||
impl<State: HasUi, W: Widget, F: FnOnce(&mut State) -> W> WidgetLike<State, FnTag> for F {
|
||||
impl<State: HasUi + 'static, W: Widget, F: FnOnce(&mut State) -> W> WidgetLike<State, FnTag> for F {
|
||||
type Widget = W;
|
||||
fn add(self, state: &mut State) -> WidgetHandle<W> {
|
||||
self(state).add(state)
|
||||
@@ -23,8 +23,8 @@ impl<State: HasUi, W: Widget, F: FnOnce(&mut State) -> W> WidgetLike<State, FnTa
|
||||
}
|
||||
|
||||
pub struct IdTag;
|
||||
impl<State: HasUi, W: ?Sized + Widget + Unsize<dyn Widget> + 'static> WidgetLike<State, IdTag>
|
||||
for WidgetHandle<W>
|
||||
impl<State: HasUi + 'static, W: ?Sized + Widget + Unsize<dyn Widget> + 'static>
|
||||
WidgetLike<State, IdTag> for WidgetHandle<W>
|
||||
{
|
||||
type Widget = W;
|
||||
fn add(self, _: &mut State) -> WidgetHandle<W> {
|
||||
@@ -34,7 +34,7 @@ impl<State: HasUi, W: ?Sized + Widget + Unsize<dyn Widget> + 'static> WidgetLike
|
||||
|
||||
pub struct IdFnTag;
|
||||
impl<
|
||||
State: HasUi,
|
||||
State: HasUi + 'static,
|
||||
W: ?Sized + Widget + Unsize<dyn Widget> + 'static,
|
||||
F: FnOnce(&mut State) -> WidgetHandle<W>,
|
||||
> WidgetLike<State, IdFnTag> for F
|
||||
|
||||
Reference in New Issue
Block a user