Axel Meyer bd43f2659d fix(selection): sync prev_click_down before early returns
Previously, set_enabled(false) caused prev_click_down to drift, so a
click that spanned a disable/enable window would be silently dropped.
Move release-edge sync above early returns; handle click_action==nil
guard inline so is_action_down isn't called with nil.
2026-05-14 15:06:46 +02:00

lib-core.selection — v0.1.0

Click-Select + Drag-Box-Select + Selection-Set-State.

Quick Setup

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.

Description
P.3.6 lib-core.selection v0.1.0 � Handle-Registry + Click/Drag-Box State-Machine + Selection-Set-API
Readme 43 KiB
Languages
Lua 96.3%
Shell 3.7%