| Crates.io | tessera-ui-macros |
| lib.rs | tessera-ui-macros |
| version | 0.4.1 |
| created_at | 2025-07-15 15:15:38.214772+00 |
| updated_at | 2025-09-13 06:13:14.166676+00 |
| description | Macros of tessera-ui, for creating functional components. |
| homepage | https://tessera-ui.github.io |
| repository | https://github.com/tessera-ui/tessera |
| max_upload_size | |
| id | 1753484 |
| size | 35,847 |
The tessera_macros crate provides procedural macros for the Tessera UI framework. Currently, it contains the #[tessera] attribute macro, which is essential for creating components in the Tessera framework.
The #[tessera] macro transforms regular Rust functions into Tessera UI components by automatically integrating them into the framework's component tree and injecting necessary runtime functionality.
measure and input_handler functions within component functionsuse tessera_macros::tessera;
#[tessera]
fn my_component() {
// Your component logic here
// The macro automatically provides access to:
// - measure: for custom layout logic
// - input_handler: for handling user interactions
}
use tessera_macros::tessera;
use std::sync::Arc;
#[tessera]
fn button_component(label: String, on_click: Arc<dyn Fn()>) {
// Component implementation
// The macro handles component tree integration
}
use tessera_macros::tessera;
use tessera::{ComputedData, Constraints};
#[tessera]
fn custom_component() {
// Define custom layout behavior
measure(Box::new(|_| {
// Custom measurement logic
use tessera::{ComputedData, Px};
Ok(ComputedData {
width: Px(100),
height: Px(50),
})
}));
// Handle user interactions
input_handler(Box::new(|_| {
// Handle events like clicks, key presses, etc.
}));
}
The #[tessera] macro performs the following transformations:
measure and input_handler functions in the component scope#[tessera]
fn my_component() {
// Component logic
}
fn my_component() {
// Component tree registration
TesseraRuntime::write().component_tree.add_node(ComponentNode { ... });
// Inject measure and input_handler functions
let measure = |fun: Box<MeasureFn>| { /* ... */ };
let input_handler = |fun: Box<InputHandlerFn>| { /* ... */ };
// Execute original function body safely
let result = {
let closure = || {
// Original component logic here
};
closure()
};
// Clean up component tree
TesseraRuntime::write().component_tree.pop_node();
result
}
use tessera_macros::tessera;
use std::sync::{Arc, atomic::{AtomicI32, Ordering}};
#[tessera]
fn counter_component(count: Arc<AtomicI32>) {
let current_count = count.load(Ordering::Relaxed);
// Use tessera_basic_components for UI
button(
ButtonArgs {
on_click: Arc::new(move || {
count.fetch_add(1, Ordering::Relaxed);
}),
..Default::default()
},
button_state,
move || text(format!("Count: {}", current_count)),
);
}
use tessera_macros::tessera;
use tessera::{ComputedData, Constraints, Px};
#[tessera]
fn custom_layout() {
measure(Box::new(|_| {
// Custom measurement logic
use tessera::{ComputedData, Px};
Ok(ComputedData {
width: Px(120),
height: Px(80),
})
}));
// Child components
text("Hello, World!");
}
This crate is part of the larger Tessera project. For contribution guidelines, please refer to the main Tessera repository.
This project is licensed under the same terms as the main Tessera framework. See the LICENSE file for details.