feat(map-editor): menu-bar top-level labels render + click

Adds the seven category labels (File, Edit, View, Map, Tools,
Window, Help) at the top of the screen with hover highlight and
click-to-open / click-to-close behaviour. Item arrays are still
empty stubs; dropdown rendering lands in the next slice.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Calic
2026-06-01 19:47:11 +02:00
parent 1a9daa8ce1
commit 2eebd3d2d5

View File

@@ -445,6 +445,25 @@ local ui = (function()
"topsurface", "surface", "subsurface", "foundation",
}
-- Item-array stubs for the dropdown system. Filled in T9.
local FILE_ITEMS = {}
local EDIT_ITEMS = {}
local VIEW_ITEMS = {}
local MAP_ITEMS = {}
local TOOLS_ITEMS = {}
local WINDOW_ITEMS = {}
local HELP_ITEMS = {}
local MENU_CATEGORIES = {
{ name = "File", items = FILE_ITEMS },
{ name = "Edit", items = EDIT_ITEMS },
{ name = "View", items = VIEW_ITEMS },
{ name = "Map", items = MAP_ITEMS },
{ name = "Tools", items = TOOLS_ITEMS },
{ name = "Window", items = WINDOW_ITEMS },
{ name = "Help", items = HELP_ITEMS },
}
-- Top-toolbar buttons (left-to-right). Action ids dispatched in
-- handle_click; hotkey labels rendered on the button face.
local TOOLBAR_BUTTONS = {
@@ -570,6 +589,45 @@ local ui = (function()
end
end
-- Returns the hit-rect table for each menu-bar category label.
-- Uses engine.render.measure_text (exposed in P.3.4).
local function menu_bar_categories_layout()
local out = {}
local x = MENU_LABEL_PAD_X
local font_size = 12
for _, cat in ipairs(MENU_CATEGORIES) do
local label_w = engine.render.measure_text(cat.name, font_size)
local hit_w = label_w + MENU_LABEL_PAD_X * 2
out[#out + 1] = {
name = cat.name,
items = cat.items,
x = x,
y = 0,
w = hit_w,
h = MENU_BAR_H,
label_x = x + MENU_LABEL_PAD_X,
}
x = x + hit_w
end
return out
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))
local open = state.get_menu_open()
for _, cat in ipairs(menu_bar_categories_layout()) do
local hovered = in_rect(mx, my, cat.x, cat.y, cat.w, cat.h)
local active = (open == cat.name)
if active or hovered then
engine.render.draw_rect(cat.x, cat.y, cat.w, cat.h,
rgba(active and COL_BUTTON_BG_ACTIVE or COL_BUTTON_BG_HOVER, 0xFF))
end
local fg = active and COL_TEXT_ACTIVE or COL_TEXT
engine.render.draw_text(cat.name, cat.label_x, 5, 12, rgba(fg, 0xFF))
end
end
local function side_panel_layout()
local screen_w, screen_h = engine.window.size()
return {
@@ -825,6 +883,7 @@ local ui = (function()
function M.draw()
local mx, my = engine.input.get_mouse_pos()
draw_menu_bar(mx, my)
draw_top_toolbar(mx, my)
draw_mode_pill()
draw_side_panel(mx, my)
@@ -948,6 +1007,26 @@ local ui = (function()
end
end
-- Menu bar top-level labels
for _, cat in ipairs(menu_bar_categories_layout()) do
if in_rect(mx, my, cat.x, cat.y, cat.w, cat.h) then
if button == "left" then
if state.get_menu_open() == cat.name then
state.close_menu()
else
state.set_menu_open(cat.name)
end
end
return true
end
end
-- Click anywhere outside the menu bar closes any open dropdown
if state.get_menu_open() and my >= MENU_BAR_H then
state.close_menu()
-- Fall through (do not return) so the click can hit something else.
end
-- Top toolbar buttons
for _, b in ipairs(toolbar_buttons_layout()) do
if in_rect(mx, my, b.x, b.y, b.w, b.h) then