Skip to content

Commit a20b509

Browse files
committed
Modernize devel/hello-world
1 parent db797cb commit a20b509

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ that repo.
2626
- Selecting all items inside a bin, minus the bin
2727
- Collapsing all bins or a single bin
2828
- Collapsing all categories
29+
-@ `devel/hello-world`: updated to use ZScreen
2930

3031
## Removed
3132

devel/hello-world.lua

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ local widgets = require('gui.widgets')
77
local HIGHLIGHT_PEN = dfhack.pen.parse{
88
ch=string.byte(' '),
99
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{
2223
widgets.Label{text={{text='Hello, world!', pen=COLOR_LIGHTGREEN}}},
2324
widgets.HotkeyLabel{
2425
frame={l=0, t=0},
@@ -32,34 +33,28 @@ function HelloWorld:init()
3233
frame_style=gui.THIN_FRAME,
3334
},
3435
}
35-
self:addviews{window}
3636
end
3737

38-
function HelloWorld:toggleHighlight()
38+
function HelloWorldWindow:toggleHighlight()
3939
local panel = self.subviews.highlight
4040
panel.frame_background = not panel.frame_background and HIGHLIGHT_PEN or nil
4141
end
4242

43-
function HelloWorld:onDismiss()
44-
view = nil
45-
end
43+
HelloWorldScreen = defclass(HelloWorldScreen, gui.ZScreen)
44+
HelloWorldScreen.ATTRS{
45+
focus_path='hello-world',
46+
}
4647

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{}}
5450
end
5551

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
5954
end
6055

6156
if dfhack_flags.module then
6257
return
6358
end
6459

65-
view = view or HelloWorld{}:show()
60+
view = view and view:raise() or HelloWorldScreen{}:show()

0 commit comments

Comments
 (0)