Skip to content

Commit 834c082

Browse files
committed
toolbars: expose button widths
1 parent f832e5d commit 834c082

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

internal/df-bottom-toolbars.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ end
2121

2222
---@alias NamedWidth table<string,integer> -- single entry, value is width
2323
---@alias NamedOffsets table<string,integer> -- multiple entries, values are offsets
24+
---@alias Button { offset: integer, width: integer }
25+
---@alias NamedButtons table<string,Button> -- multiple entries
2426

2527
---@class Toolbar
26-
---@field button_offsets NamedOffsets
28+
---@field button_offsets NamedOffsets deprecated, use buttons[name].offset
29+
---@field buttons NamedButtons
2730
---@field width integer
2831

29-
---@class Toolbar.Widget.frame
32+
---@class Toolbar.Widget.frame: widgets.Widget.frame
3033
---@field l integer Gap between the left edge of the frame and the parent.
3134
---@field t integer Gap between the top edge of the frame and the parent.
3235
---@field r integer Gap between the right edge of the frame and the parent.
@@ -38,17 +41,19 @@ end
3841
---@return Toolbar
3942
local function button_widths_to_toolbar(widths)
4043
local offsets = {}
44+
local buttons = {}
4145
local offset = 0
4246
for _, ww in ipairs(widths) do
4347
local name, w = next(ww)
4448
if name then
4549
if not name:startswith('_') then
4650
offsets[name] = offset
51+
buttons[name] = { offset = offset, width = w }
4752
end
4853
offset = offset + w
4954
end
5055
end
51-
return { button_offsets = offsets, width = offset }
56+
return { button_offsets = offsets, buttons = buttons, width = offset }
5257
end
5358

5459
---@param buttons string[]
@@ -146,10 +151,10 @@ function fort.center:secondary_toolbar_frame(interface_rect, toolbar_name)
146151
tool_name = toolbar_name --[[@as CenterToolbarToolNames]]
147152
end
148153
local toolbar_offset = self:frame(interface_rect).l
149-
local toolbar_button_offset = self.button_offsets[tool_name] or dfhack.error('invalid tool name: ' .. tool_name)
154+
local toolbar_button = self.buttons[tool_name] or dfhack.error('invalid tool name: ' .. tool_name)
150155

151156
-- Ideally, the secondary toolbar is positioned directly above the (main) toolbar button
152-
local ideal_offset = toolbar_offset + toolbar_button_offset
157+
local ideal_offset = toolbar_offset + toolbar_button.offset
153158

154159
-- In "narrow" interfaces conditions, a wide secondary toolbar (pretty much
155160
-- any tool that has "advanced" options) that was ideally positioned above

0 commit comments

Comments
 (0)