FINALLY transition events to global; slow text sending bug tho

This commit is contained in:
2025-12-11 01:21:36 -05:00
parent 2537284372
commit baaeb6b027
21 changed files with 650 additions and 557 deletions

View File

@@ -6,14 +6,14 @@ pub mod eventable {
widget_trait! {
pub trait Eventable;
fn on<E: Event, Ctx: 'static>(
fn on<E: EventAlias, Ctx: 'static>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
f: impl for<'a> EventIdFn<Ctx, <E::Event as Event>::Data<'a>, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
move |ui| {
let id = self.add(ui);
ui.register_widget_event(id.weak(), event, f);
Events::<E::Event, Ctx>::register(id.weak(), event.into_event(), f);
id
}
}
@@ -26,53 +26,37 @@ macro_rules! event_ctx {
($ty: ty) => {
mod local_event_trait {
use super::*;
use std::marker::Sized;
#[allow(unused_imports)]
use $crate::prelude::*;
#[allow(unused)]
pub trait EventableCtx<W: ?Sized, Tag, Ctx: 'static> {
fn on<E: Event>(
widget_trait! {
#[allow(unused)]
pub trait EventableCtx;
fn on<E: EventAlias>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, W>,
) -> impl WidgetIdFn<W> + EventableCtx<W, IdFnTag, Ctx>;
}
impl<WL: WidgetLike<Tag>, Tag> EventableCtx<WL::Widget, Tag, $ty> for WL {
fn on<E: Event>(
self,
event: E,
f: impl WidgetEventFn<$ty, E::Data, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> + EventableCtx<WL::Widget, IdFnTag, $ty> {
f: impl for<'a> EventIdFn<$ty, <E::Event as Event>::Data<'a>, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
eventable::Eventable::on(self, event, f)
}
}
use std::marker::Sized;
#[allow(unused)]
pub trait EventableCtxUi<W: ?Sized, Tag, Ctx: 'static>
where
WidgetRef<W>: EventableCtx<W, Tag, Ctx>,
{
fn on<E: Event>(
&mut self,
widget: WidgetRef<W>,
pub trait EventableCtxRef<W: Widget + ?Sized> {
fn on<E: EventAlias>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, W>,
f: impl for<'a> EventIdFn<$ty, <E::Event as Event>::Data<'a>, W>,
);
}
impl<W: ?Sized + 'static, Tag> EventableCtxUi<W, Tag, $ty> for Ui
where
WidgetRef<W>: EventableCtx<W, Tag, $ty>,
{
fn on<E: Event>(
&mut self,
widget: WidgetRef<W>,
impl<W: Widget + ?Sized> EventableCtxRef<W> for WidgetRef<W> {
fn on<E: EventAlias>(
self,
event: E,
f: impl WidgetEventFn<$ty, E::Data, W>,
f: impl for<'a> EventIdFn<$ty, <E::Event as Event>::Data<'a>, W>,
) {
self.register_widget_event(widget, event, f);
Events::<E::Event, $ty>::register(self, event.into_event(), f);
}
}
}