agnosticlayer
English | Русский
A flat, renderer-agnostic data layer for widget-style UI trees.
The crate stores widget data (nodes, labels, containers, images, hit shapes) in plain HashMaps and draws nothing. You read the maps and pass them to your own renderer: wgpu, a terminal, anything. The types for ids, text, images and shapes are yours.
What's inside
Node<Id>: transform, size, scale, optionalparent; the base of every widgetLabel<Text, Id>: text from your own type (TextItem)DynamicLabel<Id>: text owned by the widget itself (String)Container<Id>: padding and clipImage<ImageHandle, Id>: your own image handleHitLayer<SVec, SMap, Id>: a shape-to-id table backed by aVecor aHashMap, for your own hit testingLayer<SVec, SMap, ImageHandle, Text, Id>: owns all the maps; methodsadd_*,remove_*,update_*,get_*
What it isn't
- A scene graph: nesting is a single
parent: Option<Id>field, and you walk the tree yourself. Any widget can be a parent. - A renderer, layout engine or input handler.
- Tied to specific types:
WidgetId,TextItem,ImageItem,ShapeVecandShapeMapare traits.WidgetId,ImageItem,ShapeVecandShapeMapare implemented for every suitable type, sou32works as is.
Quick start
[]
= "0.2.0"
use *;
use ;
use ;
use Layer;
use Node;
// Your own text type
;
// Layer<SVec, SMap, ImageHandle, Text, Id>
// Unused parameters can be set to `Void` or `()`
let mut layer: = new;
let root = new;
layer.add_container;
// A label whose parent is 1
let label = new;
layer.add_label;
// The label's parent
let parent = layer.get_container_label;
// Reading for rendering
for label in layer.get_label_map.values
The crate does not perform hit testing: HitLayer only stores a shape-to-id table, and the actual hit check is yours to write. To use the table, put your own shape type in place of Void in SVec (for the Vec) or in SMap (for the HashMap; the shape must be Hash + Eq).
let mut layer: = new;
let button = Rect ;
layer.add_hit_in_vec;
let id = layer.get_hit_in_vec; // Some(2)
Lookup is by shape equality. Whether a cursor falls inside a Rect is up to your code; the table gives you the widget id.