UI module

button

procedureextensionexperimentalsince 0.31.0Source

A push button. Returns true on the frame it was clicked (or Enter or Space pressed while focused).

Example↗
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);
button :: (
    text: string,
    options: Button_Options = .{},
    loc := #caller_location
) -> clicked: bool

A push button. Returns true on the frame it was clicked (or Enter or Space pressed while focused).

Parameters

text: string
the caption. It is copied for the frame.
options: Button_Options = .{}
look, size and whether it is enabled.
loc := #caller_location
the call site. It identifies the widget from one frame to the next, so leave the default.

Returns

clicked: bool
Example↗
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);

See also