remove context generic

This commit is contained in:
2025-08-25 18:53:21 -04:00
parent d4b1a56467
commit e8b255c8f9
17 changed files with 167 additions and 217 deletions

View File

@@ -119,24 +119,24 @@ impl<W> Drop for WidgetId<W> {
pub struct IdTag;
pub struct IdFnTag;
// pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui<Ctx>) -> WidgetId<W>;
// pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui) -> WidgetId<W>;
macro_rules! WidgetIdFnRet {
($W:ty, $Ctx:ty) => {
impl FnOnce(&mut $crate::layout::Ui<$Ctx>) -> $crate::layout::WidgetId<$W>
($W:ty) => {
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W>
};
($W:ty, $Ctx:ty, $($use:tt)*) => {
impl FnOnce(&mut $crate::layout::Ui<$Ctx>) -> $crate::layout::WidgetId<$W> + use<$($use)*>
($W:ty, $($use:tt)*) => {
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W> + use<$($use)*>
};
}
pub(crate) use WidgetIdFnRet;
pub trait Idable<Ctx, Tag> {
type Widget: Widget<Ctx>;
fn set(self, ui: &mut Ui<Ctx>, id: &WidgetId<Self::Widget>);
pub trait Idable<Tag> {
type Widget: Widget;
fn set(self, ui: &mut Ui, id: &WidgetId<Self::Widget>);
fn id<'a>(
self,
id: &WidgetId<Self::Widget>,
) -> WidgetIdFnRet!(Self::Widget, Ctx, 'a, Self, Ctx, Tag)
) -> WidgetIdFnRet!(Self::Widget, 'a, Self, Tag)
where
Self: Sized,
{
@@ -149,7 +149,7 @@ pub trait Idable<Ctx, Tag> {
fn id_static<'a>(
self,
id: StaticWidgetId<Self::Widget>,
) -> WidgetIdFnRet!(Self::Widget, Ctx, 'a, Self, Ctx, Tag)
) -> WidgetIdFnRet!(Self::Widget, 'a, Self, Tag)
where
Self: Sized,
{
@@ -161,33 +161,33 @@ pub trait Idable<Ctx, Tag> {
}
}
impl<W: Widget<Ctx>, 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>, 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)
}
}
@@ -198,9 +198,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)
}
}