-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path02-toggles.raku
executable file
·55 lines (38 loc) · 1.4 KB
/
02-toggles.raku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl6
use v6;
use lib 'lib';
use GTK::Simple;
use GTK::Simple::App;
=comment
Like every GTK::Simple application, we begin by
creating a new C<GTK::Simple::App>.
my GTK::Simple::App $app .= new(title => "Toggle buttons");
=comment
This time, we create a C<GTK::Simple::Label> to display a bit of
info to the user and above and below that we create one
C<GTK::Simple::CheckButton> and a C<GTK::Simple::ToggleButton>.
$app.set-content(
GTK::Simple::VBox.new(
my $check_button = GTK::Simple::CheckButton.new(label => "check me out!"),
my $status_label = GTK::Simple::Label.new(text => "the toggles are off and off"),
my $toggle_button = GTK::Simple::ToggleButton.new(label=> "time to toggle!"),
)
);
=comment
Since the window would end up terribly tiny otherwise, we set a
quite generous inner border for the window
$app.border-width = 50;
=comment
This sub will be called whenever we toggle either of the two Buttons.
sub update_label($b) {
$status_label.text = "the toggles are " ~
($check_button, $toggle_button)>>.status.map({ <off on>[$_] }).join(" and ");
}
=comment
Now all we need to do is to connect the C<update_label> sub to the
C<toggled> supply of the buttons.
$check_button .toggled.tap: &update_label;
$toggle_button.toggled.tap: &update_label;
=comment
Finally, we let the event loop run.
$app.run;