From b2acbcc189477d7f9fc32dcc62bcf757f594e892 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Sat, 16 Aug 2025 14:43:36 -0400 Subject: [PATCH] oops --- :w | 107 ------------------------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 :w diff --git a/:w b/:w deleted file mode 100644 index 50d518c..0000000 --- a/:w +++ /dev/null @@ -1,107 +0,0 @@ -use crate::{HashMap, Ui, UiRegion, Vec2, WidgetId, util::Id}; - -pub trait SenseCtx: 'static { - fn cursor_state(&self) -> CursorState; - fn window_size(&self) -> Vec2; - fn active(&mut self, trigger: &SenseTrigger) -> bool; -} - -#[derive(Clone, Copy, PartialEq)] -pub enum Sense { - PressStart, - Pressing, - PressEnd, - HoverStart, - Hovering, - HoverEnd, - NotHovering, -} - -pub struct CursorState { - pos: Vec2, - exists: bool, - primary: ActivationState, -} - -#[derive(Debug, Clone, Copy, Default)] -pub enum ActivationState { - Start, - On, - End, - #[default] - Off, -} - -pub struct Sensor { - pub sense: Sense, - pub f: Box>, -} - -impl Clone for SensorGroup { - fn clone(&self) -> Self { - Self { - shape: self.shape.clone(), - hover: self.hover.clone(), - f: self.f.box_clone(), - } - } -} -pub type SensorMap = HashMap>>; -pub type ActiveSensors = Vec>; -pub trait SenseFn_ = FnMut(&mut Ui, &mut Ctx) + 'static; -pub type SenseShape = UiRegion; -#[derive(Clone)] -pub struct SenseTrigger { - pub shape: SenseShape, - pub sense: Sense, -} -pub struct SensorGroup { - pub shape: SenseShape, - pub hover: ActivationState, - pub sensors: Vec>, -} -pub trait SenseFn: SenseFn_ { - fn box_clone(&self) -> Box>; -} -impl + Clone, Ctx> SenseFn for F { - fn box_clone(&self) -> Box> { - Box::new(self.clone()) - } -} - -impl Ui { - pub fn add_sensor(&mut self, id: &WidgetId, f: Sensor) { - self.sensor_map - .entry(id.id.duplicate()) - .or_default() - .push(f); - } - - pub fn run_sensors(&mut self, ctx: &mut Ctx, cursor: &CursorState, window_size: Vec2) - where - Ctx: SenseCtx + 'static, - { - let mut groups = std::mem::take(&mut self.active_sensors_swap); - groups.clone_from(&self.active_sensors); - for (hover, sensors) in groups.drain(..).rev() { - for mut sensor in sensors { - if should_run(sensor.trigger, cursor, hover, window_size) { - (sensor.f)(self, ctx); - } - } - } - self.active_sensors_swap = groups; - } -} - -pub fn should_run( - trigger: SenseTrigger, - cursor: &CursorState, - hover: ActivationState, - window_size: Vec2, -) -> bool { - let region = trigger.shape.to_screen(window_size); - if !cursor.exists || !region.contains(cursor.pos) { - return trigger.sense == Sense::NotHovering; - } -}