zng_app_proc_macros/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#![doc(html_favicon_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/res/zng-logo-icon.png")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/res/zng-logo.png")]
//!
//! Proc-macros for `zng-app`.
//!
//! # Crate
//!
#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
#![warn(unused_extern_crates)]
#![warn(missing_docs)]

#[macro_use]
extern crate quote;

#[macro_use]
extern crate lazy_static;

use proc_macro::TokenStream;

#[macro_use]
mod util;

mod property;
mod ui_node;
mod wgt_property_attrs;
mod widget;
mod widget_util;

/// Expands an impl into a `UiNode` impl.
///
/// # Full Documentation
///
/// Read the documentation in the `zng::widget::ui_node` page.
#[proc_macro_attribute]
pub fn ui_node(args: TokenStream, input: TokenStream) -> TokenStream {
    ui_node::gen_ui_node(args, input)
}

/// Expands a function to a widget property.
///
/// # Full Documentation
///
/// Read the documentation in the `zng::widget::property` page.
#[proc_macro_attribute]
pub fn property(args: TokenStream, input: TokenStream) -> TokenStream {
    property::expand(args, input)
}

#[doc(hidden)]
#[proc_macro]
pub fn property_meta(input: TokenStream) -> TokenStream {
    property::expand_meta(input)
}

#[doc(hidden)]
#[proc_macro]
pub fn property_impl(input: TokenStream) -> TokenStream {
    property::expand_impl(input)
}

/// Expands a struct to a widget and macro.
///
/// # Full Documentation
///
/// Read the documentation in the `zng::widget::widget` page.
#[proc_macro_attribute]
pub fn widget(args: TokenStream, input: TokenStream) -> TokenStream {
    widget::expand(args, input, false)
}

/// Expands a generic struct to a widget mixin.
///
/// # Full Documentation
///
/// Read the documentation in the `zng::widget::widget_mixin` page.
#[proc_macro_attribute]
pub fn widget_mixin(args: TokenStream, input: TokenStream) -> TokenStream {
    widget::expand(args, input, true)
}

/// Expands a property assign to include a build action that applies an easing transition to the variable inputs.
///
/// # Full Documentation
///
/// Read the documentation in the `zng::widget::easing`.
#[proc_macro_attribute]
pub fn easing(args: TokenStream, input: TokenStream) -> TokenStream {
    wgt_property_attrs::expand_easing(args, input)
}

#[doc(hidden)]
#[proc_macro]
pub fn widget_new(input: TokenStream) -> TokenStream {
    widget::expand_new(input)
}

#[doc(hidden)]
#[proc_macro]
pub fn trace(input: TokenStream) -> TokenStream {
    eprintln!("{input}");
    input
}