sensor ctx
This commit is contained in:
@@ -44,10 +44,14 @@ pub struct SensorGroup<Ctx> {
|
||||
pub cursor: ActivationState,
|
||||
pub sensors: Vec<Sensor<Ctx>>,
|
||||
}
|
||||
pub trait SenseFn<Ctx>: FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static {
|
||||
pub struct SenseCtx<'a, Ctx> {
|
||||
pub ui: &'a mut Ui<Ctx>,
|
||||
pub app: &'a mut Ctx,
|
||||
}
|
||||
pub trait SenseFn<Ctx>: FnMut(SenseCtx<Ctx>) + 'static {
|
||||
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>>;
|
||||
}
|
||||
impl<F: FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static + Clone, Ctx> SenseFn<Ctx> for F {
|
||||
impl<F: FnMut(SenseCtx<Ctx>) + 'static + Clone, Ctx> SenseFn<Ctx> for F {
|
||||
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
@@ -77,7 +81,10 @@ impl<Ctx> Ui<Ctx> {
|
||||
|
||||
for sensor in &mut group.sensors {
|
||||
if should_run(sensor.sense, group.cursor, group.hover) {
|
||||
(sensor.f.box_clone())(self, ctx);
|
||||
(sensor.f.box_clone())(SenseCtx {
|
||||
ui: self,
|
||||
app: ctx,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user