-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path01-hello-world.raku
executable file
·73 lines (49 loc) · 1.93 KB
/
01-hello-world.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env perl6
use v6;
use lib 'lib';
use GTK::Simple;
use GTK::Simple::App;
=comment
Using C<GTK::Simple> allows you to get a U<single window> for your app
by creating a B<GTK::Simple::App>.
my GTK::Simple::App $app .= new(title => "Hello GTK!");
=begin comment
Anything that does the C<GTK::Simple::Container> role, like
C<GTK::Simple::App> for example, lets you use B<set-content>
to put widgets into its body.
In other GTK tutorials, you'll find that you have to C<gtk-widget-show>
all widgets as well as the window. set-content does all of that for us.
=end comment
$app.set-content(
GTK::Simple::VBox.new(
my $button = GTK::Simple::Button.new(label => "Hello World!"),
my $second = GTK::Simple::Button.new(label => "Goodbye!")
)
);
=comment
Note the use of U<in-line declarations> of local variables for the Buttons.
This lets us refer to the buttons again later on, but not have to refer to
them twice in a row.
=comment
Setting the C<border-width> of any C<GTK::Simple::Container> adds
a B<border around the container>.
C<border-width> on a window, however, is special-cased to put
a border U<inside> the window instead.
$app.border-width = 20;
=comment
Using the sensitive property we can make a button unclickable.
$second.sensitive = False;
=begin comment
The B<clicked> member exposes activation events as a C<Supply> that we
can tap. That C<Supply> will C<more> the Button object every time the
button is activated.
Therefore we can set the button that was just clicked inactive with
just C<.sensitive = 0>. The C<$second> button can then be activated.
=end comment
$button.clicked.tap({ .sensitive = False; $second.sensitive = True });
=comment
Clicking the second button shall C<exit> the application's main loop.
$second.clicked.tap({ $app.exit; });
=comment
Finally, we enter the main loop of the application.
$app.run;