@@ -3,8 +3,6 @@ local layout = require('gui.dflayout')
3
3
local widgets = require (' gui.widgets' )
4
4
local utils = require (' utils' )
5
5
6
- --- Demo Control Window and Screen ---
7
-
8
6
--- @class Demo
9
7
--- @field text string text displayed in main window demo list
10
8
--- @field available fun (): boolean ? return true if demo is available in current context
@@ -21,107 +19,6 @@ local function demos_are_visible()
21
19
return screen :isActive () and screen :hasFocus ()
22
20
end
23
21
24
- DemoWindow = defclass (DemoWindow , widgets .Window )
25
- DemoWindow .ATTRS {
26
- frame_title = ' dflayout demos' ,
27
- frame = { w = 39 , h = 9 },
28
- resizable = true ,
29
- autoarrange_subviews = true ,
30
- autoarrange_gap = 1 ,
31
- }
32
-
33
- --- @param args { demos : Demo[] }
34
- function DemoWindow :init (args )
35
- self .demos = args .demos
36
- self :addviews {
37
- widgets .ToggleHotkeyLabel {
38
- label = ' Demos visible when not focused?' ,
39
- initial_option = visible_when_not_focused ,
40
- on_change = function (new , old )
41
- visible_when_not_focused = new
42
- end
43
- },
44
- widgets .List {
45
- view_id = ' list' ,
46
- frame = { h = 10 , },
47
- icon_pen = COLOR_GREY ,
48
- icon_width = 3 ,
49
- on_submit = function (index , item )
50
- local demo = self .demos [index ]
51
- demo .active = demo .available () and not demo .active
52
- if demo .active then demo .update () end
53
- self :refresh ()
54
- end
55
- },
56
- }
57
- end
58
-
59
- local CHECK = string.char (251 ) -- U+221A SQUARE ROOT
60
-
61
- function DemoWindow :refresh ()
62
- local choices = {}
63
- for _ , demo in ipairs (self .demos ) do
64
- local icon
65
- if not demo .available () then
66
- icon = ' -'
67
- elseif demo .active then
68
- icon = CHECK
69
- end
70
- table.insert (choices , {
71
- text = demo .text ,
72
- icon = icon ,
73
- })
74
- end
75
- self .subviews .list :setChoices (choices )
76
- return self
77
- end
78
-
79
- DemoScreen = defclass (DemoScreen , gui .ZScreen )
80
- DemoScreen .ATTRS {
81
- focus_path = ' gui.dflayout-demo'
82
- }
83
-
84
- function DemoScreen :init (args )
85
- self .demos = args .demos
86
- local function demo_views ()
87
- local views = {}
88
- for _ , demo in ipairs (self .demos ) do
89
- if demo .views then
90
- table.move (demo .views , 1 , # demo .views , # views + 1 , views )
91
- end
92
- end
93
- return views
94
- end
95
- self :addviews {
96
- DemoWindow { demos = self .demos }:refresh (),
97
- table.unpack (demo_views ())
98
- }
99
- end
100
-
101
- function DemoScreen :onDismiss ()
102
- screen = nil
103
- end
104
-
105
- local if_percentage
106
- function DemoScreen :render (...)
107
- if demos_are_visible () then
108
- local new_if_percentage = df .global .init .display .max_interface_percentage
109
- if new_if_percentage ~= if_percentage then
110
- if_percentage = new_if_percentage
111
- self :updateLayout ()
112
- end
113
- end
114
- return DemoScreen .super .render (self , ... )
115
- end
116
-
117
- function DemoScreen :postComputeFrame (frame_body )
118
- for _ , demo in ipairs (self .demos ) do
119
- if demo .available () and demo .active then
120
- demo .update ()
121
- end
122
- end
123
- end
124
-
125
22
--- Fort Toolbar Demo ---
126
23
127
24
--- @class FortToolbarsDemo : Demo
@@ -387,7 +284,108 @@ function center_toolbar_demo:render(...)
387
284
return center_render (self , ... )
388
285
end
389
286
390
- --- start demo control window ---
287
+ --- Demo Control Window and Screen ---
288
+
289
+ DemoWindow = defclass (DemoWindow , widgets .Window )
290
+ DemoWindow .ATTRS {
291
+ frame_title = ' dflayout demos' ,
292
+ frame = { w = 39 , h = 9 },
293
+ resizable = true ,
294
+ autoarrange_subviews = true ,
295
+ autoarrange_gap = 1 ,
296
+ }
297
+
298
+ --- @param args { demos : Demo[] }
299
+ function DemoWindow :init (args )
300
+ self .demos = args .demos
301
+ self :addviews {
302
+ widgets .ToggleHotkeyLabel {
303
+ label = ' Demos visible when not focused?' ,
304
+ initial_option = visible_when_not_focused ,
305
+ on_change = function (new , old )
306
+ visible_when_not_focused = new
307
+ end
308
+ },
309
+ widgets .List {
310
+ view_id = ' list' ,
311
+ frame = { h = 10 , },
312
+ icon_pen = COLOR_GREY ,
313
+ icon_width = 3 ,
314
+ on_submit = function (index , item )
315
+ local demo = self .demos [index ]
316
+ demo .active = demo .available () and not demo .active
317
+ if demo .active then demo .update () end
318
+ self :refresh ()
319
+ end
320
+ },
321
+ }
322
+ end
323
+
324
+ local CHECK = string.char (251 ) -- U+221A SQUARE ROOT
325
+
326
+ function DemoWindow :refresh ()
327
+ local choices = {}
328
+ for _ , demo in ipairs (self .demos ) do
329
+ local icon
330
+ if not demo .available () then
331
+ icon = ' -'
332
+ elseif demo .active then
333
+ icon = CHECK
334
+ end
335
+ table.insert (choices , {
336
+ text = demo .text ,
337
+ icon = icon ,
338
+ })
339
+ end
340
+ self .subviews .list :setChoices (choices )
341
+ return self
342
+ end
343
+
344
+ DemoScreen = defclass (DemoScreen , gui .ZScreen )
345
+ DemoScreen .ATTRS {
346
+ focus_path = ' gui.dflayout-demo'
347
+ }
348
+
349
+ function DemoScreen :init (args )
350
+ self .demos = args .demos
351
+ local function demo_views ()
352
+ local views = {}
353
+ for _ , demo in ipairs (self .demos ) do
354
+ if demo .views then
355
+ table.move (demo .views , 1 , # demo .views , # views + 1 , views )
356
+ end
357
+ end
358
+ return views
359
+ end
360
+ self :addviews {
361
+ DemoWindow { demos = self .demos }:refresh (),
362
+ table.unpack (demo_views ())
363
+ }
364
+ end
365
+
366
+ function DemoScreen :onDismiss ()
367
+ screen = nil
368
+ end
369
+
370
+ local if_percentage
371
+ function DemoScreen :render (...)
372
+ if demos_are_visible () then
373
+ local new_if_percentage = df .global .init .display .max_interface_percentage
374
+ if new_if_percentage ~= if_percentage then
375
+ if_percentage = new_if_percentage
376
+ self :updateLayout ()
377
+ end
378
+ end
379
+ return DemoScreen .super .render (self , ... )
380
+ end
381
+
382
+ function DemoScreen :postComputeFrame (frame_body )
383
+ for _ , demo in ipairs (self .demos ) do
384
+ if demo .available () and demo .active then
385
+ demo .update ()
386
+ end
387
+ end
388
+ end
391
389
392
390
screen = screen and screen :raise () or DemoScreen {
393
391
demos = {
0 commit comments