Expand description
Keru is an experimental graphical user interface library.
§Code Example
// Define a unique identity for the button
#[node_key] const INCREASE: NodeKey;
 
// Create a NodeParams struct describing a button
let increase_button = BUTTON
    .color(Color::RED)
    .text("Increase")
    .key(INCREASE);
 
// Place the nodes into the tree and define the layout
ui.v_stack().nest(|| {
    ui.add(increase_button);
    ui.label(&state.count.to_string());
});
 
// Change the state in response to events
if ui.is_clicked(INCREASE) {
    state.count += 1;
}
// `is_clicked()` can be also called as a chained method after `ui.add(increase_button)`.
// In that case, using a key wouldn't be necessary.See the counter_small example in the repository for a full working version of this code.
§Window Loop
Keru is meant to be used as part of a regular winit/wgpu window loop managed by the library user, as shown in the window_loop example in the repository. However, it also includes a one-line window loop that can be used for quick experimentation.
Once you have a window loop, you can create a Ui struct and store it in your main program state.
§Building the GUI
Every frame, start a new GUI frame, rerun all your GUI building code, then finish the frame.
ui.begin_frame();
ui.v_stack().nest(|| {
    ui.label("Hello");
    ui.label("World");
});
ui.finish_frame();The Ui struct retains the state of the whole GUI, so even if you do this on every frame, it doesn’t mean that the GUI is rerendering or doing a full relayout every time. The library can detect differences and apply only the minimal updates or partial relayouts needed.
- 
In Keru, everything is a node. Whether you want a button, an image, a text element, a stack container, or anything else, the way is always to
add()a node with the rightNodeParams. - 
Uihas some convenience methods likeUi::label(). These are always equivalent toaddingone or more nodes with specificNodeParams. - 
To check interactions on a node, use
NodeParams::key()to associate aNodeKeyto aNodeParams, then call methods likeUi::is_clicked()with the sameNodeKey. - 
You can use the
NodeKey::sibling()function to create keys dynamically at runtime. This is useful for dynamic GUIs where you can’t identify every node with a staticNodeKeyin the way the basic examples do it. - 
To create reusable “components”, you can just wrap the GUI building code in a function, like the builtin convenience functions like
Ui::label()do. If the code uses uniqueNodeKeys, however, you’ll need to wrap it in asubtree.This allows multiple calls to the same component function to reuse the same key multiple times without conflicts.
 - 
The
Ui::reactive()function provides an experimental way to improve performance in complex GUIs with many independent components. 
Modules§
- basic_
window_ loop  - Helper functions for 
winitandwgpu. - example_
window_ loop  - A very simple way to start a 
winit/wgpuwindow loop and to draw a Keru GUI inside it. - winit_
key_ events  - winit_
mouse_ events  
Structs§
- Color
 - A 
rgbacolor - Full
Node Params  - An extended version of 
NodeParamsthat can hold text or other borrowed data. - Immut
 - A wrapper struct for a value that will never change during its lifetime.
 - Interact
 - The node’s interact behavior.
 - Layout
 - The node’s layout, size and position.
 - NodeKey
 - An unique key that identifies a GUI node.
 - Node
Params  - A struct describing the params of a GUI node.
 - Observer
 - A wrapper that keeps track of changes to a value.
 - Reactive
 - A struct referring to a reactive block created with 
Ui::reactive(). - Rect
 - The node’s visual appearance.
 - Render
Info  - The data needed for rendering a node with custom code.
 - Rounded
Corners  - A bitflag struct defining which corners of a rectangle are rounded
 - Stack
 - Options for stack container nodes.
 - Static
 - A wrapper struct for a 
'staticvalue that will never change during its lifetime. - Tab
 - A tab for 
Ui::vertical_tabs - Text
Options  - Options for text nodes.
 - Ui
 - The central struct of the library, representing the whole GUI state.
 - UiParent
 - A struct referring to a node that was 
addedon the tree. - UiSubtree
 - A struct referring to a subtree created with 
Ui::subtree()orUi::named_subtree(). - Vertex
Colors  - A node’s vertex colors.
 - Xy
 - A generic container for two-dimensional data.
 
Enums§
- Arrange
 - Options for the arrangement of child nodes within a stack node.
 - Axis
 - The X or Y axes.
 - Len
 - A length on the screen, expressed either as pixels or as a fraction of a parent rectangle.
 - Position
 - A node’s position relative to its parent.
 - Shape
 - The node’s shape.
 - Size
 - A node’s size.
 
Constants§
- BUTTON
 NodeParamsfor a button.- CONTAINER
 NodeParamsfor a container.- CUSTOM_
RENDERED_ PANEL  NodeParamsfor a custom rendered node.- DEFAULT
 NodeParamsfor a default.- H_STACK
 NodeParamsfor a horizontal stack.- ICON_
BUTTON  NodeParamsfor an icon button.- IMAGE
 NodeParamsfor an image.- IMAGE_
BUTTON  NodeParamsfor an icon button.- LABEL
 NodeParamsfor a label.- MARGIN
 NodeParamsfor a margin.- MULTILINE_
LABEL  NodeParamsfor a label containing a multi-line paragraph.- PANEL
 NodeParamsfor a panel.- SPACER
 NodeParamsfor a spacer element.- TEXT
 NodeParamsfor a text element.- TEXT_
EDIT  NodeParamsfor a text element.- TEXT_
PARAGRAPH  NodeParamsfor a text element containing a multi-line paragraph.- V_
SCROLL_ STACK  NodeParamsfor a vertically scrollable vertical stack.- V_STACK
 NodeParamsfor a vertical stack.
Traits§
Functions§
- is_
in_ skipped_ reactive_ block  - Returns 
trueif currently in a reactive block that is being skipped. 
Type Aliases§
- Subtree
Key  - XyRect
 - A two-dimensional rectangle.