change macro a bit
This commit is contained in:
@@ -21,6 +21,7 @@ struct InputFn {
|
|||||||
impl Parse for Input {
|
impl Parse for Input {
|
||||||
fn parse(input: ParseStream) -> Result<Self> {
|
fn parse(input: ParseStream) -> Result<Self> {
|
||||||
let vis = input.parse()?;
|
let vis = input.parse()?;
|
||||||
|
input.parse::<Token![trait]>()?;
|
||||||
let name = input.parse()?;
|
let name = input.parse()?;
|
||||||
input.parse::<Token![;]>()?;
|
input.parse::<Token![;]>()?;
|
||||||
let mut fns = Vec::new();
|
let mut fns = Vec::new();
|
||||||
|
|||||||
@@ -1,6 +1,25 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use iris_macro::widget_trait;
|
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
|
// TODO: naming in here is a bit weird like eventable
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! event_ctx {
|
macro_rules! event_ctx {
|
||||||
@@ -61,22 +80,3 @@ macro_rules! event_ctx {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub use 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#![feature(associated_type_defaults)]
|
#![feature(associated_type_defaults)]
|
||||||
|
|
||||||
mod default;
|
mod default;
|
||||||
mod traits;
|
mod event;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
pub use iris_core::*;
|
pub use iris_core::*;
|
||||||
@@ -12,7 +12,7 @@ pub use iris_macro::*;
|
|||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::default::*;
|
pub use super::default::*;
|
||||||
pub use super::traits::*;
|
pub use super::event::*;
|
||||||
pub use super::widget::*;
|
pub use super::widget::*;
|
||||||
|
|
||||||
pub use iris_core::layout::*;
|
pub use iris_core::layout::*;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use iris_macro::widget_trait;
|
|||||||
// these methods should "not require any context" (require unit) because they're in core
|
// these methods should "not require any context" (require unit) because they're in core
|
||||||
event_ctx!(());
|
event_ctx!(());
|
||||||
|
|
||||||
widget_trait!(
|
widget_trait! {
|
||||||
pub CoreWidget;
|
pub trait CoreWidget;
|
||||||
|
|
||||||
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad> {
|
fn pad(self, padding: impl Into<Padding>) -> impl WidgetFn<Pad> {
|
||||||
|ui| Pad {
|
|ui| Pad {
|
||||||
@@ -130,7 +130,7 @@ widget_trait!(
|
|||||||
fn set_ptr(self, ptr: &WidgetRef<WidgetPtr>, ui: &mut Ui) {
|
fn set_ptr(self, ptr: &WidgetRef<WidgetPtr>, ui: &mut Ui) {
|
||||||
ptr.get_mut().inner = Some(self.add(ui));
|
ptr.get_mut().inner = Some(self.add(ui));
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
|
||||||
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
pub trait CoreWidgetArr<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
|
||||||
fn span(self, dir: Dir) -> SpanBuilder<LEN, Wa, Tag>;
|
fn span(self, dir: Dir) -> SpanBuilder<LEN, Wa, Tag>;
|
||||||
|
|||||||
Reference in New Issue
Block a user