@@ -9,6 +9,7 @@ local guidm = require('gui.dwarfmode')
9
9
local utils = require (' utils' )
10
10
local widgets = require (' gui.widgets' )
11
11
local overlay = require (' plugins.overlay' )
12
+ local layout = require (' gui.dflayout' )
12
13
13
14
local function noop ()
14
15
end
@@ -399,13 +400,42 @@ end
399
400
-- MassRemoveToolbarOverlay
400
401
--
401
402
403
+ local MR_BUTTON_WIDTH = 4
404
+ local MR_BUTTON_HEIGHT = layout .SECONDARY_TOOLBAR_HEIGHT
405
+ local MR_TOOLTIP_WIDTH = 26
406
+ local MR_TOOLTIP_HEIGHT = 6
407
+ local MR_WIDTH = math.max (MR_TOOLTIP_WIDTH , MR_BUTTON_WIDTH )
408
+ local MR_HEIGHT = MR_TOOLTIP_HEIGHT + 1 --[[ empty line ]] + MR_BUTTON_HEIGHT
409
+
410
+ local erase_toolbar = layout .fort .secondary_toolbars .erase
411
+
412
+ -- one "gap column" past the right end of the erase secondary toolbar
413
+ local function mass_remove_button_offsets (interface_size )
414
+ local erase_frame = erase_toolbar .frame (interface_size )
415
+ return {
416
+ l = erase_frame .l + erase_frame .w + 1 ,
417
+ w = erase_frame .w ,
418
+ r = erase_frame .r - 1 - MR_BUTTON_WIDTH ,
419
+
420
+ t = erase_frame .t ,
421
+ h = erase_frame .h ,
422
+ b = erase_frame .b ,
423
+ }
424
+ end
425
+
426
+ -- If the overlay version is bumped, this could be changed to
427
+ -- mass_remove_button_offsets(layout.MINIMUM_INTERFACE_RECT).l
428
+ -- Adopting the calculated value would let the overlay be moved all the way to
429
+ -- the left in a minimum-size interface.
430
+ local MR_DEFAULT_L_OFFSET = 41
431
+
402
432
MassRemoveToolbarOverlay = defclass (MassRemoveToolbarOverlay , overlay .OverlayWidget )
403
433
MassRemoveToolbarOverlay .ATTRS {
404
434
desc = ' Adds a button to the erase toolbar to open the mass removal tool.' ,
405
- default_pos = {x = 42 , y =- 4 },
435
+ default_pos = {x = ( MR_DEFAULT_L_OFFSET + 1 ) , y =- ( layout . TOOLBAR_HEIGHT + 1 ) },
406
436
default_enabled = true ,
407
437
viewscreens = ' dwarfmode/Designate/ERASE' ,
408
- frame = {w = 26 , h = 10 },
438
+ frame = {w = MR_WIDTH , h = MR_HEIGHT },
409
439
}
410
440
411
441
function MassRemoveToolbarOverlay :init ()
@@ -417,7 +447,7 @@ function MassRemoveToolbarOverlay:init()
417
447
418
448
self :addviews {
419
449
widgets .Panel {
420
- frame = {t = 0 , r = 0 , w = 26 , h = 6 },
450
+ frame = {t = 0 , r = 0 , w = MR_WIDTH , h = MR_TOOLTIP_HEIGHT },
421
451
frame_style = gui .FRAME_PANEL ,
422
452
frame_background = gui .CLEAR_PEN ,
423
453
frame_inset = {l = 1 , r = 1 },
@@ -435,7 +465,7 @@ function MassRemoveToolbarOverlay:init()
435
465
},
436
466
widgets .Panel {
437
467
view_id = ' icon' ,
438
- frame = {b = 0 , r = 22 , w = 4 , h = 3 },
468
+ frame = {b = 0 , r = 0 , w = MR_WIDTH , h = MR_BUTTON_HEIGHT },
439
469
subviews = {
440
470
widgets .Label {
441
471
text = widgets .makeButtonLabelText {
@@ -469,12 +499,7 @@ function MassRemoveToolbarOverlay:init()
469
499
end
470
500
471
501
function MassRemoveToolbarOverlay :preUpdateLayout (parent_rect )
472
- local w = parent_rect .width
473
- if w <= 130 then
474
- self .frame .w = 50
475
- else
476
- self .frame .w = (parent_rect .width + 1 )// 2 - 15
477
- end
502
+ self .frame .w = MR_WIDTH + math.max (0 , mass_remove_button_offsets (parent_rect ).l - MR_DEFAULT_L_OFFSET )
478
503
end
479
504
480
505
function MassRemoveToolbarOverlay :onInput (keys )
0 commit comments