Skip to content

Commit 48571b2

Browse files
authored
Merge pull request #1363 from SquidCoderIndustries/squid-slider-widget
Added new slider widget to `devel/hello-world`
2 parents 1c1bbe1 + 44bf3c6 commit 48571b2

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Template for new versions:
4040
- `immortal-cravings`: prioritize high-value meals, properly split of portions, and don't go eating or drinking on a full stomach
4141

4242
## Misc Improvements
43+
- `devel/hello-world`: updated to show off the new Slider widget
4344

4445
## Removed
4546

devel/hello-world.lua

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ local HIGHLIGHT_PEN = dfhack.pen.parse{
1212

1313
HelloWorldWindow = defclass(HelloWorldWindow, widgets.Window)
1414
HelloWorldWindow.ATTRS{
15-
frame={w=20, h=14},
15+
frame={w=25, h=25},
1616
frame_title='Hello World',
1717
autoarrange_subviews=true,
18-
autoarrange_gap=1,
18+
autoarrange_gap=2,
19+
resizable=true,
20+
resize_min={w=25, h=25},
1921
}
2022

2123
function HelloWorldWindow:init()
24+
local LEVEL_OPTIONS = {
25+
{label='Low', value=1},
26+
{label='Medium', value=2},
27+
{label='High', value=3},
28+
{label='Pro', value=4},
29+
{label='Insane', value=5},
30+
}
31+
2232
self:addviews{
2333
widgets.Label{text={{text='Hello, world!', pen=COLOR_LIGHTGREEN}}},
2434
widgets.HotkeyLabel{
25-
frame={l=0, t=0},
35+
frame={l=0},
2636
label='Click me',
2737
key='CUSTOM_CTRL_A',
2838
on_activate=self:callback('toggleHighlight'),
@@ -32,6 +42,28 @@ function HelloWorldWindow:init()
3242
frame={w=10, h=5},
3343
frame_style=gui.INTERIOR_FRAME,
3444
},
45+
widgets.Divider{
46+
frame={h=1},
47+
frame_style_l=false,
48+
frame_style_r=false,
49+
},
50+
widgets.CycleHotkeyLabel{
51+
view_id='level',
52+
frame={l=0, w=20},
53+
label='Level:',
54+
key_back='CUSTOM_SHIFT_C',
55+
key='CUSTOM_SHIFT_V',
56+
options=LEVEL_OPTIONS,
57+
initial_option=LEVEL_OPTIONS[1].value,
58+
},
59+
widgets.Slider{
60+
frame={l=1},
61+
num_stops=#LEVEL_OPTIONS,
62+
get_idx_fn=function()
63+
return self.subviews.level:getOptionValue()
64+
end,
65+
on_change=function(idx) self.subviews.level:setOption(idx) end,
66+
},
3567
}
3668
end
3769

0 commit comments

Comments
 (0)