refactor(map-editor): retire legacy toolbar

Removes the eight-button top toolbar, its layout helpers, click
dispatcher and all TOOLBAR_* constants. Side-panel and palette
offsets now anchor to MENU_BAR_H. Mode-pill no longer overlaps a
parallel toolbar element.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Calic
2026-06-01 20:07:57 +02:00
parent 107eade2fa
commit 1945e91441

117
init.lua
View File

@@ -374,7 +374,7 @@ local ui = (function()
-- ===================================================================== -- =====================================================================
-- Layout constants -- Layout constants
-- ===================================================================== -- =====================================================================
-- Menu bar (replaces TOOLBAR_H block in v0.3.0) -- Menu bar
local MENU_BAR_H = 24 local MENU_BAR_H = 24
local MENU_LABEL_PAD_X = 12 local MENU_LABEL_PAD_X = 12
local MODE_PILL_W = 130 local MODE_PILL_W = 130
@@ -391,13 +391,6 @@ local ui = (function()
local DROPDOWN_MIN_W = 180 local DROPDOWN_MIN_W = 180
local DROPDOWN_PAD_X = 10 local DROPDOWN_PAD_X = 10
-- Top toolbar (full-width, mode-switch + action buttons)
local TOOLBAR_H = 32
local TOOLBAR_BUTTON_W = 88
local TOOLBAR_BUTTON_H = 24
local TOOLBAR_BUTTON_GAP = 6
local TOOLBAR_PADDING = 4
-- Side panel (right edge, layers vis + active) -- Side panel (right edge, layers vis + active)
local SIDE_PANEL_W = 160 local SIDE_PANEL_W = 160
local LAYER_ROW_H = 22 local LAYER_ROW_H = 22
@@ -592,19 +585,6 @@ local ui = (function()
{ name = "Help", items = HELP_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 = {
{ id="mode_auto", label="Auto-Tile", hotkey="Tab", group="mode" },
{ id="mode_direct", label="Direct", hotkey="Tab", group="mode" },
{ id="save", label="Save", hotkey="S" },
{ id="erase", label="Erase", hotkey="E" },
{ id="rotate", label="Rotate", hotkey="R" },
{ id="flip", label="Flip", hotkey="H" },
{ id="reset_xform", label="Reset", hotkey="0" },
{ id="help", label="Help", hotkey="I" },
}
-- Cheatsheet content (rendered into the modal). -- Cheatsheet content (rendered into the modal).
local CHEATSHEET = { local CHEATSHEET = {
{ key="Tab", action="Toggle mode (Auto-Tile / Direct)" }, { key="Tab", action="Toggle mode (Auto-Tile / Direct)" },
@@ -667,30 +647,6 @@ local ui = (function()
-- resize robustness — engine.window.size() is cheap). -- resize robustness — engine.window.size() is cheap).
-- ===================================================================== -- =====================================================================
local function toolbar_layout()
local screen_w = engine.window.size()
return { x = 0, y = 0, w = screen_w, h = TOOLBAR_H }
end
-- Returns array of { id, label, hotkey, group, x, y, w, h } for each
-- toolbar button, packed left-to-right within the toolbar rect.
local function toolbar_buttons_layout()
local out = {}
local x = TOOLBAR_PADDING
local y = (TOOLBAR_H - TOOLBAR_BUTTON_H) / 2
for i, b in ipairs(TOOLBAR_BUTTONS) do
out[i] = {
id = b.id,
label = b.label,
hotkey = b.hotkey,
group = b.group,
x = x, y = y, w = TOOLBAR_BUTTON_W, h = TOOLBAR_BUTTON_H,
}
x = x + TOOLBAR_BUTTON_W + TOOLBAR_BUTTON_GAP
end
return out
end
-- 0.3.0: Mode-pill anchored to the right end of the menu bar. -- 0.3.0: Mode-pill anchored to the right end of the menu bar.
local function mode_pill_layout() local function mode_pill_layout()
local screen_w = engine.window.size() local screen_w = engine.window.size()
@@ -894,9 +850,9 @@ local ui = (function()
local screen_w, screen_h = engine.window.size() local screen_w, screen_h = engine.window.size()
return { return {
x = screen_w - SIDE_PANEL_W, x = screen_w - SIDE_PANEL_W,
y = TOOLBAR_H, y = MENU_BAR_H,
w = SIDE_PANEL_W, w = SIDE_PANEL_W,
h = screen_h - TOOLBAR_H - PALETTE_H, h = screen_h - MENU_BAR_H - PALETTE_H,
} }
end end
@@ -1125,47 +1081,6 @@ local ui = (function()
-- Drawing -- Drawing
-- ===================================================================== -- =====================================================================
-- Decide whether a toolbar button is in the "active" highlighted
-- state — only mode-group buttons match the current mode.
local function button_is_active(b)
if b.group ~= "mode" then return false end
if b.id == "mode_auto" and state.get_mode() == "auto-tile" then return true end
if b.id == "mode_direct" and state.get_mode() == "direct" then return true end
return false
end
local function draw_button(b, mx, my)
local is_active = button_is_active(b)
local is_hover = in_rect(mx, my, b.x, b.y, b.w, b.h)
local bg = is_active and COL_BUTTON_BG_ACTIVE
or is_hover and COL_BUTTON_BG_HOVER
or COL_BUTTON_BG
local text_col = is_active and COL_TEXT_ACTIVE or COL_TEXT
engine.render.draw_rect(b.x, b.y, b.w, b.h, rgba(bg, 0xFF))
if is_active then
engine.render.draw_rect_lines(b.x, b.y, b.w, b.h, rgba(COL_BUTTON_BORDER, 0xFF))
end
engine.render.draw_text(b.label, b.x + 6, b.y + 4, 12, rgba(text_col, 0xFF))
if b.hotkey then
engine.render.draw_text("(" .. b.hotkey .. ")", b.x + 6, b.y + 14, 9,
rgba(text_col, 0xC0))
end
end
local function draw_top_toolbar(mx, my)
local t = toolbar_layout()
engine.render.draw_rect(t.x, t.y, t.w, t.h, rgba(COL_TOOLBAR_BG, 0xFF))
for _, b in ipairs(toolbar_buttons_layout()) do
draw_button(b, mx, my)
end
-- Mode + active-layer label in the toolbar's right area
local label = string.format("Mode: %s Layer: %s",
state.get_mode(), state.get_active_layer())
local screen_w = engine.window.size()
engine.render.draw_text(label, screen_w - SIDE_PANEL_W - 240, 10, 12,
rgba(COL_TEXT_MUTED, 0xFF))
end
local function draw_side_panel(mx, my) local function draw_side_panel(mx, my)
local p = side_panel_layout() local p = side_panel_layout()
engine.render.draw_rect(p.x, p.y, p.w, p.h, rgba(COL_PANEL_BG, 0xFF)) engine.render.draw_rect(p.x, p.y, p.w, p.h, rgba(COL_PANEL_BG, 0xFF))
@@ -1278,7 +1193,6 @@ local ui = (function()
end end
end end
end end
draw_top_toolbar(mx, my)
draw_mode_pill() draw_mode_pill()
if state.is_layers_panel_shown() then if state.is_layers_panel_shown() then
draw_side_panel(mx, my) draw_side_panel(mx, my)
@@ -1371,21 +1285,6 @@ local ui = (function()
end end
end end
-- Dispatch a toolbar-button click to the appropriate action.
local function dispatch_toolbar_button(id)
if id == "mode_auto" then actions.set_mode("auto-tile")
elseif id == "mode_direct" then actions.set_mode("direct")
elseif id == "save" then actions.save()
elseif id == "erase" then
local cell = state.get_mouse_cell()
if cell then actions.erase_cell_at(cell.x, cell.y) end
elseif id == "rotate" then actions.cycle_rotation()
elseif id == "flip" then actions.toggle_flip()
elseif id == "reset_xform" then actions.reset_transform()
elseif id == "help" then actions.open_cheatsheet()
end
end
-- Hit-test mouse click. Returns true if the click was consumed by UI. -- Hit-test mouse click. Returns true if the click was consumed by UI.
-- button: "left" | "right" -- button: "left" | "right"
function M.handle_click(mx, my, button) function M.handle_click(mx, my, button)
@@ -1483,16 +1382,6 @@ local ui = (function()
state.close_menu() state.close_menu()
end 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
if button == "left" then
dispatch_toolbar_button(b.id)
end
return true
end
end
-- Bottom palette swatches: left = select slot -- Bottom palette swatches: left = select slot
if state.is_palette_shown() then if state.is_palette_shown() then
for _, sw in ipairs(palette_swatches_layout()) do for _, sw in ipairs(palette_swatches_layout()) do