REAL SENSORS
This commit is contained in:
44
src/layout/sense.rs
Normal file
44
src/layout/sense.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user