work
This commit is contained in:
1 parent
a9c76e4326
commit
79813db3ba
35 files changed
+378
-403
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{HasEvents, HasUi, Widget, WidgetRef};
|
||||
use crate::{HasEvents, WeakWidget, Widget};
|
||||
|
||||
pub struct EventCtx<'a, Rsc: HasEvents, Data> {
|
||||
pub state: &'a mut Rsc::State,
|
||||
@@ -6,13 +6,13 @@ pub struct EventCtx<'a, Rsc: HasEvents, Data> {
|
||||
}
|
||||
|
||||
pub struct EventIdCtx<'a, Rsc: HasEvents, Data, W: ?Sized> {
|
||||
pub widget: WidgetRef<W>,
|
||||
pub widget: WeakWidget<W>,
|
||||
pub state: &'a mut Rsc::State,
|
||||
pub data: Data,
|
||||
}
|
||||
|
||||
impl<Rsc: HasEvents + HasUi, Data, W: Widget> EventIdCtx<'_, Rsc, Data, W> {
|
||||
impl<Rsc: HasEvents, Data, W: Widget> EventIdCtx<'_, Rsc, Data, W> {
|
||||
pub fn widget<'a>(&self, rsc: &'a mut Rsc) -> &'a mut W {
|
||||
&mut rsc.ui_mut()[self.widget]
|
||||
&mut rsc.widgets_mut()[self.widget]
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ActiveData, Event, EventCtx, EventFn, EventIdCtx, EventLike, HasEvents, IdLike, LayerId,
|
||||
Widget, WidgetEventFn, WidgetId, WidgetRef,
|
||||
Widget, WidgetEventFn, WidgetId, WeakWidget,
|
||||
util::{HashMap, HashSet, TypeMap},
|
||||
};
|
||||
use std::{any::TypeId, rc::Rc};
|
||||
@@ -26,7 +26,7 @@ impl<Rsc: HasEvents + 'static> EventManager<Rsc> {
|
||||
|
||||
pub fn register<W: Widget + ?Sized, E: EventLike>(
|
||||
&mut self,
|
||||
id: WidgetRef<W>,
|
||||
id: WeakWidget<W>,
|
||||
event: E,
|
||||
f: impl WidgetEventFn<Rsc, <E::Event as Event>::Data, W>,
|
||||
) {
|
||||
@@ -114,7 +114,7 @@ impl<Rsc: HasEvents, E: Event> Default for TypeEventManager<Rsc, E> {
|
||||
impl<Rsc: HasEvents + 'static, E: Event> TypeEventManager<Rsc, E> {
|
||||
fn register<W: Widget + ?Sized>(
|
||||
&mut self,
|
||||
widget: WidgetRef<W>,
|
||||
widget: WeakWidget<W>,
|
||||
event: impl EventLike<Event = E>,
|
||||
f: impl WidgetEventFn<Rsc, E::Data, W>,
|
||||
) {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
use crate::{
|
||||
Event, EventCtx, EventLike, EventManager, HasUi, IdLike, Widget, WidgetEventFn, WidgetRef,
|
||||
Event, EventCtx, EventLike, EventManager, IdLike, UiRsc, Widget, WidgetEventFn, WeakWidget,
|
||||
};
|
||||
|
||||
pub trait HasState: 'static {
|
||||
type State;
|
||||
}
|
||||
|
||||
pub trait HasEvents: Sized + HasUi + HasState {
|
||||
pub trait HasEvents: Sized + UiRsc + HasState {
|
||||
fn events(&self) -> &EventManager<Self>;
|
||||
fn events_mut(&mut self) -> &mut EventManager<Self>;
|
||||
|
||||
fn register_event<W: Widget + ?Sized, E: EventLike>(
|
||||
&mut self,
|
||||
id: WidgetRef<W>,
|
||||
id: WeakWidget<W>,
|
||||
event: E,
|
||||
f: impl WidgetEventFn<Self, <E::Event as Event>::Data, W>,
|
||||
) {
|
||||
|
||||
Reference in new issue
Block a user