textual_macros/lib.rs
1//! Proc macros for the textual TUI framework.
2//!
3//! Provides `#[derive(Reactive)]` for reactive field system.
4
5extern crate proc_macro;
6use proc_macro::TokenStream;
7
8mod reactive;
9
10/// Derive macro for the reactive field system.
11///
12/// Annotate struct fields with `#[reactive]`, `#[reactive(layout)]`,
13/// `#[reactive(watch)]`, or `#[var]` to generate getters, setters with
14/// change detection, and watcher dispatch.
15#[proc_macro_derive(Reactive, attributes(reactive, var, computed))]
16pub fn derive_reactive(input: TokenStream) -> TokenStream {
17 reactive::derive_reactive_impl(input.into()).into()
18}
19
20mod on_handler;
21
22/// Attribute macro for typed message handler dispatch.
23///
24/// Apply to a method to generate a companion dispatch method that
25/// pattern-matches against the `Message` enum and calls the handler
26/// with the typed event payload.
27///
28/// # Usage
29///
30/// ```ignore
31/// #[on(ButtonPressed)]
32/// fn handle_button(&mut self, event: &ButtonPressed, ctx: &mut EventCtx) { ... }
33///
34/// #[on(ButtonPressed, selector = "#save")]
35/// fn handle_save(&mut self, event: &ButtonPressed, ctx: &mut EventCtx) { ... }
36/// ```
37#[proc_macro_attribute]
38pub fn on(attr: TokenStream, item: TokenStream) -> TokenStream {
39 on_handler::on_handler_impl(attr.into(), item.into()).into()
40}