A declarative UI and layout submodule.
Experimental API:
The ui submodule is an experimental and new API that is highly susceptible to breaking changes in the future.
root(bounds: Rect, direction: Direction = Direction.VERTICAL, align: Align = Align.START, justify: Align = Align.START) → _RootContextroot(bounds: Rect, direction: Direction = Direction.VERTICAL, align: Align = Align.START, justify: Align = Align.START) → _RootContextCreate a root UI context for the current frame.
The root defines the available bounds for the UI tree and controls the default layout direction and alignment. Use it as a context manager.
Args
bounds : The available region for the UI.direction : The root layout direction. Defaults to Vertical.align : Cross-axis alignment for root children. Defaults to Start.justify : Main-axis justification for root children. Defaults to Start.Returns
_RootContext : A context manager that finalizes the UI when exited.
row(style: Style | None = None, gap: float = 0.0, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _Contextrow(style: Style | None = None, gap: float = 0.0, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _ContextCreate a horizontal container.
Children are laid out left to right unless the active direction or alignment settings are changed on the returned context.
Args
style : Base style for the container.gap : Space between child elements. Defaults to 0.0.padding : Inner padding of the container. Defaults to 0.0.align : Cross-axis alignment for children. Defaults to Start.justify : Main-axis justification for children. Defaults to Start.Returns
_Context : A context manager for the row.
column(style: Style | None = None, gap: float = 0.0, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _Contextcolumn(style: Style | None = None, gap: float = 0.0, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _ContextCreate a vertical container.
Children are laid out top to bottom unless alignment or spacing overrides are applied on the returned context.
Args
style : Base style for the container.gap : Space between child elements. Defaults to 0.0.padding : Inner padding of the container. Defaults to 0.0.align : Cross-axis alignment for children. Defaults to Start.justify : Main-axis justification for children. Defaults to Start.Returns
_Context : A context manager for the column.
stack(style: Style | None = None, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _Contextstack(style: Style | None = None, padding: float = 0.0, align: Align = Align.START, justify: Align = Align.START) → _ContextCreate an overlapping container.
Stack children share the same container space instead of being arranged in a linear flow.
Args
style : Base style for the container.padding : Inner padding of the container. Defaults to 0.0.align : Alignment for children inside the stack. Defaults to Start.justify : Justification for children inside the stack. Defaults to Start.Returns
_Context : A context manager for the stack.
panel(style: Style = ...) → Nonepanel(style: Style = ...) → NoneCreate a non-interactive container element.
Panels draw their background, texture, and borders using the provided style.
button(text: str, style: Style = ...) → boolbutton(text: str, style: Style = ...) → boolCreate a clickable text button.
The button is evaluated against the previous frame's bounds and returns True when it is clicked during the current frame.
Args
text : The label displayed on the button.style : Visual and layout settings for the button.Returns
bool : True if the button was clicked this frame, otherwise False.