@@ -9,6 +9,7 @@ local guidm = require('gui.dwarfmode')
99local utils = require (' utils' )
1010local widgets = require (' gui.widgets' )
1111local overlay = require (' plugins.overlay' )
12+ local layout = require (' gui.dflayout' )
1213
1314local function noop ()
1415end
@@ -399,13 +400,42 @@ end
399400-- MassRemoveToolbarOverlay
400401--
401402
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+
402432MassRemoveToolbarOverlay = defclass (MassRemoveToolbarOverlay , overlay .OverlayWidget )
403433MassRemoveToolbarOverlay .ATTRS {
404434 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 ) },
406436 default_enabled = true ,
407437 viewscreens = ' dwarfmode/Designate/ERASE' ,
408- frame = {w = 26 , h = 10 },
438+ frame = {w = MR_WIDTH , h = MR_HEIGHT },
409439}
410440
411441function MassRemoveToolbarOverlay :init ()
@@ -417,7 +447,7 @@ function MassRemoveToolbarOverlay:init()
417447
418448 self :addviews {
419449 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 },
421451 frame_style = gui .FRAME_PANEL ,
422452 frame_background = gui .CLEAR_PEN ,
423453 frame_inset = {l = 1 , r = 1 },
@@ -435,7 +465,7 @@ function MassRemoveToolbarOverlay:init()
435465 },
436466 widgets .Panel {
437467 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 },
439469 subviews = {
440470 widgets .Label {
441471 text = widgets .makeButtonLabelText {
@@ -469,12 +499,7 @@ function MassRemoveToolbarOverlay:init()
469499end
470500
471501function 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 )
478503end
479504
480505function MassRemoveToolbarOverlay :onInput (keys )
0 commit comments