sensor ctx

This commit is contained in:
2025-08-20 13:09:03 -04:00
parent 1482e5d67c
commit b7f83b58a9
4 changed files with 22 additions and 19 deletions

View File

@@ -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,
});
}
}
}