Skip to content

Commit f832e5d

Browse files
committed
toolbars: (demo) show computed button positions
1 parent 0eb3df5 commit f832e5d

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

internal/df-bottom-toolbars.lua

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ end
265265
local gui = require('gui')
266266
local Panel = require('gui.widgets.containers.panel')
267267
local Label = require('gui.widgets.labels.label')
268+
local utils = require('utils')
268269
local Window = require('gui.widgets.containers.window')
269270
local Toggle = require('gui.widgets.labels.toggle_hotkey_label')
270271

@@ -294,22 +295,26 @@ local demo_panel_width = label_width + 4
294295
local demo_panel_height = 3
295296

296297
local left_toolbar_demo = ToolbarDemoPanel{
298+
frame_title = 'left toolbar',
297299
frame = { l = temp_x, t = temp_y, w = demo_panel_width, h = demo_panel_height },
298-
subviews = { Label{ frame = { xalign = 0.5, w = label_width }, text = 'left' } },
300+
subviews = { Label{ view_id = 'buttons', frame = { l = 0, r = 0 } } },
299301
}
300302
local center_toolbar_demo = ToolbarDemoPanel{
303+
frame_title = 'center toolbar',
301304
frame = { l = temp_x + demo_panel_width, t = temp_y, w = demo_panel_width, h = demo_panel_height },
302-
subviews = { Label{ frame = { xalign = 0.5, w = label_width }, text = 'center' } },
305+
subviews = { Label{ view_id = 'buttons', frame = { l = 0, r = 0 } } },
303306
}
304307
local right_toolbar_demo = ToolbarDemoPanel{
308+
frame_title = 'right toolbar',
305309
frame = { l = temp_x + 2 * demo_panel_width, t = temp_y, w = demo_panel_width, h = demo_panel_height },
306-
subviews = { Label{ frame = { xalign = 0.5, w = label_width }, text = 'right' } },
310+
subviews = { Label{ view_id = 'buttons', frame = { l = 0, r = 0 } } },
307311
}
308312
local secondary_visible = false
309313
local secondary_toolbar_demo
310314
secondary_toolbar_demo = ToolbarDemoPanel{
315+
frame_title = 'secondary toolbar',
311316
frame = { l = temp_x + demo_panel_width, t = temp_y - demo_panel_height, w = demo_panel_width, h = demo_panel_height },
312-
subviews = { Label{ frame = { xalign = 0.5, w = label_width }, text = 'secondary' } },
317+
subviews = { Label{ view_id = 'buttons', frame = { l = 0, r = 0 } } },
313318
visible = function() return visible() and secondary_visible end,
314319
}
315320

@@ -320,13 +325,27 @@ function update_demonstrations(secondary)
320325
-- [l tool] [c tool] [r tool] (bottom of UI)
321326
local toolbar_demo_dy = -TOOLBAR_HEIGHT
322327
local ir = gui.get_interface_rect()
323-
local function update(v, frame)
328+
local function update(v, frame, buttons)
324329
v.frame = {
325330
w = frame.w,
326331
h = frame.h,
327332
l = frame.l + ir.x1,
328333
t = frame.t + ir.y1 + toolbar_demo_dy,
329334
}
335+
local sorted = {}
336+
for _, offset in pairs(buttons) do
337+
utils.insert_sorted(sorted, offset)
338+
end
339+
local buttons = ''
340+
for i, o in ipairs(sorted) do
341+
if o > #buttons then
342+
buttons = buttons .. (' '):rep(o - #buttons)
343+
end
344+
buttons = buttons .. '/--\\'
345+
end
346+
v.subviews.buttons:setText(
347+
buttons:sub(2) -- the demo panel border is at offset 0, so trim first character to start at offset 1
348+
)
330349
end
331350
if secondary then
332351
-- a secondary toolbar is active, move the primary demonstration up to
@@ -335,16 +354,17 @@ function update_demonstrations(secondary)
335354
-- {s demo}
336355
-- [s tool]
337356
-- [l tool] [c tool] [r tool] (bottom of UI)
338-
update(secondary_toolbar_demo, fort.center:secondary_toolbar_frame(ir, secondary))
357+
update(secondary_toolbar_demo, fort.center:secondary_toolbar_frame(ir, secondary),
358+
fort.center.secondary_toolbars[secondary].button_offsets)
339359
secondary_visible = true
340360
toolbar_demo_dy = toolbar_demo_dy - 2 * SECONDARY_TOOLBAR_HEIGHT
341361
else
342362
secondary_visible = false
343363
end
344364

345-
update(left_toolbar_demo, fort.left:frame(ir))
346-
update(right_toolbar_demo, fort.right:frame(ir))
347-
update(center_toolbar_demo, fort.center:frame(ir))
365+
update(left_toolbar_demo, fort.left:frame(ir), fort.left.button_offsets)
366+
update(right_toolbar_demo, fort.right:frame(ir), fort.right.button_offsets)
367+
update(center_toolbar_demo, fort.center:frame(ir), fort.center.button_offsets)
348368
end
349369

350370
local tool_from_designation = {

0 commit comments

Comments
 (0)