please rust analyzer with macros

This commit is contained in:
2025-08-16 02:34:44 -04:00
parent 166394d8d9
commit b0fe7310eb
5 changed files with 45 additions and 32 deletions

View File

@@ -74,7 +74,7 @@ pub trait WidgetLike<Ctx, Tag> {
fn with_id<W2>(
self,
f: impl FnOnce(&mut Ui<Ctx>, WidgetId<Self::Widget>) -> WidgetId<W2>,
) -> impl WidgetIdFn<W2, Ctx>
) -> WidgetIdFnRet!(W2, Ctx)
where
Self: Sized,
{
@@ -85,11 +85,28 @@ pub trait WidgetLike<Ctx, Tag> {
}
}
/// A function that returns a widget given a UI.
/// Useful for defining trait functions on widgets that create a parent widget so that the children
/// don't need to be IDs yet
pub trait WidgetFn<W: Widget<Ctx>, Ctx> = FnOnce(&mut Ui<Ctx>) -> W;
pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui<Ctx>) -> WidgetId<W>;
// A function that returns a widget given a UI.
// Useful for defining trait functions on widgets that create a parent widget so that the children
// don't need to be IDs yet
// pub trait WidgetFn<W: Widget<Ctx>, Ctx> = FnOnce(&mut Ui<Ctx>) -> W;
// pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui<Ctx>) -> WidgetId<W>;
// copium for rust analyzer
macro_rules! WidgetFnRet {
($W:ty, $Ctx:ty) => {
impl FnOnce(&mut $crate::Ui<$Ctx>) -> $W
};
}
pub(crate) use WidgetFnRet;
macro_rules! WidgetIdFnRet {
($W:ty, $Ctx:ty) => {
impl FnOnce(&mut $crate::Ui<$Ctx>) -> $crate::WidgetId<$W>
};
($W:ty, $Ctx:ty, $($use:tt)*) => {
impl FnOnce(&mut $crate::Ui<$Ctx>) -> $crate::WidgetId<$W> + use<$($use)*>
};
}
pub(crate) use WidgetIdFnRet;
pub trait Idable<Ctx, Tag> {
type Widget: Widget<Ctx>;
@@ -97,7 +114,7 @@ pub trait Idable<Ctx, Tag> {
fn id<'a>(
self,
id: &WidgetId<Self::Widget>,
) -> impl WidgetIdFn<Self::Widget, Ctx> + use<'a, Self, Ctx, Tag>
) -> WidgetIdFnRet!(Self::Widget, Ctx, 'a, Self, Ctx, Tag)
where
Self: Sized,
{