Tessera (WIP)
Introduction
Tessera is a declarative, immediate-mode UI framework for Rust. With a functional approach at its core, it aims to provide ultimate performance, flexibility, and extensibility.
The project is currently in its early stages of development. Feel free to explore the latest progress through the example code.
Roadmap
Currently, the framework is in the early stages of development. The v0.1.0 roadmap includes:
-
Core: Implement framework core (tessera), including
Component treeMeasurement SystemState ManagementRenderer, including pluggable shader systemBasic types (Dp,Px)Focus management#[tessera] macro, for convenient component definition- Event handling
Mouse eventsTouch eventsRaw Keyboard events- IME event (windows, linux, macOS) (partially completed)
- IME event (android)
- IME event (ios)
-
Basic Components: Implement some basic components (tessera_basic_components), including
rowcolumnboxedtextspacer- text_editor (partially completed)
buttonsurfacefluid_glassscrollableimagecheckbox- radio
switchsliderprogressdialog
Core Features
- Declarative Component Model: Define and compose components using simple functions with the
#[tessera]macro, resulting in clean and intuitive code. - Powerful and Flexible Layout System: A constraint-based (
Fixed,Wrap,Fill) layout engine, combined with components likerowandcolumn(inspired by Jetpack Compose), makes it easy to implement responsive layouts from simple to complex.
-
Pluggable Shader Engine: Shaders are first-class citizens in Tessera. The core of Tessera doesn't come with built-in drawing primitives like a "brush". Instead, it provides an easy-to-use WGPU rendering/compute pipeline plugin system, offering an experience closer to some game engines. This is intentional, for the following reasons:
- The Advent of WGPU: The emergence of WGPU and WGSL has made shader programming simpler, more efficient, and easily adaptable to mainstream GPU backends. Writing shaders directly is no longer a painful process.
- Neumorphism: In recent years, pure flat design has led to visual fatigue, and more applications are adopting neumorphic design styles. The main difference from the old skeuomorphism of the 2000s is its hyper-realistic perfection, which requires many visual effects that are difficult to implement uniformly, such as lighting, shadows, reflections, refractions, bloom, and perspective. Attempting to encapsulate a perfect "brush" to achieve these effects is very difficult and inelegant.
- Flexibility: With custom shaders, we can easily implement advanced effects like custom lighting, shadows, particle systems, etc., without relying on the framework's built-in drawing tools.
- GPU Compute: One of the biggest advantages of WGPU over its predecessors is that compute shaders are first-class citizens. A future-oriented framework should take full advantage of this. By using custom compute shaders, we can perform complex computational tasks such as image processing and physics simulations, which are often unacceptably inefficient to perform on the CPU.
- Decentralized Component Design: Thanks to the pluggable rendering pipeline,
tesseraitself does not include any built-in components. Whiletessera_basic_componentsprovides a set of common components, you are free to mix and match or create your own component libraries. - Explicit State Management: Components are stateless. State is passed in explicitly as parameters (usually in the form of
Arc<Lock<State>>due to the highly parallel design), and interaction logic is handled within thestate_handlerclosure, making data flow clear and controllable. - Parallelized By Design: The framework utilizes parallel processing in its core. For example, the size measurement of the component tree uses Rayon for parallel computation to improve the performance of complex UIs.
A Glance
Here is a simple counter application using tessera_basic_components that demonstrates the basic usage of Tessera.
/// Main counter application component
Core Concepts
-
Component Model
Tesseracomponents are regular Rust functions annotated with the#[tessera]macro. This macro integrates the component function into the framework's component tree. Inside the function body, you can callmeasureto customize layout logic, measure and place child component functions to build the UI hierarchy, and callstate_handlerto handle user interactions.measureandstate_handlerare automatically injected into the function context by thetesseramacro and do not need to be imported. -
Layout & Measurement The UI layout is determined during the "measurement" phase. Each component can provide a
measureclosure, in which you can:- Measure the size of child components (with constraints).
- Use
place_nodeto determine the position of child components. - Return the final size of the current component (
ComputedData). If nomeasureclosure is provided, the framework defaults to stacking all child components at(0, 0)and setting the container size to the minimum size that envelops all children.
-
State Management
Tesserapromotes an explicit state management pattern. Components are stateless; they receive shared state via parameters (usuallyArc<T>). All state changes and event responses are handled within thestate_handlerclosure, which makes the data flow unidirectional and predictable.
Getting Started
tessera is currently in early development, and there is no stable way to create a project yet. The following uses the example crate as a showcase project that runs on Windows, Linux, macOS, and Android.
Running the Example on Windows / Linux
# Enter the example directory
# Run
Running the Example on Android
-
Install xbuild
-
Run the example
# Find your device ID # Assuming device ID is adb:823c4f8b and architecture is arm64
Workspace Structure
Tessera uses a multi-crate workspace structure with a clear separation of responsibilities:
tessera: The core functionality of the framework, including the component tree, renderer, runtime, basic types (Dp,Px), and event handling.tessera_basic_components: Provides a set of ready-to-use UI components (likerow,column,text,button,surface) and their rendering pipelines.tessera_macros: Contains the#[tessera]procedural macro, which greatly simplifies component definition. Documentationexample: An example project demonstrating how to build applications with theTesseraframework.
License
Tessera is licensed under either of the MIT License or the Apache License 2.0.