libui.node — Node Base & Build Infrastructure

Node base class and build infrastructure for the declarative UI layer.

class libui.node.BuildContext(window=None)

Bases: object

Carries shared state during the build phase.

class libui.node.Node(**kwargs)

Bases: object

Base descriptor for a UI element. Lightweight — does not create widgets.

Subclasses override create_widget() and optionally attach_children().

create_widget(ctx: BuildContext) Any
build(ctx: BuildContext) Any

Materialise the widget tree rooted at this node.

bind_props(widget: Any) None

Bind State/Computed props to widget attributes.

attach_callbacks(widget: Any) None

Register event callbacks on the widget.

attach_children(widget: Any, ctx: BuildContext) None

Override to add children to the widget.

libui.node.make_two_way(node: Node, widget, prop: str, state: State, event: str, user_cb=None, _wrap_cb: bool = True) None

Set up two-way binding between a State and a widget property.

State -> widget: subscribe to state changes and set widget prop. Widget -> state: register the widget event callback to push into state. The reentrancy guard in State.set() prevents cycles.

If user_cb is provided it is called with the current value after the State has been updated.

libui.node.stretchy(node: Node) Node

Mark a node as stretchy in a Box layout.