From b7b0ecb9f469e6bb88d75fc0010169a7bbf35ab8 Mon Sep 17 00:00:00 2001 From: Calic Date: Sun, 14 Jun 2026 02:22:51 +0200 Subject: [PATCH] fix: support multiple bind_default_trigger calls Previously trigger_action_name + trigger_widget_id were module-local scalars, so the second bind_default_trigger call overwrote the first (and reused the action name 'panel_toggle' so lib-core.input's binding was also clobbered). Switched to a triggers array; each binding gets a unique input action 'panel_toggle_' so multiple widgets can be toggled by their own keys independently. --- README.md | 2 +- init.lua | 24 +++++++++++++++--------- manifest.lib | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 90e94e9..7acdef6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ handles input dispatch (mouse click + wheel, edge-detected), renders a titled panel overlay, and supports a context-menu layer. Designed as the glue layer between game modules and the engine render/input surfaces. -**Version:** 0.1.0 +**Version:** 0.1.1 **Lib-ID:** lib-core.panel **Requires:** engine.render.*, engine.input.*, lib-core.input (lazy, for default-trigger) **Tags:** panel, overlay, ui, input, context-menu diff --git a/init.lua b/init.lua index cf63c2d..85594da 100644 --- a/init.lua +++ b/init.lua @@ -43,8 +43,10 @@ local widgets = {} -- widget_id (string) → widget_def table local active = nil -- active widget_id or nil local theme = {} -- merged DEFAULT_THEME + overrides local ctx_menu = nil -- context-menu state table or nil -local trigger_action_name = nil -- input action name for default trigger -local trigger_widget_id = nil -- which widget_id to toggle on trigger +-- Default-trigger bindings: array of {action_name, widget_id}. Multiple +-- bind_default_trigger calls append independent entries (each widget gets +-- its own input-action so they don't clobber each other in lib-core.input). +local triggers = {} local last_mouse_left = false -- for edge-detection (was down last frame) local last_mouse_right = false -- for edge-detection (was down last frame) @@ -313,6 +315,8 @@ end --- Binds a keyboard key as the default toggle trigger for a widget. --- key defaults to "tab" when nil. Lazy-requires lib-core.input to avoid --- module-load-time circular dependency. +--- Multiple calls register independent triggers (each widget gets its own +--- input-action named "panel_toggle_" so bindings don't clobber). --- Loud-error if widget_id is not registered ("register before bind"). function M.bind_default_trigger(key, widget_id) if key == nil then key = "tab" end @@ -321,9 +325,9 @@ function M.bind_default_trigger(key, widget_id) .. "' (register before bind)") end local input = require("lib-core.input") -- lazy require: avoid load-time cycle - input.bind("panel_toggle", {key}) - trigger_action_name = "panel_toggle" - trigger_widget_id = widget_id + local action_name = "panel_toggle_" .. widget_id + input.bind(action_name, {key}) + table.insert(triggers, { action_name = action_name, widget_id = widget_id }) end -- ----------------------------------------------------------------------- @@ -384,11 +388,13 @@ end --- - Mouse edge-detection for click events (dispatches on press, not hold) --- - Mouse-wheel event dispatch function M.update(dt) - -- Check default trigger (lazy requires lib-core.input internally if bound) - if trigger_action_name then + -- Check all default triggers (lazy requires lib-core.input if any are bound) + if #triggers > 0 then local input = require("lib-core.input") - if input.was_action_pressed(trigger_action_name) then - M.toggle(trigger_widget_id) + for _, t in ipairs(triggers) do + if input.was_action_pressed(t.action_name) then + M.toggle(t.widget_id) + end end end diff --git a/manifest.lib b/manifest.lib index 596dd7e..def1ccf 100644 --- a/manifest.lib +++ b/manifest.lib @@ -1 +1 @@ -{"id":"lib-core.panel","version":"0.1.0","api_min":"0.1","deps":[]} +{"id":"lib-core.panel","version":"0.1.1","api_min":"0.1","deps":[]}