diff --git a/init.lua b/init.lua index 67e8ca7..298495b 100644 --- a/init.lua +++ b/init.lua @@ -698,6 +698,23 @@ local ui = (function() end end + local function fire_item(it) + if item_is_disabled(it) then return false end -- absorbed, no close + if it.type == "action" then + if it.fire then it.fire() end + return true -- close menu + elseif it.type == "modal" then + if it.modal_id then state.open_modal(it.modal_id) end + return true + elseif it.type == "toggle" then + if it.fire then it.fire() end + return true + elseif it.type == "submenu" then + return false -- handled separately + end + return false + end + local function draw_menu_bar(mx, my) local screen_w = engine.window.size() engine.render.draw_rect(0, 0, screen_w, MENU_BAR_H, rgba(COL_TOOLBAR_BG, 0xFF)) @@ -1116,10 +1133,33 @@ local ui = (function() end end - -- Click anywhere outside the menu bar closes any open dropdown - if state.get_menu_open() and my >= MENU_BAR_H then + -- Dropdown items + local open_name = state.get_menu_open() + if open_name then + for _, cat in ipairs(menu_bar_categories_layout()) do + if cat.name == open_name then + local dd = dropdown_layout(cat) + if in_rect(mx, my, dd.x, dd.y, dd.w, dd.h) then + if button == "left" then + for _, row in ipairs(dd.rows) do + if in_rect(mx, my, row.x, row.y, row.w, row.h) then + if row.item.type ~= "separator" then + if fire_item(row.item) then + state.close_menu() + end + end + return true + end + end + end + return true -- empty area inside dropdown, absorbed + end + break + end + end + -- Click outside the dropdown closes it (no return — fall through so + -- the click can also hit other UI like canvas). state.close_menu() - -- Fall through (do not return) so the click can hit something else. end -- Top toolbar buttons