Expand description
Ui: the frame builder a Rust view declares its tree through.
A Ui borrows a Core for the length of one frame. It is a thin,
safe facade over the core’s flat builder methods (which are also the FFI
surface): every call opens, fills or closes a node, or reads a fact the
last frame established. It never captures app state, so view(&state)
and update(&mut state) cannot conflict.
The shape of a view: containers open with Ui::with (scoped) or
Ui::open/Ui::close, leaves with Ui::leaf and Ui::text,
and each node’s look and behaviour is a NodeSpec. Nodes are keyed by
position unless a _keyed or _indexed form gives them a stable
identity, which anything retained across frames (focus, scrolling, an
edit buffer, a transition) needs.
use kui_core::{Color, Core, NodeSpec, Size, Sizing, TextStyle, widgets};
let mut core = Core::new();
let mut ui = core.frame(Size::new(400.0, 300.0), 1.0);
let theme = ui.theme();
ui.configure_root(NodeSpec::column().fill().pad(12.0).gap(8.0));
// A toolbar: a row of buttons, keyed by their labels.
ui.with(NodeSpec::row().gap(6.0), |ui| {
widgets::button(ui, "Open", "open");
widgets::button(ui, "Save", "save");
});
// A panel that grows to fill the rest, with a label in it.
let panel = ui.with_keyed(
"panel",
NodeSpec::column().fill().pad(8.0).bg(theme.surface).radius(6.0),
|ui| {
ui.text("Ready.", TextStyle::new(14.0).color(theme.muted));
ui.leaf(NodeSpec::row().size(Sizing::GROW, 1.0).bg(Color::hex(0x80808080)));
},
);
assert!(!ui.is_hovered(panel)); // nothing has moved the pointer yet
ui.finish();Ui::finish is the one way out of a frame: it runs layout and
emission and leaves the results in Core::output.