strong & weak widgets
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
use std::{hash::Hash, rc::Rc};
|
||||
|
||||
use crate::{
|
||||
Ui, UiModule, WidgetHandle, WidgetView,
|
||||
Ui, UiModule, WidgetView,
|
||||
util::{HashMap, Id},
|
||||
};
|
||||
use std::{hash::Hash, rc::Rc};
|
||||
|
||||
pub trait Event: Sized {
|
||||
type Module<Ctx: 'static>: EventModule<Self, Ctx>;
|
||||
@@ -16,9 +15,8 @@ pub struct EventCtx<'a, Ctx, Data> {
|
||||
pub data: Data,
|
||||
}
|
||||
|
||||
pub type ECtx<'a, Ctx, Data, W> = EventIdCtx<'a, Ctx, Data, W>;
|
||||
pub struct EventIdCtx<'a, Ctx, Data, W> {
|
||||
pub id: &'a WidgetView<W>,
|
||||
pub struct EventIdCtx<'a, Ctx, Data, W: ?Sized> {
|
||||
pub id: WidgetView<W>,
|
||||
pub ui: &'a mut Ui,
|
||||
pub state: &'a mut Ctx,
|
||||
pub data: Data,
|
||||
@@ -27,8 +25,11 @@ pub struct EventIdCtx<'a, Ctx, Data, W> {
|
||||
pub trait EventFn<Ctx, Data>: Fn(EventCtx<Ctx, Data>) + 'static {}
|
||||
impl<F: Fn(EventCtx<Ctx, Data>) + 'static, Ctx, Data> EventFn<Ctx, Data> for F {}
|
||||
|
||||
pub trait WidgetEventFn<Ctx, Data, W>: Fn(EventIdCtx<Ctx, Data, W>) + 'static {}
|
||||
impl<F: Fn(EventIdCtx<Ctx, Data, W>) + 'static, Ctx, Data, W> WidgetEventFn<Ctx, Data, W> for F {}
|
||||
pub trait WidgetEventFn<Ctx, Data, W: ?Sized>: Fn(EventIdCtx<Ctx, Data, W>) + 'static {}
|
||||
impl<F: Fn(EventIdCtx<Ctx, Data, W>) + 'static, Ctx, Data, W: ?Sized> WidgetEventFn<Ctx, Data, W>
|
||||
for F
|
||||
{
|
||||
}
|
||||
|
||||
pub trait DefaultEvent: Hash + Eq + 'static {
|
||||
type Data: Clone = ();
|
||||
@@ -129,7 +130,7 @@ impl Ui {
|
||||
pub fn run_event<E: Event, Ctx: 'static, W>(
|
||||
&mut self,
|
||||
ctx: &mut Ctx,
|
||||
id: &WidgetHandle<W>,
|
||||
id: WidgetView<W>,
|
||||
event: E,
|
||||
data: E::Data,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user