IDC FINALLY OH MY GOD (I think like ctx + resize propagation + some other stuff)

This commit is contained in:
2025-09-11 00:59:26 -04:00
parent 709a2d0e17
commit 242c3b992e
15 changed files with 476 additions and 281 deletions

View File

@@ -1,25 +1,26 @@
use crate::prelude::*;
pub trait Sensable<W, Tag> {
fn on(self, sense: Senses, f: impl SenseFn) -> impl WidgetIdFn<W>;
pub trait Sensable<W, Ctx, Tag> {
fn on(self, sense: Senses, f: impl SenseFn<Ctx>) -> impl WidgetIdFn<W, Ctx>;
fn id_on(
self,
senses: Senses,
f: impl FnMut(&WidgetId<W>, &mut Ui, SenseCtx) + 'static,
) -> impl WidgetIdFn<W>
f: impl FnMut(&WidgetId<W>, &mut Ctx, SenseCtx) + 'static,
) -> impl WidgetIdFn<W, Ctx>
where
W: Widget;
fn edit_on(
self,
senses: Senses,
f: impl FnMut(&mut W, SenseCtx) + 'static,
) -> impl WidgetIdFn<W>
) -> impl WidgetIdFn<W, Ctx>
where
W: Widget;
W: Widget,
Ctx: UiCtx;
}
impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
fn on(self, senses: Senses, f: impl SenseFn) -> impl WidgetIdFn<W::Widget> {
impl<W: WidgetLike<Ctx, Tag>, Ctx, Tag> Sensable<W::Widget, Ctx, Tag> for W {
fn on(self, senses: Senses, f: impl SenseFn<Ctx>) -> impl WidgetIdFn<W::Widget, Ctx> {
move |ui| {
let id = self.add(ui);
ui.add_sensor(
@@ -35,24 +36,25 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
fn id_on(
self,
senses: Senses,
mut f: impl FnMut(&WidgetId<W::Widget>, &mut Ui, SenseCtx) + 'static,
) -> impl WidgetIdFn<W::Widget>
mut f: impl FnMut(&WidgetId<W::Widget>, &mut Ctx, SenseCtx) + 'static,
) -> impl WidgetIdFn<W::Widget, Ctx>
where
W::Widget: Widget,
{
self.with_id(move |ui, id| {
let id2 = id.clone();
ui.add(id.on(senses, move |ui, pos| f(&id2, ui, pos)))
id.on(senses, move |ctx, pos| f(&id2, ctx, pos)).add(ui)
})
}
fn edit_on(
self,
senses: Senses,
mut f: impl FnMut(&mut W::Widget, SenseCtx) + 'static,
) -> impl WidgetIdFn<W::Widget>
) -> impl WidgetIdFn<W::Widget, Ctx>
where
W::Widget: Widget,
Ctx: UiCtx,
{
self.id_on(senses, move |id, ui, pos| f(&mut ui[id], pos))
self.id_on(senses, move |id, ctx, pos| f(&mut ctx.ui()[id], pos))
}
}