Tessera Macros
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.
Overview
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.
Features
- Component Integration: Automatically registers functions as components in the Tessera component tree
- Runtime Injection: Provides access to
measure
andinput_handler
functions within component functions - Clean Syntax: Enables declarative component definition with minimal boilerplate
- Tree Management: Handles component tree node creation and cleanup automatically
Usage
Basic Component Definition
use tessera;
Component with Parameters
use tessera;
use Arc;
Using Measure and Input Handler
use tessera;
use ;
How It Works
The #[tessera]
macro performs the following transformations:
- Component Registration: Adds the function to the component tree with its name
- Runtime Access: Injects code to access the Tessera runtime
- Function Injection: Provides
measure
andinput_handler
functions in the component scope - Tree Management: Handles pushing and popping nodes from the component tree
- Error Safety: Wraps the original function body to prevent early returns from breaking the component tree
Before Macro Application
After Macro Application (Conceptual)
Examples
Simple Counter Component
use tessera;
use ;
Custom Layout Component
use tessera;
use ;
Contributing
This crate is part of the larger Tessera project. For contribution guidelines, please refer to the main Tessera repository.
License
This project is licensed under the same terms as the main Tessera framework. See the LICENSE file for details.