declarative_gpui/lib.rs
1//! Declarative `ui!` macro for building GPUI element trees.
2//!
3//! All parsing and expansion logic lives in `declarative-gpui-core` — a
4//! normal library crate, so it can be unit-tested, benchmarked, and fuzzed
5//! (proc-macro crates export nothing but their macros, and the `proc_macro`
6//! API is only usable inside a real expansion). This crate is just the entry
7//! point converting at the `proc_macro` / `proc_macro2` boundary.
8
9use proc_macro::TokenStream;
10
11/// Build a GPUI element tree declaratively.
12///
13/// Elements take style tokens, `key = value` builder calls, and call-style
14/// args; children go in braces, and `if`/`for`/`match` expand to real Rust
15/// control flow. See the crate README for the full token reference.
16///
17/// ```ignore
18/// use declarative_gpui::ui;
19/// use gpui::prelude::*;
20///
21/// let view = ui! {
22/// col(gap_4 p_16 bg_1c1a17 rounded_lg) {
23/// text("Hello" text_lg semibold text_f5f0e8)
24/// for item in items {
25/// row(gap_2) { text(item.name) }
26/// }
27/// }
28/// };
29/// ```
30#[proc_macro]
31pub fn ui(input: TokenStream) -> TokenStream {
32 declarative_gpui_core::ui_impl(input.into()).into()
33}