Skip to content

Commit

Permalink
lots of comments for the second example
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed May 24, 2014
1 parent 3993435 commit df0b11c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/02_toggles.pm6
@@ -1,7 +1,16 @@
use GTK::Simple;

=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!"),
Expand All @@ -10,16 +19,33 @@ $app.set_content(
)
);

=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 eases stringification of the toggle status a bit.

enum ToggleState <off on>;

=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({ ToggleState $_ }).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;

0 comments on commit df0b11c

Please sign in to comment.