Handle-Registry + Click/Drag-Box State-Machine + Selection-Set-API + alpha-tinted render-helpers. Release-edge detection internal via prev_click_down (no was_action_released in lib-core.input). See: meta/docs/superpowers/specs/2026-05-14-p3-6-lib-selection-design.md
46 lines
1.6 KiB
Markdown
46 lines
1.6 KiB
Markdown
# lib-core.selection — v0.1.0
|
|
|
|
Click-Select + Drag-Box-Select + Selection-Set-State.
|
|
|
|
## Quick Setup
|
|
|
|
```lua
|
|
local selection = require("lib-core.selection")
|
|
local input = require("lib-core.input")
|
|
|
|
input.bind("lmb", { "mouse_left" })
|
|
input.bind("mod_add", { "shift" })
|
|
input.bind("mod_toggle", { "ctrl" })
|
|
|
|
selection.bind_action("lmb")
|
|
selection.bind_modifier_add("mod_add")
|
|
selection.bind_modifier_toggle("mod_toggle")
|
|
|
|
local handle = selection.register(function()
|
|
return { x = entity.x, y = entity.y, w = entity.w, h = entity.h }
|
|
end)
|
|
|
|
-- per-frame:
|
|
function update(ctx, dt) selection.update(dt) end
|
|
function render(ctx)
|
|
camera.begin()
|
|
-- entities…
|
|
selection.render_highlights() -- world-space
|
|
camera.finish()
|
|
selection.render_drag_box() -- screen-space
|
|
end
|
|
```
|
|
|
|
## API
|
|
|
|
- Registry: `register(aabb_fn) → handle`, `unregister(h)`, `count_registered()`
|
|
- Set-Query: `list()`, `count()`, `contains(h)`, `is_empty()`
|
|
- Set-Mutation: `add(h)`, `remove(h)`, `toggle(h)`, `clear()`
|
|
- Bindings: `bind_action(name)`, `bind_modifier_add(name)`, `bind_modifier_toggle(name)`
|
|
- State-Config: `set_drag_threshold(px)` / `drag_threshold()`, `set_enabled(bool)` / `enabled()`
|
|
- State-Query: `drag_state() → "idle"|"ambiguous"|"dragging"`, `box_rect() → {x,y,w,h}|nil`
|
|
- Visual: `set_drag_box_color(r,g,b,a)` / `drag_box_color()`, `set_highlight_color(r,g,b,a)` / `highlight_color()`
|
|
- Per-Frame: `update(dt)`, `render_drag_box()`, `render_highlights()`
|
|
|
|
See `meta/docs/superpowers/specs/2026-05-14-p3-6-lib-selection-design.md` for full design.
|