|
21 | 21 |
|
22 | 22 | ---@alias NamedWidth table<string,integer> -- single entry, value is width |
23 | 23 | ---@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 |
24 | 26 |
|
25 | 27 | ---@class Toolbar |
26 | | ----@field button_offsets NamedOffsets |
| 28 | +---@field button_offsets NamedOffsets deprecated, use buttons[name].offset |
| 29 | +---@field buttons NamedButtons |
27 | 30 | ---@field width integer |
28 | 31 |
|
29 | | ----@class Toolbar.Widget.frame |
| 32 | +---@class Toolbar.Widget.frame: widgets.Widget.frame |
30 | 33 | ---@field l integer Gap between the left edge of the frame and the parent. |
31 | 34 | ---@field t integer Gap between the top edge of the frame and the parent. |
32 | 35 | ---@field r integer Gap between the right edge of the frame and the parent. |
|
38 | 41 | ---@return Toolbar |
39 | 42 | local function button_widths_to_toolbar(widths) |
40 | 43 | local offsets = {} |
| 44 | + local buttons = {} |
41 | 45 | local offset = 0 |
42 | 46 | for _, ww in ipairs(widths) do |
43 | 47 | local name, w = next(ww) |
44 | 48 | if name then |
45 | 49 | if not name:startswith('_') then |
46 | 50 | offsets[name] = offset |
| 51 | + buttons[name] = { offset = offset, width = w } |
47 | 52 | end |
48 | 53 | offset = offset + w |
49 | 54 | end |
50 | 55 | end |
51 | | - return { button_offsets = offsets, width = offset } |
| 56 | + return { button_offsets = offsets, buttons = buttons, width = offset } |
52 | 57 | end |
53 | 58 |
|
54 | 59 | ---@param buttons string[] |
@@ -146,10 +151,10 @@ function fort.center:secondary_toolbar_frame(interface_rect, toolbar_name) |
146 | 151 | tool_name = toolbar_name --[[@as CenterToolbarToolNames]] |
147 | 152 | end |
148 | 153 | 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) |
150 | 155 |
|
151 | 156 | -- 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 |
153 | 158 |
|
154 | 159 | -- In "narrow" interfaces conditions, a wide secondary toolbar (pretty much |
155 | 160 | -- any tool that has "advanced" options) that was ideally positioned above |
|
0 commit comments