@@ -54,15 +54,12 @@ DraggablePanel.ATTRS{
54
54
draggable = true ,
55
55
drag_anchors = {frame = true , body = true },
56
56
drag_bound = ' body' ,
57
+ widget = DEFAULT_NIL ,
57
58
}
58
59
59
60
function DraggablePanel :onInput (keys )
60
- if keys ._MOUSE_L then
61
- local rect = self .frame_rect
62
- local x ,y = self :getMousePos (gui .ViewRect {rect = rect })
63
- if x then
64
- self .on_click ()
65
- end
61
+ if keys ._MOUSE_L and self :getMousePos () then
62
+ self .on_click ()
66
63
end
67
64
return DraggablePanel .super .onInput (self , keys )
68
65
end
@@ -72,16 +69,16 @@ function DraggablePanel:postUpdateLayout()
72
69
local frame = self .frame
73
70
local matcher = {t =not not frame .t , b =not not frame .b ,
74
71
l =not not frame .l , r =not not frame .r }
75
- local parent_rect , frame_rect = self .frame_parent_rect , self .frame_rect
76
- if frame_rect .y1 <= parent_rect .y1 then
77
- frame .t , frame .b = frame_rect .y1 - parent_rect .y1 , nil
78
- elseif frame_rect .y2 >= parent_rect .y2 then
79
- frame .t , frame .b = nil , parent_rect .y2 - frame_rect .y2
72
+ local parent_rect , frame_rect = self .widget . frame_parent_rect , self .frame_body
73
+ if frame_rect .y1 - 1 <= parent_rect .y1 then
74
+ frame .t , frame .b = frame_rect .y1 - parent_rect .y1 - 1 , nil
75
+ elseif frame_rect .y2 + 1 >= parent_rect .y2 then
76
+ frame .t , frame .b = nil , parent_rect .y2 - frame_rect .y2 - 1
80
77
end
81
- if frame_rect .x1 <= parent_rect .x1 then
82
- frame .l , frame .r = frame_rect .x1 - parent_rect .x1 , nil
83
- elseif frame_rect .x2 >= parent_rect .x2 then
84
- frame .l , frame .r = nil , parent_rect .x2 - frame_rect .x2
78
+ if frame_rect .x1 - 1 <= parent_rect .x1 then
79
+ frame .l , frame .r = frame_rect .x1 - parent_rect .x1 - 1 , nil
80
+ elseif frame_rect .x2 + 1 >= parent_rect .x2 then
81
+ frame .l , frame .r = nil , parent_rect .x2 - frame_rect .x2 - 1
85
82
end
86
83
self .frame_style = make_highlight_frame_style (self .frame )
87
84
if not not frame .t ~= matcher .t or not not frame .b ~= matcher .b
@@ -92,7 +89,7 @@ function DraggablePanel:postUpdateLayout()
92
89
end
93
90
94
91
function DraggablePanel :onRenderFrame (dc , rect )
95
- if self :getMousePos (gui . ViewRect { rect = self . frame_rect } ) then
92
+ if self :getMousePos () then
96
93
self .frame_background = to_pen {
97
94
ch = 32 , fg = COLOR_LIGHTGREEN , bg = COLOR_LIGHTGREEN }
98
95
else
@@ -112,6 +109,7 @@ function OverlayConfig:init()
112
109
overlay .register_trigger_lock_screen (self )
113
110
114
111
local contexts = dfhack .gui .getFocusStrings (dfhack .gui .getDFViewscreen (true ))
112
+ local interface_width_pct = df .global .init .display .max_interface_percentage
115
113
116
114
local main_panel = widgets .Window {
117
115
frame = {w = DIALOG_WIDTH , h = LIST_HEIGHT + 15 },
@@ -124,19 +122,25 @@ function OverlayConfig:init()
124
122
frame = {t = 0 , l = 0 },
125
123
text = {
126
124
' Current contexts: ' ,
127
- {text = table.concat (contexts , ' , ' ), pen = COLOR_CYAN }
125
+ {text = table.concat (contexts , ' , ' ), pen = COLOR_CYAN },
126
+ }},
127
+ widgets .Label {
128
+ frame = {t = 2 , l = 0 },
129
+ text = {
130
+ ' Interface width percent: ' ,
131
+ {text = interface_width_pct , pen = COLOR_CYAN },
128
132
}},
129
133
widgets .CycleHotkeyLabel {
130
134
view_id = ' filter' ,
131
- frame = {t = 2 , l = 0 },
135
+ frame = {t = 4 , l = 0 },
132
136
key = ' CUSTOM_CTRL_O' ,
133
- label = ' Showing: ' ,
137
+ label = ' Showing' ,
134
138
options = {{label = ' overlays for the current contexts' , value = ' cur' },
135
139
{label = ' all overlays' , value = ' all' }},
136
140
on_change = self :callback (' refresh_list' )},
137
141
widgets .FilteredList {
138
142
view_id = ' list' ,
139
- frame = {t = 4 , b = 7 },
143
+ frame = {t = 6 , b = 7 },
140
144
on_select = self :callback (' highlight_selected' ),
141
145
},
142
146
widgets .HotkeyLabel {
@@ -160,7 +164,21 @@ function OverlayConfig:init()
160
164
' to anchor the widget to that edge.' ,
161
165
},
162
166
}
163
- self :addviews {main_panel }
167
+
168
+ self :addviews {
169
+ widgets .Divider {
170
+ view_id = ' left_border' ,
171
+ frame = {l = 0 , w = 1 },
172
+ frame_style = gui .FRAME_THIN ,
173
+ },
174
+ widgets .Divider {
175
+ view_id = ' right_border' ,
176
+ frame = {r = 0 , w = 1 },
177
+ frame_style = gui .FRAME_THIN ,
178
+ },
179
+ main_panel ,
180
+ }
181
+
164
182
self :refresh_list ()
165
183
end
166
184
@@ -203,15 +221,18 @@ function OverlayConfig:refresh_list(filter)
203
221
frame_style = SHADOW_FRAME ,
204
222
on_click = make_on_click_fn (# choices + 1 ),
205
223
name = name ,
224
+ widget = widget ,
206
225
}
207
226
panel .on_drag_end = function (success )
208
227
if (success ) then
209
228
local frame = panel .frame
210
- local posx = frame .l and tostring (frame .l + 2 )
211
- or tostring (- (frame .r + 2 ))
212
- local posy = frame .t and tostring (frame .t + 2 )
213
- or tostring (- (frame .b + 2 ))
214
- overlay .overlay_command ({' position' , name , posx , posy },true )
229
+ local frame_rect = panel .frame_rect
230
+ local frame_parent_rect = panel .frame_parent_rect
231
+ local posx = frame .l and tostring (frame_rect .x1 + 2 )
232
+ or tostring (frame_rect .x2 - frame_parent_rect .width - 1 )
233
+ local posy = frame .t and tostring (frame_rect .y1 + 2 )
234
+ or tostring (frame_rect .y2 - frame_parent_rect .height - 1 )
235
+ overlay .overlay_command ({' position' , name , posx , posy }, true )
215
236
end
216
237
self .reposition_panel = nil
217
238
end
@@ -267,15 +288,27 @@ function OverlayConfig:reset()
267
288
if not obj or not obj .panel then return end
268
289
overlay .overlay_command ({' position' , obj .panel .name , ' default' }, true )
269
290
self :refresh_list (self .subviews .filter :getOptionValue ())
291
+ self :updateLayout ()
270
292
end
271
293
272
294
function OverlayConfig :onDismiss ()
273
295
view = nil
274
296
end
275
297
298
+ function OverlayConfig :preUpdateLayout (parent_rect )
299
+ local interface_rect = gui .get_interface_rect ()
300
+ local left , right = self .subviews .left_border , self .subviews .right_border
301
+ left .frame .l = interface_rect .x1 - 1
302
+ left .visible = left .frame .l >= 0
303
+ right .frame .r = nil
304
+ right .frame .l = interface_rect .x2 + 1
305
+ right .visible = right .frame .l < parent_rect .width
306
+ end
307
+
276
308
function OverlayConfig :postUpdateLayout ()
309
+ local rect = gui .ViewRect {rect = gui .get_interface_rect ()}
277
310
for _ ,choice in ipairs (self .subviews .list :getChoices ()) do
278
- choice .panel :updateLayout (choice . widget . frame_parent_rect )
311
+ choice .panel :updateLayout (rect )
279
312
end
280
313
end
281
314
@@ -304,17 +337,18 @@ function OverlayConfig:onInput(keys)
304
337
end
305
338
end
306
339
307
- function OverlayConfig :onRenderFrame (dc , rect )
340
+ function OverlayConfig :onRenderFrame ()
308
341
self :renderParent ()
342
+ local interface_area_painter = gui .Painter .new (gui .ViewRect {rect = gui .get_interface_rect ()})
309
343
for _ ,choice in ipairs (self .subviews .list :getVisibleChoices ()) do
310
344
local panel = choice .panel
311
345
if panel and panel ~= self .selected_panel then
312
- panel :render (dc )
346
+ panel :render (interface_area_painter )
313
347
end
314
348
end
315
349
if self .selected_panel then
316
350
self .render_selected_panel = function ()
317
- self .selected_panel :render (dc )
351
+ self .selected_panel :render (interface_area_painter )
318
352
end
319
353
else
320
354
self .render_selected_panel = nil
0 commit comments