tasks initial impl (still working on task_on trait method)
This commit is contained in:
61
src/event.rs
61
src/event.rs
@@ -1,17 +1,20 @@
|
||||
use crate::prelude::*;
|
||||
use iris_core::*;
|
||||
use iris_macro::*;
|
||||
|
||||
use crate::default::{TaskCtx, Tasks};
|
||||
|
||||
pub mod eventable {
|
||||
use super::*;
|
||||
widget_trait! {
|
||||
pub trait Eventable<Rsc: HasEvents + 'static>;
|
||||
pub trait Eventable<Rsc: HasEvents>;
|
||||
fn on<E: EventLike>(
|
||||
self,
|
||||
event: E,
|
||||
f: impl for<'a> WidgetEventFn<Rsc, <E::Event as Event>::Data<'a>, WL::Widget>,
|
||||
) -> impl WidgetIdFn<Rsc, WL::Widget> {
|
||||
move |state| {
|
||||
let id = self.add(state);
|
||||
state.register_event(id, event.into_event(), move |ctx, rsc| {
|
||||
move |rsc| {
|
||||
let id = self.add(rsc);
|
||||
rsc.register_event(id, event.into_event(), move |ctx, rsc| {
|
||||
f(&mut EventIdCtx {
|
||||
widget: id,
|
||||
state: ctx.state,
|
||||
@@ -22,4 +25,52 @@ pub mod eventable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// widget_trait! {
|
||||
// pub trait TaskEventable<Rsc: HasEvents + HasTasks>;
|
||||
// fn task_on<E: EventLike>(
|
||||
// self,
|
||||
// event: E,
|
||||
// f: impl for<'a> AsyncWidgetEventFn<Rsc, <E::Event as Event>::Data<'a>, WL::Widget>,
|
||||
// ) -> impl WidgetIdFn<Rsc, WL::Widget> {
|
||||
// move |rsc| {
|
||||
// let id = self.add(rsc);
|
||||
// rsc.register_event(id, event.into_event(), move |ctx, rsc| {
|
||||
// rsc.tasks_mut().spawn(async move |task| {
|
||||
// f(&mut AsyncEventIdCtx {
|
||||
// widget: id,
|
||||
// state: ctx.state,
|
||||
// data: ctx.data,
|
||||
// task,
|
||||
// }, rsc).await;
|
||||
// });
|
||||
// });
|
||||
// id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
pub trait HasTasks: Sized + HasState + HasEvents {
|
||||
fn tasks_mut(&mut self) -> &mut Tasks<Self>;
|
||||
}
|
||||
|
||||
pub trait AsyncWidgetEventFn<Rsc: HasEvents, Data, W: ?Sized>:
|
||||
AsyncFn(&mut AsyncEventIdCtx<Rsc, Data, W>, &mut Rsc) + 'static
|
||||
{
|
||||
}
|
||||
impl<
|
||||
Rsc: HasEvents,
|
||||
F: AsyncFn(&mut AsyncEventIdCtx<Rsc, Data, W>, &mut Rsc) + 'static,
|
||||
Data,
|
||||
W: ?Sized,
|
||||
> AsyncWidgetEventFn<Rsc, Data, W> for F
|
||||
{
|
||||
}
|
||||
|
||||
pub struct AsyncEventIdCtx<'a, Rsc: HasEvents, Data, W: ?Sized> {
|
||||
pub widget: WidgetRef<W>,
|
||||
pub state: &'a mut Rsc::State,
|
||||
pub data: &'a mut Data,
|
||||
pub task: &'a mut TaskCtx<Rsc>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user