REAL SENSORS
This commit is contained in:
@@ -1,22 +1,29 @@
|
||||
use crate::{
|
||||
SenseFn, SenseTrigger, Sensors, UiRegion, WidgetId, Widgets,
|
||||
ActiveSensor, ActiveSensors, SenseTrigger, SensorMap, UiRegion, WidgetId, Widgets,
|
||||
primitive::{PrimitiveData, PrimitiveInstance, Primitives},
|
||||
};
|
||||
|
||||
pub struct Painter<'a, Ctx> {
|
||||
pub struct Painter<'a, Ctx: 'static> {
|
||||
nodes: &'a Widgets<Ctx>,
|
||||
ctx: &'a mut Ctx,
|
||||
sensors: &'a mut Sensors<Ctx>,
|
||||
sensors_map: &'a mut SensorMap<Ctx>,
|
||||
active_sensors: &'a mut ActiveSensors<Ctx>,
|
||||
primitives: Primitives,
|
||||
pub region: UiRegion,
|
||||
}
|
||||
|
||||
impl<'a, Ctx> Painter<'a, Ctx> {
|
||||
pub fn new(nodes: &'a Widgets<Ctx>, ctx: &'a mut Ctx, sensors: &'a mut Sensors<Ctx>) -> Self {
|
||||
pub fn new(
|
||||
nodes: &'a Widgets<Ctx>,
|
||||
ctx: &'a mut Ctx,
|
||||
sensors_map: &'a mut SensorMap<Ctx>,
|
||||
active_sensors: &'a mut ActiveSensors<Ctx>,
|
||||
) -> Self {
|
||||
Self {
|
||||
nodes,
|
||||
ctx,
|
||||
sensors,
|
||||
active_sensors,
|
||||
sensors_map,
|
||||
primitives: Primitives::default(),
|
||||
region: UiRegion::full(),
|
||||
}
|
||||
@@ -37,6 +44,20 @@ impl<'a, Ctx> Painter<'a, Ctx> {
|
||||
where
|
||||
Ctx: 'static,
|
||||
{
|
||||
if let Some(sensors) = self.sensors_map.get(&id.id) {
|
||||
self.active_sensors.push(
|
||||
sensors
|
||||
.iter()
|
||||
.map(|sensor| ActiveSensor {
|
||||
trigger: SenseTrigger {
|
||||
shape: self.region,
|
||||
sense: sensor.sense,
|
||||
},
|
||||
f: sensor.f.box_clone(),
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
self.nodes.get_dyn(id).draw(self);
|
||||
}
|
||||
|
||||
@@ -50,10 +71,6 @@ impl<'a, Ctx> Painter<'a, Ctx> {
|
||||
self.region = old;
|
||||
}
|
||||
|
||||
pub fn sense(&mut self, trigger: SenseTrigger, f: Box<dyn SenseFn<Ctx>>) {
|
||||
self.sensors.push((trigger, f));
|
||||
}
|
||||
|
||||
pub fn finish(self) -> Primitives {
|
||||
self.primitives
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user