| Crates.io | tessera-macros |
| lib.rs | tessera-macros |
| version | 0.0.0 |
| created_at | 2026-01-07 05:04:13.586868+00 |
| updated_at | 2026-01-07 05:04:13.586868+00 |
| description | Macros of tessera-ui. |
| homepage | https://tessera-ui.github.io |
| repository | https://github.com/tessera-ui/tessera |
| max_upload_size | |
| id | 2027551 |
| size | 38,824 |
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.
layout and input_handler functions within component functionsuse tessera_macros::tessera;
#[tessera]
fn my_component() {
// Your component logic here
// The macro automatically provides access to:
// - layout: 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_ui::{ComputedData, LayoutInput, LayoutOutput, LayoutSpec, MeasurementError, Px};
#[derive(Clone, PartialEq)]
struct FixedLayout;
impl LayoutSpec for FixedLayout {
fn measure(
&self,
_input: &LayoutInput<'_>,
_output: &mut LayoutOutput<'_>,
) -> Result<ComputedData, MeasurementError> {
Ok(ComputedData {
width: Px(100),
height: Px(50),
})
}
}
#[tessera]
fn custom_component() {
// Define custom layout behavior
layout(FixedLayout);
// Handle user interactions
input_handler(|_| {
// Handle events like clicks, key presses, etc.
});
}
The #[tessera] macro performs the following transformations:
layout 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 layout and input_handler functions
let layout = |spec: impl LayoutSpec| { /* ... */ };
let input_handler = |fun: impl Fn(InputHandlerInput) + Send + Sync + 'static| { /* ... */ };
// 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 tessera_ui::remember;
use tessera_components::{
button::{ButtonArgs, button},
text::text,
};
#[tessera]
fn counter_component() {
let count = remember(|| 0i32);
button(
ButtonArgs::filled(move || count.with_mut(|c| *c += 1)),
|| text(format!("Count: {}", count.get())),
);
}
use tessera_macros::tessera;
use tessera_ui::{ComputedData, LayoutInput, LayoutOutput, LayoutSpec, MeasurementError, Px};
#[derive(Clone, PartialEq)]
struct FixedLayout;
impl LayoutSpec for FixedLayout {
fn measure(
&self,
_input: &LayoutInput<'_>,
_output: &mut LayoutOutput<'_>,
) -> Result<ComputedData, MeasurementError> {
Ok(ComputedData {
width: Px(120),
height: Px(80),
})
}
}
#[tessera]
fn custom_layout() {
layout(FixedLayout);
// 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.