REACTIVITY

This commit is contained in:
2025-08-24 20:34:19 -04:00
parent 50ccf7393d
commit 6bb6db32a6
7 changed files with 305 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
HashMap,
layout::{Ui, UiRegion, Vec2, WidgetId},
util::HashMap,
util::Id,
};
@@ -36,7 +36,7 @@ pub struct Sensor<Ctx> {
}
pub type SensorMap<Ctx> = HashMap<Id, SensorGroup<Ctx>>;
pub type ActiveSensors = Vec<(SenseShape, Id)>;
pub type ActiveSensors = HashMap<Id, SenseShape>;
pub type SenseShape = UiRegion;
#[derive(Clone)]
pub struct SenseTrigger {
@@ -74,9 +74,9 @@ impl<Ctx> Ui<Ctx> {
where
Ctx: 'static,
{
let mut active = std::mem::take(&mut self.active_sensors);
let active = std::mem::take(&mut self.active.sensors);
let mut map = std::mem::take(&mut self.sensor_map);
for (shape, id) in active.iter_mut().rev() {
for (id, shape) in active.iter() {
let group = &mut map.get_mut(id).unwrap();
let region = shape.to_screen(window_size);
let in_shape = cursor.exists && region.contains(cursor.pos);
@@ -90,7 +90,7 @@ impl<Ctx> Ui<Ctx> {
}
}
self.sensor_map = map;
self.active_sensors = active;
self.active.sensors = active;
}
}