Acme-Gtk2-Ex-Builder
view release on metacpan or search on metacpan
lib/Acme/Gtk2/Ex/Builder.pm view on Meta::CPAN
=encoding utf-8
=head1 NAME
Acme::Gtk2::Ex::Builder - Funny Gtk2 Interface Design Module
=head1 VERSION
version 0.008
=head1 SYNOPSIS
use strict;
use warnings;
use Gtk2 -init;
use Acme::Gtk2::Ex::Builder;
my $app = build {
widget Window => contain {
info id => 'window';
set title => 'Awesome App';
set default_size => 200, 100;
set position => 'center';
on delete_event => sub { Gtk2->main_quit; };
widget Button => contain {
set label => 'Action';
on clicked => sub { say 'Seoul Perl Mongers!' };
};
};
};
$app->find('window')->show_all;
Gtk2->main;
=head1 METHODS
=head2 find
Find and get widget by ID.
You can find widget only you set C<id> with C<info> function.
my $app = build {
widget Window => contain {
info id => 'my-window';
};
};
my $window = $app->find('my-window');
=head1 FUNCTIONS
=head2 build
This function acts like ordinary "new" method.
It is exported by default and returns L<Acme::Gtk2::Ex::Builder> object.
It can contains several C<widget> functions.
my $app = build {
widget Window;
widget Dialog;
widget FileChooser;
widget VBox;
};
=head2 widget
This function creates the Gtk2 widget.
In fact when you use this, C<< Gtk2::XXX->new >> will be called.
See L<Gtk2> and Gtk2 API reference.
Following code will call C<< Gtk2::Window->new >>.
my $app = build {
widget Window;
};
If you need more children widgets,
use C<contain>, then call C<widget> again and again.
my $app = build {
widget Window contain => {
widget HBox => contain {
widget Button;
widget Button;
widget Button;
};
};
};
If you have to use more parameters for constructor,
then specify additional parameters after the C<widget> block.
Following code create L<Gtk2::SimpleList> with
additional C<timestamp>, C<nick> and C<message> parameter.
See L<Gtk2> and Gtk2 API reference.
use Gtk2;
use Gtk2::SimpleList; # Do NOT forgot!!
my $app = build {
widget SimpleList => contain {
info id => 'logviewer';
set headers_visible => FALSE;
set rules_hint => TRUE;
}, (
timestamp => 'markup',
nick => 'markup',
message => 'markup',
);
};
It also supports prebuilt widget.
my $prev_button = Gtk2::Button->new('Prev');
my $next_button = Gtk2::Button->new('Next');
my $quit_button = Gtk2::Button->new;
my $app = build {
widget VBox => contain {
widget HBox => contain {
widget $prev_button;
widget $next_button;
};
widget $next_button => contain {
info packing => TRUE, TRUE, 1, 'end';
set label => 'quit';
on clicked => \&quit_clicked;
}
};
};
=head2 info
This function sets additional information.
Since it is not realted to Gtk2 functions,
attributes, signal and properties,
so save anything what you want or need.
Currently C<id> and C<packing> have some special meanings.
C<id> is used for C<widget> method to find widget.
C<packing> is used for L<Gtk2::VBox> and L<Gtk2::HBox>.
my $app = build {
widget Window => contain {
info id => 'window';
set title => 'Seoul.pm irc log viewer';
};
widget HBox => contain {
info id => 'hbox';
info packing => TRUE, TRUE, 1, 'start';
widget ScrolledWindow => contain {
set policy => 'never', 'automatic';
};
};
};
=head2 on
This function connects signals for specified widget.
Actually it is same as C<< $widget->signal_connect >>.
See L<Gtk2> and Gtk2 API reference.
my $app = build {
widget Window => contain {
on delete_event => sub { Gtk2->main_quit };
widget VBox => contain {
widget ToggleButton => contain {
set label => "show/hide";
on toggled => \&toggled;
};
widget Button => contain {
set label => 'Quit';
on clicked => sub { Gtk2->main_quit };
};
};
};
};
=head2 set
This function calls C<< $widget->set_KEY(VALUE) >> function
for specified widget.
See L<Gtk2> and Gtk2 API reference.
my $app = build {
widget Window => contain {
set title => 'Awesome App';
set default_size => 200, 100;
set position => 'center';
};
};
=head2 prop
This function sets properties for specified widget.
Actually it is same as C<< $widget->set(KEY, VALUE) >>.
See L<Gtk2> and Gtk2 API reference.
my $app = build {
widget Window => contain {
info id => 'window';
set position => 'center';
prop title => 'Window Example';
prop opacity => 0.8;
( run in 1.788 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )