remove context generic

This commit is contained in:
iris committed 2025-08-25 18:53:21 -04:00
1 parent d4b1a56467
commit e8b255c8f9
17 files changed
+167 -217

No files matched your search

+16 -23
View File
@@ -30,12 +30,12 @@ pub enum ActivationState {
Off,
}
pub struct Sensor<Ctx> {
pub struct Sensor {
pub sense: Sense,
pub f: Box<dyn SenseFn<Ctx>>,
pub f: Box<dyn SenseFn>,
}
pub type SensorMap<Ctx> = HashMap<Id, SensorGroup<Ctx>>;
pub type SensorMap = HashMap<Id, SensorGroup>;
pub type ActiveSensors = HashMap<Id, SenseShape>;
pub type SenseShape = UiRegion;
#[derive(Clone)]
@@ -43,26 +43,22 @@ pub struct SenseTrigger {
pub shape: SenseShape,
pub sense: Sense,
}
pub struct SensorGroup<Ctx> {
pub struct SensorGroup {
pub hover: ActivationState,
pub cursor: ActivationState,
pub sensors: Vec<Sensor<Ctx>>,
pub sensors: Vec<Sensor>,
}
pub struct SenseCtx<'a, Ctx> {
pub ui: &'a mut Ui<Ctx>,
pub app: &'a mut Ctx,
pub trait SenseFn: FnMut(&mut Ui) + 'static {
fn box_clone(&self) -> Box<dyn SenseFn>;
}
pub trait SenseFn<Ctx>: FnMut(SenseCtx<Ctx>) + 'static {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>>;
}
impl<F: FnMut(SenseCtx<Ctx>) + 'static + Clone, Ctx> SenseFn<Ctx> for F {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>> {
impl<F: FnMut(&mut Ui) + 'static + Clone> SenseFn for F {
fn box_clone(&self) -> Box<dyn SenseFn> {
Box::new(self.clone())
}
}
impl<Ctx> Ui<Ctx> {
pub fn add_sensor<W>(&mut self, id: &WidgetId<W>, f: Sensor<Ctx>) {
impl Ui {
pub fn add_sensor<W>(&mut self, id: &WidgetId<W>, f: Sensor) {
self.sensor_map
.entry(id.id.duplicate())
.or_default()
@@ -70,10 +66,7 @@ impl<Ctx> Ui<Ctx> {
.push(f);
}
pub fn run_sensors(&mut self, ctx: &mut Ctx, cursor: &CursorState, window_size: Vec2)
where
Ctx: 'static,
{
pub fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2) {
let active = std::mem::take(&mut self.active.sensors);
let mut map = std::mem::take(&mut self.sensor_map);
for (id, shape) in active.iter() {
@@ -85,7 +78,7 @@ impl<Ctx> Ui<Ctx> {
for sensor in &mut group.sensors {
if should_run(sensor.sense, group.cursor, group.hover) {
(sensor.f.box_clone())(SenseCtx { ui: self, app: ctx });
(sensor.f.box_clone())(self);
}
}
}
@@ -141,7 +134,7 @@ impl ActivationState {
}
}
impl<Ctx> Default for SensorGroup<Ctx> {
impl Default for SensorGroup {
fn default() -> Self {
Self {
hover: Default::default(),
@@ -150,7 +143,7 @@ impl<Ctx> Default for SensorGroup<Ctx> {
}
}
}
impl<Ctx: 'static> Clone for SensorGroup<Ctx> {
impl Clone for SensorGroup {
fn clone(&self) -> Self {
Self {
hover: self.hover,
@@ -159,7 +152,7 @@ impl<Ctx: 'static> Clone for SensorGroup<Ctx> {
}
}
}
impl<Ctx: 'static> Clone for Sensor<Ctx> {
impl Clone for Sensor {
fn clone(&self) -> Self {
Self {
sense: self.sense,