remove context from ui (again) and create weird trait for it

This commit is contained in:
2025-09-24 17:41:25 -04:00
parent 26c248dcba
commit 719bee4b31
12 changed files with 107 additions and 92 deletions

View File

@@ -131,14 +131,14 @@ impl<W> Drop for WidgetId<W> {
pub struct IdTag;
pub struct IdFnTag;
pub trait WidgetIdFn<W, Ctx>: FnOnce(&mut Ui<Ctx>) -> WidgetId<W> {}
impl<W, F: FnOnce(&mut Ui<Ctx>) -> WidgetId<W>, Ctx> WidgetIdFn<W, Ctx> for F {}
pub trait WidgetIdFn<W>: FnOnce(&mut Ui) -> WidgetId<W> {}
impl<W, F: FnOnce(&mut Ui) -> WidgetId<W>> WidgetIdFn<W> for F {}
/// TODO: does this ever make sense to use? it allows for invalid ids
pub trait Idable<Ctx, Tag> {
pub trait Idable<Tag> {
type Widget: Widget;
fn set(self, ui: &mut Ui<Ctx>, id: &WidgetId<Self::Widget>);
fn id(self, id: &WidgetId<Self::Widget>) -> impl WidgetIdFn<Self::Widget, Ctx>
fn set(self, ui: &mut Ui, id: &WidgetId<Self::Widget>);
fn id(self, id: &WidgetId<Self::Widget>) -> impl WidgetIdFn<Self::Widget>
where
Self: Sized,
{
@@ -148,7 +148,7 @@ pub trait Idable<Ctx, Tag> {
id
}
}
fn id_static(self, id: StaticWidgetId<Self::Widget>) -> impl WidgetIdFn<Self::Widget, Ctx>
fn id_static(self, id: StaticWidgetId<Self::Widget>) -> impl WidgetIdFn<Self::Widget>
where
Self: Sized,
{
@@ -160,33 +160,33 @@ pub trait Idable<Ctx, Tag> {
}
}
impl<W: Widget, Ctx> Idable<Ctx, WidgetTag> for W {
impl<W: Widget> Idable<WidgetTag> for W {
type Widget = W;
fn set(self, ui: &mut Ui<Ctx>, id: &WidgetId<Self::Widget>) {
fn set(self, ui: &mut Ui, id: &WidgetId<Self::Widget>) {
ui.set(id, self);
}
}
impl<F: FnOnce(&mut Ui<Ctx>) -> W, W: Widget, Ctx> Idable<Ctx, FnTag> for F {
impl<F: FnOnce(&mut Ui) -> W, W: Widget> Idable<FnTag> for F {
type Widget = W;
fn set(self, ui: &mut Ui<Ctx>, id: &WidgetId<Self::Widget>) {
fn set(self, ui: &mut Ui, id: &WidgetId<Self::Widget>) {
let w = self(ui);
ui.set(id, w);
}
}
impl<W: 'static, Ctx> WidgetLike<Ctx, IdTag> for WidgetId<W> {
impl<W: 'static> WidgetLike<IdTag> for WidgetId<W> {
type Widget = W;
fn add(self, _: &mut Ui<Ctx>) -> WidgetId<W> {
fn add(self, _: &mut Ui) -> WidgetId<W> {
self
}
}
impl<W: 'static, F: FnOnce(&mut Ui<Ctx>) -> WidgetId<W>, Ctx> WidgetLike<Ctx, IdFnTag> for F {
impl<W: 'static, F: FnOnce(&mut Ui) -> WidgetId<W>> WidgetLike<IdFnTag> for F {
type Widget = W;
fn add(self, ui: &mut Ui<Ctx>) -> WidgetId<W> {
fn add(self, ui: &mut Ui) -> WidgetId<W> {
self(ui)
}
}
@@ -200,9 +200,9 @@ impl<W> StaticWidgetId<W> {
}
}
impl<W: 'static, Ctx> WidgetLike<Ctx, IdTag> for StaticWidgetId<W> {
impl<W: 'static> WidgetLike<IdTag> for StaticWidgetId<W> {
type Widget = W;
fn add(self, ui: &mut Ui<Ctx>) -> WidgetId<W> {
fn add(self, ui: &mut Ui) -> WidgetId<W> {
self.id(&ui.send)
}
}