UI module

key

procedureextensionexperimentalsince 0.31.0Source

Give the next widget an explicit key, for items in a list whose order changes. Without it a widget in a loop is identified by its position in the loop.

Example↗
Item :: struct { id: int; name: string; }
items := Item.[.{ 7, "seven" }, .{ 9, "nine" }];

ui := headless();
defer free_ui(*ui);
frame(*ui, *items, (list: *[2] Item) {
    for column() {
        for list.* {
            key(it.id);
            label(it.name);
        }
    }
});
assert(find_label(*ui, "nine") != null);
key :: (value: $T)

Give the next widget an explicit key, for items in a list whose order changes. Without it a widget in a loop is identified by its position in the loop.

Parameters

value: $T
anything that identifies the item and stays the same as the list changes.
Example↗
Item :: struct { id: int; name: string; }
items := Item.[.{ 7, "seven" }, .{ 9, "nine" }];

ui := headless();
defer free_ui(*ui);
frame(*ui, *items, (list: *[2] Item) {
    for column() {
        for list.* {
            key(it.id);
            label(it.name);
        }
    }
});
assert(find_label(*ui, "nine") != null);

See also