UI module

widget

procedureextensionexperimentalsince 0.31.0Source

Declare a widget: find or create its node, make it the next child of the open container and return it. This is what the library's own widgets use; a custom widget calls it too.

Example↗
ui := headless();
defer free_ui(*ui);
push_ui(*ui);
begin_frame(*ui);
node := widget(.LEAF, .CUSTOM, .{ width = 40, height = 20 }, #location());
node.label = "swatch";
end_frame(*ui);
pop_ui();
assert(node.kind == .LEAF);
widget :: (
    kind: Node_Kind,
    role: Role,
    style: Style,
    loc: Source_Code_Location
) -> *Node

Declare a widget: find or create its node, make it the next child of the open container and return it. This is what the library's own widgets use; a custom widget calls it too.

Parameters

kind: Node_Kind
whether the node is text, a leaf with a paint callback, or a container.
role: Role
what the widget is.
style: Style
layout and paint options.
loc: Source_Code_Location
the call site. It identifies the node from one frame to the next, so pass the caller's location.

Returns

Example↗
ui := headless();
defer free_ui(*ui);
push_ui(*ui);
begin_frame(*ui);
node := widget(.LEAF, .CUSTOM, .{ width = 40, height = 20 }, #location());
node.label = "swatch";
end_frame(*ui);
pop_ui();
assert(node.kind == .LEAF);

See also