TAG TECHNOLOGY

This commit is contained in:
2025-08-14 12:21:26 -04:00
parent 4d68fa476d
commit e41970287d
19 changed files with 267 additions and 165 deletions

35
src/core/sense.rs Normal file
View File

@@ -0,0 +1,35 @@
use std::marker::PhantomData;
use crate::{Painter, Widget, WidgetFn, WidgetId, WidgetLike};
pub struct Sensor<F: SenseFn<Ctx>, Ctx> {
inner: WidgetId,
f: F,
_pd: PhantomData<Ctx>,
}
impl<F: SenseFn<Ctx>, Ctx: 'static> Widget<Ctx> for Sensor<F, Ctx> {
fn draw(&self, painter: &mut Painter<Ctx>) {
(self.f)(painter.ctx_mut());
painter.draw(&self.inner);
}
}
pub trait SenseFn<Ctx> = Fn(&mut Ctx) + 'static;
pub trait Sensable<Ctx: 'static, Tag> {
fn sense<F: SenseFn<Ctx>>(self, f: F) -> impl WidgetFn<Sensor<F, Ctx>, Ctx>;
}
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> Sensable<Ctx, Tag> for W {
fn sense<F: SenseFn<Ctx>>(self, f: F) -> impl WidgetFn<Sensor<F, Ctx>, Ctx> {
|ui| {
let inner = self.add(ui).erase_type();
Sensor {
inner,
f,
_pd: PhantomData,
}
}
}
}