Run one frame with the app's build procedure.
Queued input is applied first, against the previous frame's layout, and build reacts to it
while it runs (button returns true, a text editor takes the typed text). A widget declared
above the one that reacted has already been drawn from the old state, so when the frame had input
it builds once more with the input spent: what you queued shows in the tree and the layout when
frame returns. build therefore runs twice on such a frame, and the second run sees no clicks,
keys or focus changes. A frame without input builds once.
- ui: the UI to run the frame on.
- app: your app state, passed to
build. - build: declares the widgets for the frame.
ui := headless(.{ width = 320, height = 200 });
defer free_ui(*ui);
count := 0;
build := (n: *int) {
for column(.{ gap = 8, padding = 16 }) {
label(tprint("Clicked % times", n.*));
if button("Add") n.* += 1;
}
};
frame(*ui, *count, build);
click(*ui, find_label(*ui, "Add"));
frame(*ui, *count, build);
assert(count == 1);frame :: (ui: *UI_State, app: *$T, build: (app: *T))
Run one frame with the app's build procedure.
Queued input is applied first, against the previous frame's layout, and build reacts to it
while it runs (button returns true, a text editor takes the typed text). A widget declared
above the one that reacted has already been drawn from the old state, so when the frame had input
it builds once more with the input spent: what you queued shows in the tree and the layout when
frame returns. build therefore runs twice on such a frame, and the second run sees no clicks,
keys or focus changes. A frame without input builds once.
Parameters
- ui: *UI_State
- the UI to run the frame on.
- app: *$T
- your app state, passed to
build. - build: (app: *T)
- declares the widgets for the frame.
ui := headless(.{ width = 320, height = 200 });
defer free_ui(*ui);
count := 0;
build := (n: *int) {
for column(.{ gap = 8, padding = 16 }) {
label(tprint("Clicked % times", n.*));
if button("Add") n.* += 1;
}
};
frame(*ui, *count, build);
click(*ui, find_label(*ui, "Add"));
frame(*ui, *count, build);
assert(count == 1);