actually sane sensor handling

This commit is contained in:
2025-08-16 00:56:00 -04:00
parent f4aef3a983
commit 11188f2951
9 changed files with 306 additions and 117 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
ActiveSensors, HashMap, Painter, SenseCtx, Sensor, SensorMap, Widget, WidgetId, WidgetLike,
ActiveSensors, HashMap, Painter, SensorMap, Widget, WidgetId, WidgetLike,
primitive::Primitives,
util::{IDTracker, Id},
};
@@ -13,8 +13,8 @@ pub struct Ui<Ctx> {
base: Option<WidgetId>,
widgets: Widgets<Ctx>,
updates: Vec<WidgetId>,
active_sensors: ActiveSensors<Ctx>,
sensor_map: SensorMap<Ctx>,
pub(super) active_sensors: ActiveSensors,
pub(super) sensor_map: SensorMap<Ctx>,
primitives: Primitives,
full_redraw: bool,
}
@@ -85,26 +85,6 @@ impl<Ctx> Ui<Ctx> {
self.primitives = painter.finish();
}
pub fn add_sensor<W>(&mut self, id: &WidgetId<W>, f: Sensor<Ctx>) {
self.sensor_map
.entry(id.id.duplicate())
.or_default()
.push(f);
}
pub fn run_sensors(&mut self, ctx: &mut Ctx)
where
Ctx: SenseCtx + 'static,
{
for sensors in self.active_sensors.clone().iter().rev() {
for sensor in sensors {
if ctx.active(&sensor.trigger) {
(sensor.f.box_clone())(self, ctx);
}
}
}
}
pub fn update(&mut self, ctx: &mut Ctx) -> Option<&Primitives>
where
Ctx: 'static,