RAUI
Renderer Agnostic User Interface
Table of contents
About
RAUI is heavely inspired by React declarative UI composition and UE4 Slate widget components system.
The main idea behind RAUI architecture is to treat UI as another data that you transform into target renderable data format used by your rendering engine of choice.
Architecture
Application
It is the central point of user interrest. It performs whole UI processing logic. There you apply widget tree that wil be processed, send messages from host application to widgets and receive signals sent from widgets to host application.
let mut application = new;
let tree = widget! ;
let mut renderer = default;
application.apply;
if let Ok = application.render
Widget
Widgets are divided into two categories:
- Widget Node - used as source UI trees (variant that can be either a component, unit or none)
widget!
- Widget Component - you can think of them as Virtual DOM nodes, they store:
- pointer to component function (that process their data)
- unique key (that is a part of widget ID and will be used to tell the system if it should carry its state to next processing run)
- boxed cloneable properties data (if component is a function, then properties are function arguments)
- listed slots (simply: widget children)
- named slots (similar to listed slots: widget children, but these ones have names assigned to them, so you can access them by name instead of by index)
- Widget Unit - an atomic element that renderers use to convert into target renderable data format for rendering engine of choice.
widget!
Component Function
Component functions are static functions that transforms input data (properties, state or neither of them) into output widget tree (usually used to simply wrap another components tree under one simple component, where at some point the simplest components returns final widget units). They work together as a chain of transforms - root component applies some properties into children components using data from its own properties or state.
implement_props_data!;
widget_component!
widget_component!
This may bring up a question: "If i use only functions and no objects to tell how to visualize UI, how do i keep some data between each render run?". For that you use states. State is a data that is stored between each processing call as long as given widget is alive (that means: as long as widget id stays the same between two processing calls, to make sure your widget stays the same, you use keys - if no key is assigned, system will generate one for your widget but that will make it possible to die at any time if for example number of widget children changes in your common parent, your widget will change its id when key wasn't assigned). Some additional notes: While you use properties to send information down the tree and states to store widget data between processing cals, you can communicate with another widgets and host application using messages and signals! More than that, you can assign a closure that will be called when your widget gets unmounted from the tree.
widget_component!
Installation
There is a main raui
crate that contains all of the project sub-crates to allow easy access to all features needed at any time, each enabled using Cargo feature
flags (by default only raui-core
subcrate is enabled).
[]
= { = "0.5", = ["all"] }
raui-core
- Core module that contains all RAUI essential logic.[] = "0.5"
raui-binary-renderer
- Renders RAUI widget tree into binary format.[] = "0.5"
raui-html-renderer
- Renders RAUI widget tree into simple HTML format.[] = "0.5"
raui-json-renderer
- Renders RAUI widget tree into JSON format.[] = "0.5"
raui-ron-renderer
- Renders RAUI widget tree into RON format.[] = "0.5"
raui-yaml-renderer
- Renders RAUI widget tree into YAML format.[] = "0.5"
TODO
RAUI is still in early development phase, so prepare for these changes until v1.0:
- Reduce unnecessary allocations in processing pipeline.
- Find a solution (or make it a feature) for moving from trait objects data into strongly typed data for properties and states.
- Create renderer for at least one popular Rust graphics engine.
- Make C API bindings.