Skip to content

GridLayout

Draggable dashboard panels with a restorable arrangement.

Native GridLayout preview

A real Linux/X11 native capture in light appearance. The same control also supports the initial dark theme.

Runnable example

import gpyui as ui

initial = [ui.GridArea("notes", col_span=6, row_span=3), ui.GridArea("status", col=6, col_span=6, row_span=2)]
notes = ui.GridItem(
    "notes",
    title="Notes",
    children=[ui.TextInput("Review Friday"), ui.Label("Drag the title to move this panel.")],
).style(padding=8)
status = ui.GridItem("status", title="Status", children=[ui.Tag("Ready", variant="success")]).style(padding=8)
control = ui.GridLayout(initial, children=[notes, status])
reset = ui.Button("Reset layout", on_click=lambda: setattr(control, "value", initial))

app = ui.Application(ui.Column([control, reset]), title="GridLayout", width=640, height=340)
app.run()

Run this in a fresh Python process on a desktop with the native build installed.

Properties

Property Default Type / accepted values Update
value [] list[GridArea or area dict] Assignment
columns 12 integer 1–64 Constructor only
row_height 2.5 0.5–64 rem Assignment
draggable true bool Assignment
resizable true bool Assignment
prevent_collision false bool Assignment
compaction "none" none · vertical · horizontal Constructor only

Accepts children=[...], a with block, and runtime add, insert, remove, clear, set_children or assignment to children. Each child has one parent. Reuse existing instances to preserve native state; see runtime composition.

Construct explicit child lists outside a composition context, as in the example. Inside a with block, construct the parent first and then its children.

All controls support visible and dispose(). Hiding or detaching retains native state; disposal permanently releases it. See Control.

Events and state

  • on_change(event): Runs after native value and Python mirror/bound State change.
  • on_select(event): Receives the selected grid item key or None.

Handlers can take zero arguments or one Event, and can be synchronous or async. They run on the owned Python asyncio loop. See events and asyncio.

bind_value(State(...)) binds both ways without echoing native edits back through setters. unbind() disposes the subscription. See state binding.

Contract and limits

Each GridItem key matches a GridArea ID. Coordinates are zero-based and row height is in rem. GridLayout.value is a JSON-compatible list of areas. Save event.value from on_change and assign it to restore the arrangement. on_select receives a key or None. An item is rendered when an area with its key exists. Unmatched areas reserve space.

All controls accept pixel layout and semantic theme styling through .style(...). Collections are copied on assignment/read: reassign them to submit updates.

Python implementation · Native builders · Full coverage and remaining Kit APIs