Compare commits

1 Commits

Author SHA1 Message Date
7f4846a2d3 change macro a bit 2025-12-09 02:03:54 -05:00
4 changed files with 25 additions and 24 deletions

View File

@@ -21,6 +21,7 @@ struct InputFn {
impl Parse for Input {
fn parse(input: ParseStream) -> Result<Self> {
let vis = input.parse()?;
input.parse::<Token![trait]>()?;
let name = input.parse()?;
input.parse::<Token![;]>()?;
let mut fns = Vec::new();

View File

@@ -1,6 +1,25 @@
use crate::prelude::*;
use iris_macro::widget_trait;
pub mod eventable {
use super::*;
widget_trait! {
pub trait Eventable;
fn on<E: Event, Ctx: 'static>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
move |ui| {
let id = self.add(ui);
ui.register_widget_event(&id, event, f);
id
}
}
}
}
// TODO: naming in here is a bit weird like eventable
#[macro_export]
macro_rules! event_ctx {
@@ -61,22 +80,3 @@ macro_rules! event_ctx {
};
}
pub use event_ctx;
pub mod eventable {
use super::*;
widget_trait!(
pub Eventable;
fn on<E: Event, Ctx: 'static>(
self,
event: E,
f: impl WidgetEventFn<Ctx, E::Data, WL::Widget>,
) -> impl WidgetIdFn<WL::Widget> {
move |ui| {
let id = self.add(ui);
ui.register_widget_event(&id, event, f);
id
}
}
);
}

View File

@@ -4,7 +4,7 @@
#![feature(associated_type_defaults)]
mod default;
mod traits;
mod event;
mod widget;
pub use iris_core::*;
@@ -12,7 +12,7 @@ pub use iris_macro::*;
pub mod prelude {
pub use super::default::*;
pub use super::traits::*;
pub use super::event::*;
pub use super::widget::*;
pub use iris_core::layout::*;

View File

@@ -4,8 +4,8 @@ use iris_macro::widget_trait;
// these methods should "not require any context" (require unit) because they're in core
event_ctx!(());
widget_trait!(
pub CoreWidget;
widget_trait! {
pub trait CoreWidget;
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad> {
|ui| Pad {
@@ -130,7 +130,7 @@ widget_trait!(
fn set_ptr(self, ptr: &WidgetRef<WidgetPtr>, ui: &mut Ui) {
ptr.get_mut().inner = Some(self.add(ui));
}
);
}
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
fn span(self, dir: Dir) -> SpanBuilder<LEN, Wa, Tag>;