sensor ctx
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::{Sense, SenseFn, Sensor, Ui, Widget, WidgetId, WidgetIdFnRet, WidgetLike};
|
||||
use crate::{Sense, SenseCtx, SenseFn, Sensor, Widget, WidgetId, WidgetIdFnRet, WidgetLike};
|
||||
|
||||
pub trait Sensable<W, Ctx, Tag> {
|
||||
fn on(self, sense: Sense, f: impl SenseFn<Ctx>) -> WidgetIdFnRet!(W, Ctx);
|
||||
fn id_on(
|
||||
self,
|
||||
sense: Sense,
|
||||
f: impl FnMut(&WidgetId<W>, &mut Ui<Ctx>, &mut Ctx) + 'static + Clone,
|
||||
f: impl FnMut(&WidgetId<W>, SenseCtx<Ctx>) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W, Ctx)
|
||||
where
|
||||
W: Widget<Ctx>;
|
||||
@@ -35,26 +35,24 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> Sensable<W::Widget, Ctx, Tag> for W {
|
||||
fn id_on(
|
||||
self,
|
||||
sense: Sense,
|
||||
// trait copied here bc rust analyzer skill issue
|
||||
mut f: impl FnMut(&WidgetId<W::Widget>, &mut Ui<Ctx>, &mut Ctx) + 'static + Clone,
|
||||
mut f: impl FnMut(&WidgetId<W::Widget>, SenseCtx<Ctx>) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget, Ctx)
|
||||
where
|
||||
W::Widget: Widget<Ctx>,
|
||||
{
|
||||
self.with_id(move |ui, id| {
|
||||
let id2 = id.clone();
|
||||
ui.add(id.on(sense, move |ui, ctx| f(&id2, ui, ctx)))
|
||||
ui.add(id.on(sense, move |ctx| f(&id2, ctx)))
|
||||
})
|
||||
}
|
||||
fn edit_on(
|
||||
self,
|
||||
sense: Sense,
|
||||
// trait copied here bc rust analyzer skill issue
|
||||
mut f: impl FnMut(&mut W::Widget, &mut Ctx) + 'static + Clone,
|
||||
) -> WidgetIdFnRet!(W::Widget, Ctx)
|
||||
where
|
||||
W::Widget: Widget<Ctx>,
|
||||
{
|
||||
self.id_on(sense, move |id, ui, ctx| f(&mut ui[id], ctx))
|
||||
self.id_on(sense, move |id, ctx| f(&mut ctx.ui[id], ctx.app))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user