REAL SENSORS

This commit is contained in:
2025-08-15 21:42:35 -04:00
parent 9f1802f497
commit a7dfacb83e
10 changed files with 257 additions and 123 deletions

44
src/layout/sense.rs Normal file
View File

@@ -0,0 +1,44 @@
use crate::{HashMap, Ui, UiRegion, util::Id};
#[derive(Clone, Copy, PartialEq)]
pub enum Sense {
Press,
Held,
Hover,
NoHover,
}
pub struct Sensor<Ctx> {
pub sense: Sense,
pub f: Box<dyn SenseFn<Ctx>>,
}
pub struct ActiveSensor<Ctx> {
pub trigger: SenseTrigger,
pub f: Box<dyn SenseFn<Ctx>>,
}
impl<Ctx: 'static> Clone for ActiveSensor<Ctx> {
fn clone(&self) -> Self {
Self {
trigger: self.trigger.clone(),
f: self.f.box_clone(),
}
}
}
pub type SensorMap<Ctx> = HashMap<Id, Vec<Sensor<Ctx>>>;
pub type ActiveSensors<Ctx> = Vec<Vec<ActiveSensor<Ctx>>>;
pub trait SenseFn_<Ctx> = FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static;
pub type SenseShape = UiRegion;
#[derive(Clone)]
pub struct SenseTrigger {
pub shape: SenseShape,
pub sense: Sense,
}
pub trait SenseFn<Ctx>: SenseFn_<Ctx> {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>>;
}
impl<F: SenseFn_<Ctx> + Clone, Ctx> SenseFn<Ctx> for F {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>> {
Box::new(self.clone())
}
}