Skip to content

Commit 86ef030

Browse files
authored
Port 'Spin Button' demo to Vala (#171)
1 parent 51e5765 commit 86ef030

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/Spin Button/main.vala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! /usr/bin/env -S vala workbench.vala --pkg libadwaita-1
2+
3+
private Gtk.SpinButton hours;
4+
private Gtk.SpinButton minutes;
5+
6+
string tell_time () {
7+
return (@"The time selected is $(hours.text):$(minutes.text)");
8+
}
9+
10+
public void main () {
11+
hours = (Gtk.SpinButton) workbench.builder.get_object ("hours");
12+
minutes = (Gtk.SpinButton) workbench.builder.get_object ("minutes");
13+
14+
hours.text = "00";
15+
minutes.text = "00";
16+
17+
hours.value_changed.connect (() => {
18+
message (@"$(tell_time ())");
19+
});
20+
21+
minutes.value_changed.connect (() => {
22+
message (@"$(tell_time ())");
23+
});
24+
25+
26+
hours.output.connect (() => {
27+
var value = (int) hours.adjustment.value;
28+
hours.text = "%02d".printf (value);
29+
return true;
30+
});
31+
32+
minutes.output.connect (() => {
33+
var value = (int) minutes.adjustment.value;
34+
minutes.text = "%02d".printf (value);
35+
return true;
36+
});
37+
38+
// This only works for one direction
39+
// Add any extra logic to account for wrapping in both directions
40+
minutes.wrapped.connect (() => {
41+
hours.spin (STEP_FORWARD, 1);
42+
});
43+
}

0 commit comments

Comments
 (0)