UI module

tab

procedureextensionexperimentalsince 0.31.0Source

One tab in a tab_bar, drawn selected when active.

Example↗
current := 0;
ui := headless();
defer free_ui(*ui);
build := (selected: *int) {
    for tab_bar() {
        if tab("One", selected.* == 0) == .SELECT selected.* = 0;
        if tab("Two", selected.* == 1) == .SELECT selected.* = 1;
    }
};
frame(*ui, *current, build);
click(*ui, find_label(*ui, "Two"));
frame(*ui, *current, build);
assert(current == 1);
tab :: (
    text: string,
    active: bool,
    options: Tab_Options = .{},
    loc := #caller_location
) -> Tab_Result

One tab in a tab_bar, drawn selected when active.

Parameters

text: string
the tab's title. It is copied for the frame.
active: bool
whether this is the selected tab.
options: Tab_Options = .{}
whether it shows an unsaved dot or a close button.
loc := #caller_location
the call site. It identifies the widget from one frame to the next, so leave the default.

Returns

Example↗
current := 0;
ui := headless();
defer free_ui(*ui);
build := (selected: *int) {
    for tab_bar() {
        if tab("One", selected.* == 0) == .SELECT selected.* = 0;
        if tab("Two", selected.* == 1) == .SELECT selected.* = 1;
    }
};
frame(*ui, *current, build);
click(*ui, find_label(*ui, "Two"));
frame(*ui, *current, build);
assert(current == 1);

See also