@@ -7,18 +7,19 @@ local widgets = require('gui.widgets')
7
7
local HIGHLIGHT_PEN = dfhack .pen .parse {
8
8
ch = string.byte (' ' ),
9
9
fg = COLOR_LIGHTGREEN ,
10
- bg = COLOR_LIGHTGREEN }
11
-
12
- HelloWorld = defclass (HelloWorld , gui .Screen )
13
-
14
- function HelloWorld :init ()
15
- local window = widgets .Window {
16
- frame = {w = 20 , h = 14 },
17
- frame_title = ' Hello World' ,
18
- autoarrange_subviews = true ,
19
- autoarrange_gap = 1 ,
20
- }
21
- window :addviews {
10
+ bg = COLOR_LIGHTGREEN ,
11
+ }
12
+
13
+ HelloWorldWindow = defclass (HelloWorldWindow , widgets .Window )
14
+ HelloWorldWindow .ATTRS {
15
+ frame = {w = 20 , h = 14 },
16
+ frame_title = ' Hello World' ,
17
+ autoarrange_subviews = true ,
18
+ autoarrange_gap = 1 ,
19
+ }
20
+
21
+ function HelloWorldWindow :init ()
22
+ self :addviews {
22
23
widgets .Label {text = {{text = ' Hello, world!' , pen = COLOR_LIGHTGREEN }}},
23
24
widgets .HotkeyLabel {
24
25
frame = {l = 0 , t = 0 },
@@ -32,34 +33,28 @@ function HelloWorld:init()
32
33
frame_style = gui .THIN_FRAME ,
33
34
},
34
35
}
35
- self :addviews {window }
36
36
end
37
37
38
- function HelloWorld :toggleHighlight ()
38
+ function HelloWorldWindow :toggleHighlight ()
39
39
local panel = self .subviews .highlight
40
40
panel .frame_background = not panel .frame_background and HIGHLIGHT_PEN or nil
41
41
end
42
42
43
- function HelloWorld :onDismiss ()
44
- view = nil
45
- end
43
+ HelloWorldScreen = defclass (HelloWorldScreen , gui .ZScreen )
44
+ HelloWorldScreen .ATTRS {
45
+ focus_path = ' hello-world' ,
46
+ }
46
47
47
- function HelloWorld :onInput (keys )
48
- if self :inputToSubviews (keys ) then
49
- return true
50
- elseif keys .LEAVESCREEN or keys .SELECT then
51
- self :dismiss ()
52
- return true
53
- end
48
+ function HelloWorldScreen :init ()
49
+ self :addviews {HelloWorldWindow {}}
54
50
end
55
51
56
- function HelloWorld :onRenderFrame (dc , rect )
57
- -- since we're not taking up the entire screen
58
- self :renderParent ()
52
+ function HelloWorldScreen :onDismiss ()
53
+ view = nil
59
54
end
60
55
61
56
if dfhack_flags .module then
62
57
return
63
58
end
64
59
65
- view = view or HelloWorld {}:show ()
60
+ view = view and view : raise () or HelloWorldScreen {}:show ()
0 commit comments