Sakura (Jetstream::Sakura) is CyberEther's retained, GPU-native user interface toolkit. It powers both the default flowgraph workbench and Superluminal, replacing earlier immediate-mode ImGui and ImNodes widgets with a unified component tree rendered directly through CyberEther's Metal, Vulkan, and WebGPU backends.
This guide is for contributors building or extending compositor views, settings panels, or custom frontends on top of Sakura.
The Retained Component Model
Unlike immediate-mode UI libraries that rebuild every widget from scratch on every frame, Sakura maintains a persistent tree of Sakura::Component objects:
- Owners keep components alive. A view or presenter owns its child widgets as member fields (components are non-copyable and non-movable) and passes child pointers through widget configs. Custom
Componentsubclasses manage their own children through protected helpers (addChild(),removeChild(),clearChildren(),setChildren(), andmountChildren()). - Concrete widgets update via
Config. Built-in widgets follow a value-typeConfig+update(Config)convention (not virtual methods onComponent). Callingupdate()compares the incoming config against the current state and invalidates only what changed. - Invalidation is categorized. Calling
invalidate(Dirty)marks a component with one of fiveComponent::Dirtycategories:Paint,Resource,Tree,Order, orLayout. Unchanged subtrees avoid unnecessary layout and paint work during normal edits, and the interface only redraws when something changes (full canvas resource rebuilds still walk the tree as needed).
Minimal Retained View Example
#include <jetstream/render/sakura/base.hh>
using namespace Jetstream;
struct StatusPanel {
Sakura::Div card;
Sakura::Stack row;
Sakura::Text label;
Sakura::Badge badge;
void update(const std::string& title, bool active) {
label.update({
.str = title,
.font = Sakura::Text::Font::Display,
.colorKey = "text_primary",
.scale = Sakura::Typography::Scale::Lead,
});
badge.update({
.label = active ? "Running" : "Paused",
});
row.update({
.axis = Sakura::Stack::Axis::Horizontal,
.spacing = Sakura::Spacing::Medium,
.items = {
{.child = &label},
{.child = &badge},
},
});
card.update({
.content = &row,
.size = {Sakura::Fill, 0.0f},
.padding = Sakura::Spacing::Medium,
.rounding = Sakura::Rounding::Card,
.border = true,
});
}
};
Component Lifecycle Hooks
Custom components derive from Sakura::Component (include/jetstream/render/sakura/component.hh) and override only the hooks they need:
| Hook | Purpose |
|---|---|
measure(ctx, available) |
Computes and returns the component's resolved preferred extent within the available bounds. |
layout(ctx) |
Positions child components via layoutChild() and sets clipping rectangles. |
build(ctx) |
Creates or updates GPU render primitives when Dirty::Resource is flagged. |
paint() |
Updates per-frame visual properties when Dirty::Paint is flagged. |
conceal() |
Hides render primitives when a component becomes invisible. |
wentOnscreen(frame) / wentOffscreen(frame) |
Runs during presentation according to tree visibility (distinct from destruction), letting live surfaces pause or resume work. |
Widget configs that accept an explicit size use Sakura::Fill (-1.0f) as a sentinel to request the full available width or height.
Layout and Stacking Layers
Sakura separates layout arrangement from window-wide z-ordering:
- Layout containers: Compose interfaces with
Stack(horizontal or vertical),Grid,Div,Aside,ScrollArea,Dock,Panel,Spacer,Overlay,Reveal, andPopup. - Stacking layers: The top-level
Sakura::Root(backed bySakura::Canvas) renders an explicit list ofLayer*children viaRoot::Config::layers. Stacking order comes strictly from the order passed toRoot::Config::layers, not from layer class names. Built-in layer types includeBackgroundLayer,HudLayer,FloatingLayer,ModalLayer, andToastLayer.
Palette, Style, and Typography
Visual consistency across the workbench comes from three lightweight headers:
- Palette (
palette.hh): DefinesSakura::Paletteas astd::unordered_map<std::string, ColorRGBA<F32>>mapping semantic color keys (such as"text_primary") to RGBA colors. Internal compositor and render theme helpers (such asMakeSurfaceTheme()insrc/render/sakura/themes.hh) derive matching visualization surface colors from the active palette. - Style tokens (
style.hh): Namespace-level structs define standard geometry constants:- Rounding (
Sakura::Rounding):Control(8),Card(12), andPopup(18). - Spacing (
Sakura::Spacing):XSmall(4),Small(8),Medium(12),Large(16),XLarge(24), andXXLarge(32).
- Rounding (
- Typography (
typography.hh): BaseTypography::FontSizeis15.0f, paired withTypography::Scalesteps (Small,Caption,Body,Lead,Large,Title,Heading,Headline). Keep font family mapping in mind when configuringSakura::Text:Font::DisplayandFont::DisplaySemiBolduse the display fonts,Font::SansandFont::SansBolduse the proportional body fonts, andFont::Body,Font::H1,Font::H2, andFont::Boldresolve to the monospace font family.
Input Routing, Focus, and Shortcuts
Pointer, scroll, keyboard, and text events travel through Sakura's input router to component hooks (mouseEvent, scrollPhaseEnded, keyEvent, textEvent, shortcutEvent, and focusChanged), while file drops enter through Canvas::dropFiles() and dispatch to fileDrop.
- Focus management: Components coordinate keyboard focus using
requestFocus(),offerFocus(),releaseFocus(),releaseFocusWithin(),hasFocus(), andtextEditorFocused(). - Clipboard: Use
Sakura::SetClipboardText(window, value)andSakura::GetClipboardText(window)(clipboard.hh) for platform-independent clipboard access. - Keyboard shortcuts: Wrap any subtree in
Sakura::Shortcuts(components/shortcuts.hh) to bind key combinations:
keys.update({
.bindings = {
{
.key = KeyCode::K,
.modifier = Sakura::Shortcuts::Modifier::Primary,
.yieldsToText = true,
.onPressed = [this]() { openSearch(); },
},
},
.content = &page,
});
The Modifier::Primary option matches either Control or Super (Command) on every platform, while Shortcuts::PrimaryName() formats the displayed label for the current OS. Set yieldsToText = true on bindings that should defer when a text input or code editor holds focus.
Embedding GPU Surfaces
Live visualization blocks (SURFACE-tainted modules) render into GPU textures that Sakura displays inside node cards and detached dock tiles via Sakura::SurfaceImage (components/surface_image.hh):
surfaceImage.update({
.texture = moduleSurfaceTexture,
.rounding = Sakura::Rounding::Control,
.onSize = [this](const Sakura::SurfaceResize& resize) {
updateSurfaceExtent(resize.logicalSize, resize.framebufferSize, resize.scale);
},
.onInput = [this](InputEvent event) {
surface->pushInputEvent(std::move(event));
},
});
- The
onSizecallback delivers aSakura::SurfaceResizecontaininglogicalSize,framebufferSize, and displayscale. - The
onInputcallback deliversInputEventvalues (MouseEvent,KeyEvent, andFocusEvent). Forwarding them toModule::Surface::pushInputEvent()is explicit.
For the module side of surface input (normalized coordinates, focus-loss cleanup, and ProcessSurfaceInteraction()), see Interactive Surface Input.
Built-In Component Families
Headers under include/jetstream/render/sakura/components/ group into five main families:
| Family | Key Components |
|---|---|
| Layout and navigation | Stack, Grid, Div, Aside, Dock, Panel, ScrollArea, SidebarItem, Outline, StatusBar |
| Controls and forms | Button, PillButton, ChromeButton, Toggle, Combo, Dropdown, TextInput, PillInput, PillStepper, PillTabs, SettingCard, SettingField |
| Drawing, content, and data | Box, Card, Text, Label, Badge, Markdown, Table, Image, SurfaceImage, Curves, Polyline, Sparkline, ProgressBar, QrCode |
| Editors and workbench tools | CodeEditor, MarkdownEditor, TextEditor, Console, LogView, Terminal, Chat, SearchCatalog, ModelPicker, node/ |
| Overlays and feedback | ModalLayer, FloatingLayer, HudLayer, ToastLayer, Overlay, Popup, Menu, Spinner, TipBanner |