Skip to main content

Crate blit

Crate blit 

Source
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

  1. Tree::build runs your Widgets. they add and describe nodes, but nothing is sized or drawn yet. a node defers its own content to closures from Ui::measure and Ui::paint
  2. Tree::layout sizes and positions every node, running each layout and measure closure
  3. Tree::paint runs 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

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

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:

§storage

blit provides two ways to store temporary data without allocating:

Modules§

input
state
typestate modes for Ui

Macros§

builder
defines a builder struct with chainable setters

Structs§

AnimationOptions
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
ContactId
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
FrameInfo
FrameSlice
a typed slice resolved through the FrameStore that allocated it
FrameSliceBuilder
reserved frame storage exposing only its initialized prefix
FrameStore
drawing inputs owned by a rendering context until it clears them
FrameStoreMut
append-only mutable access to a FrameStore
Id
stable identity for widgets, animations and timers, handed out by Tree
InteractCx
input and timing for your interaction
LayoutCx
Motion
applies an animation to selected layout properties
MotionProps
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
ScratchBuffer
reusable storage for temporary slices and formatted text
ScratchStr
temporary text borrowed directly or formatted into a ScratchBuffer
ScrollEvent
wheel or trackpad input for this widget
Sides
Size
Spring
a linear spring tuned by duration and bounce
Timer
a timer from Ui::timer or Ui::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
ContactSource
kind of pointer producing a contact
Easing
easing as a cubic bezier or a function
KeyboardEvent
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
HasFrameStore
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

Type Aliases§

LogicalPoint
LogicalRect
LogicalSize
PhysicalPoint
PhysicalRect
PhysicalSize