Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

hotbar

Game-HUD hotbar. Composes an hbox of per-slot buttons with overlaid count + slot-index labels, highlighting the slot indicated by selectedSlot. Clicking a slot fires the callback <opts.id or "hotbar">-<index>. The caller is the source of truth for the selection (controlled-component pattern).

Exports

  • hotbar(slots: {Slot}, selectedSlot: number?, opts: HotbarOpts?) -> WidgetNode — module returns the builder function directly.

Per-slot shape:

  • Slot = { icon: string?, count: number?, tooltip: string? }

Options:

  • id: string? — callback prefix. Default "hotbar".
  • style: table? — hbox style. Default { gap = 4 }.

Usage

local Z = require("@builtin::modules.zui")

Z.hotbar(state.slots, state.selectedSlot, { id = "hotbar" })

-- Pattern-match the per-slot callbacks:
app:on("^hotbar%-(%d+)$", function(_, _, idx)
    state.selectedSlot = tonumber(idx)
end)

Notes

  • Slot indices start at 1.
  • Empty slots (or nil) renders an empty hbox.
  • The widget is stateless — the parent app owns selection state.
  • Each button's id is <prefix>-slot-<i>; the click callback is <prefix>-<i> (note: different separator pattern by design).