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

@@ -33,7 +33,6 @@ pub struct Sensor<Ctx> {
pub type SensorMap<Ctx> = HashMap<Id, SensorGroup<Ctx>>;
pub type ActiveSensors = Vec<(SenseShape, Id)>;
pub trait SenseFn_<Ctx> = FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static;
pub type SenseShape = UiRegion;
#[derive(Clone)]
pub struct SenseTrigger {
@@ -45,10 +44,10 @@ pub struct SensorGroup<Ctx> {
pub cursor: ActivationState,
pub sensors: Vec<Sensor<Ctx>>,
}
pub trait SenseFn<Ctx>: SenseFn_<Ctx> {
pub trait SenseFn<Ctx>: FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>>;
}
impl<F: SenseFn_<Ctx> + Clone, Ctx> SenseFn<Ctx> for F {
impl<F: FnMut(&mut Ui<Ctx>, &mut Ctx) + 'static + Clone, Ctx> SenseFn<Ctx> for F {
fn box_clone(&self) -> Box<dyn SenseFn<Ctx>> {
Box::new(self.clone())
}

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,
{