Skip to main content

uzor_framework_macros/
lib.rs

1//! Procedural macros for `uzor-framework`.
2//!
3//! Exports `view!` — JSX-mimicking DSL that lowers to `widgets::lm::*`
4//! builder calls against a [`uzor_framework::widgets::ContentCx`] (a
5//! `PanelCx` or `OverlayCx`). Pure compile-time rewriting; no second
6//! manager.
7//!
8//! The macro expects one implicit identifier in scope:
9//! - `cx: &mut impl uzor_framework::widgets::ContentCx`
10//!
11//! And one prop-supplied rect on a root flex node (`<row rect={r}>` /
12//! `<col rect={r}>`), from which children rects are derived via
13//! `uzor_framework::flex::flex_solve`.
14
15extern crate proc_macro;
16
17mod lower;
18mod parse;
19
20use proc_macro::TokenStream;
21
22/// JSX-style view tree. Lowers to imperative
23/// `uzor_framework::widgets::lm::*` calls.
24///
25/// ```ignore
26/// view! {
27///     <col rect={body} gap=8>
28///         <button text="Save" on_click={|| self.save()} />
29///         <checkbox bind={&mut self.dark} label="Dark" />
30///     </col>
31/// }
32/// ```
33///
34/// Overlay tags (`modal`, `popup`, `dropdown`, `context_menu`) are deferred
35/// past M1 — they still needed layout façade handles after F8.
36#[proc_macro]
37pub fn view(input: TokenStream) -> TokenStream {
38    let node = match syn::parse::<parse::Node>(input) {
39        Ok(n) => n,
40        Err(e) => return e.to_compile_error().into(),
41    };
42    lower::lower_root(&node).into()
43}