rename widget fn macros

This commit is contained in:
2025-08-29 00:11:41 -04:00
parent 42f5a8d01b
commit d4690401eb
6 changed files with 32 additions and 34 deletions

View File

@@ -120,7 +120,7 @@ pub struct IdTag;
pub struct IdFnTag;
// pub trait WidgetIdFn<W, Ctx> = FnOnce(&mut Ui) -> WidgetId<W>;
macro_rules! WidgetIdFnRet {
macro_rules! WidgetIdFn {
($W:ty) => {
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W>
};
@@ -128,15 +128,12 @@ macro_rules! WidgetIdFnRet {
impl FnOnce(&mut $crate::layout::Ui) -> $crate::layout::WidgetId<$W> + use<$($use)*>
};
}
pub(crate) use WidgetIdFnRet;
pub(crate) use WidgetIdFn;
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, 'a, Self, Tag)
fn id<'a>(self, id: &WidgetId<Self::Widget>) -> WidgetIdFn!(Self::Widget, 'a, Self, Tag)
where
Self: Sized,
{
@@ -149,7 +146,7 @@ pub trait Idable<Tag> {
fn id_static<'a>(
self,
id: StaticWidgetId<Self::Widget>,
) -> WidgetIdFnRet!(Self::Widget, 'a, Self, Tag)
) -> WidgetIdFn!(Self::Widget, 'a, Self, Tag)
where
Self: Sized,
{

View File

@@ -1,4 +1,4 @@
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFnRet, Widgets};
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFn, Widgets};
use std::{any::Any, marker::PhantomData};
@@ -31,7 +31,7 @@ pub trait WidgetLike<Tag> {
fn with_id<W2>(
self,
f: impl FnOnce(&mut Ui, WidgetId<Self::Widget>) -> WidgetId<W2>,
) -> WidgetIdFnRet!(W2)
) -> WidgetIdFn!(W2)
where
Self: Sized,
{
@@ -48,12 +48,12 @@ pub trait WidgetLike<Tag> {
/// Useful for defining trait functions on widgets that create a parent widget so that the children
/// don't need to be IDs yet
/// currently a macro for rust analyzer (doesn't support trait aliases atm)
macro_rules! WidgetFnRet {
macro_rules! WidgetFn {
($W:ty) => {
impl FnOnce(&mut $crate::layout::Ui) -> $W
};
}
pub(crate) use WidgetFnRet;
pub(crate) use WidgetFn;
impl<W: Widget, F: FnOnce(&mut Ui) -> W> WidgetLike<FnTag> for F {
type Widget = W;