Expand description
a small immediate-mode library for building user interfaces
§frame lifecycle
every frame builds the Tree from scratch, then lays it out and paints it
Tree::buildruns yourWidgets. they add and describe nodes, but nothing is sized or drawn yet. a node defers its own content to closures fromUi::measureandUi::paintTree::layoutsizes and positions every node, running each layout and measure closureTree::paintruns each paint closure with its node’s solved area
§layout
a node arranges its children with the Layout from Ui::layout. each child can pass
the layout a Layout::Item through Ui::item
a layout works one axis at a time
Layout::fitreports the smallest and natural extents of the contentLayout::distributesplits the final extent and positions the children
Ui::place positions a node outside its parent’s flow, relative to a target node, with a
Place. popovers use this
§interaction
Ui::interact adds an Interact to a node and returns its latest response.
interactions run before each build using the last build’s layout, so a widget sees this
frame’s input while it builds
§identity
every node receives a stable Id matched across frames without hashing
Ui::childmatches by parent and call siteUi::child_inmatches by an integerKeyin aScope(fromUi::scopeorScope::ROOT)Ui::resolveturns a scope and key into itsIdbefore the node is builtUi::nodequeries a node’s previous area or attaches interactions byId
an Id stops resolving once its node is absent for a full build, so resolve from a scope
and key each frame rather than storing Ids across frames
fn list<C: Context>(mut ui: Ui<'_, C>, rows: &[u32]) {
let scope = ui.scope();
let mut column = ui.layout(());
for &row in rows {
// keyed by row, so each keeps its state when the list reorders
column.child_in(scope, row).insert(());
}
}§context
everything is generic over a Context, which carries frame wide resources such as a
renderer, theme, or asset cache into every widget, layout and paint closure. keep application
state in your app and pass it down explicitly. a context opts into capabilities:
Paint<T>draws commandT. paint callbacks send commands through itHasFrameStoreprovides aFrameStorefor data that lasts the whole frame
§storage
blit provides two ways to store temporary data without allocating:
Scratchlasts until the current scope endsFrameSlicelasts the whole frame. use it for data a draw command reads later
Modules§
Macros§
- builder
- defines a builder struct with chainable setters
Structs§
- Animation
Options - controls how scalar motion starts and retargets
- Children
- flow children of a node in build order, skipping nodes positioned with
Place - Constraints
- Contact
- a mouse button press or touch, from down to release or cancellation
- Contact
Id - identifies one press or touch within a
Tree - Contacts
- iterate contact handles from
InteractCx::contacts - Corners
- radii of a rounded rectangle
- Fit
- smallest and natural content extents
- Frame
Info - Frame
Slice - a typed slice resolved through the FrameStore that allocated it
- Frame
Slice Builder - reserved frame storage exposing only its initialized prefix
- Frame
Store - drawing inputs owned by a rendering context until it clears them
- Frame
Store Mut - append-only mutable access to a
FrameStore - Id
- stable identity for widgets, animations and timers, handed out by
Tree - Interact
Cx - input and timing for your interaction
- Layout
Cx - Motion
- applies an animation to selected layout properties
- Motion
Props - NodeId
- identifies a node only during the current render
- PaintCx
- context resources and temporary storage for painting
- PlaceCx
- resolves an out of flow node after all flow layout
- Point
- Rect
- Scale2
- Scope
- a space of keys, so keys from unrelated code never meet
- Scratch
- a growable temporary buffer exposing only its initialized elements
- Scratch
Buffer - reusable storage for temporary slices and formatted text
- Scratch
Str - temporary text borrowed directly or formatted into a
ScratchBuffer - Scroll
Event - wheel or trackpad input for this widget
- Sides
- Size
- Spring
- a linear spring tuned by duration and bounce
- Timer
- a timer from
Ui::timerorUi::interval - Tree
- Tween
- an easing curve with a duration specifying the time to reach the target
- Ui
- scoped handle for building a tree node
Enums§
- Animation
- target motion using a tween or a spring
- Axis
- Contact
Source - kind of pointer producing a contact
- Easing
- easing as a cubic bezier or a function
- Keyboard
Event - keyboard and text input routed through focus
- Phase
- StrSource
- text from borrowed strings or formatting arguments
Traits§
- Context
- resources shared by every widget, layout and painter in a frame
- HasFrame
Store - provides access to drawing inputs owned by a context
- Interact
- handle input for your widget
- Key
- a key in a
Scope, any integer widened so one value names one node whatever its type - Layout
- Paint
- accepts one kind of drawing operation in frame coordinates
- Place
- positions a node outside its parent’s flow
- Scalar
- coordinate arithmetic and snapping used by
Context::Scalar - Widget
- builds part of the ui each frame and returns a response such as whether it was clicked