simvx.core.ui.grid_slots¶
GridSlots: non-widget layout helper for fixed-size cell grids.
Used by ports that draw N×M slots of identical cells (You’re the OS dashboards: CPUs, idle queues, ragequit, RAM, disk; Solitaire foundation/tableau rows; Balatro hand+jokers+consumables; tactics movement-range overlays). The shape is always “compute a slot index → position” and never a hierarchical container.
GridSlots is a pure function-of-its-fields layout calculator: it owns no
nodes, queues no redraws, and never participates in input. Drop one into any
on_draw and call :meth:idx_to_xy per cell.
Example::
from simvx.core.ui import GridSlots
slots = GridSlots(rows=4, cols=8, size=(48, 48), gap=4, origin=(20, 100))
for i, item in enumerate(items):
x, y = slots.idx_to_xy(i)
renderer.draw_rect((x, y), slots.size, colour=...)
Module Contents¶
Classes¶
Fixed-size cell grid laid out row-major from |
Data¶
API¶
- simvx.core.ui.grid_slots.__all__¶
[‘GridSlots’]
- class simvx.core.ui.grid_slots.GridSlots[source]¶
Fixed-size cell grid laid out row-major from
origin.All coordinates are returned as :class:
Vec2. Layout is row-major (idx = row * cols + col); passrow_major=Falseto flip to column-major.Args: rows: Number of rows. Must be
>= 1. cols: Number of columns. Must be>= 1. size:(cell_w, cell_h)cell dimensions in pixels. gap: Pixel gutter between adjacent cells (same on both axes). origin:(x, y)top-left corner of the cell at index0. row_major: When True (default),idxincreases left-to-right then top-to-bottom; when False, top-to-bottom then left-to-right.- rows: int¶
None
- cols: int¶
None
- size: tuple[float, float]¶
(48.0, 48.0)
- gap: float¶
4.0
- origin: tuple[float, float]¶
(0.0, 0.0)
- row_major: bool¶
True
- property total_size: simvx.core.math.types.Vec2[source]¶
Outer width and height of the grid (no trailing gap).
- idx_to_rc(idx: int) tuple[int, int][source]¶
Translate a linear index into
(row, col)honouringrow_major.
- idx_to_xy(idx: int) simvx.core.math.types.Vec2[source]¶
Top-left corner of slot
idxin absolute coordinates.
- xy_to_idx(x: float, y: float) int | None[source]¶
Hit-test
(x, y); returns the slot index orNoneif outside.Points inside the gap gutter return
None.
- __iter__() Iterator[simvx.core.math.types.Vec2][source]¶
Iterate
idx_to_xyfor every slot in order.