Skip to content

Commit 1e1be64

Browse files
committed
toolbars: change interface_rect to interface_size
We only use the width and height, so hint at that in the name and type.
1 parent 9b36299 commit 1e1be64

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

internal/df-bottom-toolbars.lua

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ TOOLBAR_HEIGHT = 3
139139
SECONDARY_TOOLBAR_HEIGHT = 3
140140
MINIMUM_INTERFACE_RECT = require('gui').mkdims_wh(0, 0, 114, 46)
141141

142+
-- Only width and height are used here. We could define a new "@class", but
143+
-- LuaLS doesn't seem to accept gui.dimensions values as compatible with that
144+
-- new class...
145+
---@alias Toolbar.Rectangle.Size gui.dimension
146+
142147
---@generic T
143148
---@param sequences T[][]
144149
---@return T[]
@@ -212,15 +217,15 @@ fort.left = buttons_to_toolbar{
212217
'orders', 'nobles', 'objects', 'justice',
213218
}
214219

215-
---@param interface_rect gui.dimension
220+
---@param interface_size Toolbar.Rectangle.Size
216221
---@return Toolbar.Widget.frame
217-
function fort.left:frame(interface_rect)
222+
function fort.left:frame(interface_size)
218223
return {
219224
l = 0,
220225
w = self.width,
221-
r = interface_rect.width - self.width,
226+
r = interface_size.width - self.width,
222227

223-
t = interface_rect.height - TOOLBAR_HEIGHT,
228+
t = interface_size.height - TOOLBAR_HEIGHT,
224229
h = TOOLBAR_HEIGHT,
225230
b = 0,
226231
}
@@ -241,22 +246,22 @@ fort.center = button_widths_to_toolbar{
241246
{ _right_border = 1 },
242247
}
243248

244-
---@param interface_rect gui.dimension
249+
---@param interface_size Toolbar.Rectangle.Size
245250
---@return Toolbar.Widget.frame
246-
function fort.center:frame(interface_rect)
251+
function fort.center:frame(interface_size)
247252
-- center toolbar is "centered" in interface area, but never closer to the
248253
-- left toolbar than fort.left_center_gap_minimum
249254

250-
local interface_offset_centered = math.ceil((interface_rect.width - self.width + 1) / 2)
255+
local interface_offset_centered = math.ceil((interface_size.width - self.width + 1) / 2)
251256
local interface_offset_min = fort.left.width + fort.left_center_gap_minimum
252257
local interface_offset = math.max(interface_offset_min, interface_offset_centered)
253258

254259
return {
255260
l = interface_offset,
256261
w = self.width,
257-
r = interface_rect.width - interface_offset - self.width,
262+
r = interface_size.width - interface_offset - self.width,
258263

259-
t = interface_rect.height - TOOLBAR_HEIGHT,
264+
t = interface_size.height - TOOLBAR_HEIGHT,
260265
h = TOOLBAR_HEIGHT,
261266
b = 0,
262267
}
@@ -265,10 +270,10 @@ end
265270
---@alias CenterToolbarToolNames 'dig' | 'chop' | 'gather' | 'smooth' | 'erase' | 'build' | 'stockpile' | 'zone' | 'burrow' | 'cart' | 'traffic' | 'mass_designation'
266271
---@alias CenterToolbarSecondaryToolbarNames 'dig' | 'chop' | 'gather' | 'smooth' | 'erase' | 'stockpile' | 'stockpile_paint' | 'burrow_paint' | 'traffic' | 'mass_designation'
267272

268-
---@param interface_rect gui.dimension
273+
---@param interface_size Toolbar.Rectangle.Size
269274
---@param toolbar_name CenterToolbarSecondaryToolbarNames
270275
---@return Toolbar.Widget.frame
271-
function fort.center:secondary_toolbar_frame(interface_rect, toolbar_name)
276+
function fort.center:secondary_toolbar_frame(interface_size, toolbar_name)
272277
local secondary_toolbar = self.secondary_toolbars[toolbar_name] or
273278
dfhack.error('invalid toolbar name: ' .. toolbar_name)
274279

@@ -281,7 +286,7 @@ function fort.center:secondary_toolbar_frame(interface_rect, toolbar_name)
281286
else
282287
tool_name = toolbar_name --[[@as CenterToolbarToolNames]]
283288
end
284-
local toolbar_offset = self:frame(interface_rect).l
289+
local toolbar_offset = self:frame(interface_size).l
285290
local toolbar_button = self.buttons[tool_name] or dfhack.error('invalid tool name: ' .. tool_name)
286291

287292
-- Ideally, the secondary toolbar is positioned directly above the (main) toolbar button
@@ -295,16 +300,16 @@ function fort.center:secondary_toolbar_frame(interface_rect, toolbar_name)
295300

296301
-- padding necessary to line up width-constrained secondaries
297302
local secondary_padding = 5
298-
local width_constrained_offset = math.max(0, interface_rect.width - (secondary_toolbar.width + secondary_padding))
303+
local width_constrained_offset = math.max(0, interface_size.width - (secondary_toolbar.width + secondary_padding))
299304

300305
-- Use whichever position is left-most.
301306
local l = math.min(ideal_offset, width_constrained_offset)
302307
return {
303308
l = l,
304309
w = secondary_toolbar.width,
305-
r = interface_rect.width - l - secondary_toolbar.width,
310+
r = interface_size.width - l - secondary_toolbar.width,
306311

307-
t = interface_rect.height - TOOLBAR_HEIGHT - SECONDARY_TOOLBAR_HEIGHT,
312+
t = interface_size.height - TOOLBAR_HEIGHT - SECONDARY_TOOLBAR_HEIGHT,
308313
h = SECONDARY_TOOLBAR_HEIGHT,
309314
b = TOOLBAR_HEIGHT,
310315
}
@@ -378,15 +383,15 @@ fort.right = buttons_to_toolbar{
378383
'squads', 'world',
379384
}
380385

381-
---@param interface_rect gui.dimension
386+
---@param interface_size Toolbar.Rectangle.Size
382387
---@return Toolbar.Widget.frame
383-
function fort.right:frame(interface_rect)
388+
function fort.right:frame(interface_size)
384389
return {
385-
l = interface_rect.width - self.width,
390+
l = interface_size.width - self.width,
386391
w = self.width,
387392
r = 0,
388393

389-
t = interface_rect.height - TOOLBAR_HEIGHT,
394+
t = interface_size.height - TOOLBAR_HEIGHT,
390395
h = TOOLBAR_HEIGHT,
391396
b = 0,
392397
}

0 commit comments

Comments
 (0)