view release on metacpan or search on metacpan
lib/Tickit/ContainerWidget.pm view on Meta::CPAN
sub new
{
my $class = shift;
foreach my $method (qw( children )) {
$class->can( $method ) or
croak "$class cannot ->$method - do you subclass and implement it?";
}
my $self = $class->SUPER::new( @_ );
$self->{child_opts} = {};
return $self;
}
=head1 METHODS
=cut
lib/Tickit/ContainerWidget.pm view on Meta::CPAN
{
my $self = shift;
$self->reshape if $self->window;
$self->resized;
}
sub window_gained
{
my $self = shift;
$self->SUPER::window_gained( @_ );
$self->window->set_focus_child_notify( 1 );
}
sub window_lost
{
my $self = shift;
foreach my $child ( $self->children ) {
my $childwin = $child->window;
$childwin and $childwin->close;
$child->set_window( undef );
}
$self->SUPER::window_lost( @_ );
}
sub _on_win_focus
{
my $self = shift;
$self->SUPER::_on_win_focus( @_ );
$self->set_style_tag( "focus-child" => $_[1] ) if $_[2];
}
=head2 find_child
$child = $widget->find_child( $how, $other, %args )
Returns a child widget. The C<$how> argument determines how this is done,
relative to the child widget given by C<$other>:
lib/Tickit/OneLineWidget.pm view on Meta::CPAN
sub new
{
my $class = shift;
my %args = @_;
foreach my $method (qw( render_line )) {
$class->can( $method ) or
croak "$class cannot ->$method - do you subclass and implement it?";
}
my $self = $class->SUPER::new( %args );
$self->set_valign( $args{valign} || 0 );
return $self;
}
=head1 ACCESSORS
=cut
lib/Tickit/SingleChildWidget.pm view on Meta::CPAN
Constructs a new C<Tickit::SingleChildWidget> object. If passed an argument
called C<child> this will be added as the contained child widget.
=cut
sub new
{
my $class = shift;
my %args = @_;
my $self = $class->SUPER::new( %args );
$self->set_child( $args{child} ) if exists $args{child};
return $self;
}
=head1 METHODS
=cut
lib/Tickit/SingleChildWidget.pm view on Meta::CPAN
=cut
sub set_child
{
my $self = shift;
my ( $child ) = @_;
if( my $old_child = $self->child ) {
undef $self->{child};
$self->SUPER::remove( $old_child );
}
$self->{child} = $child;
if( $child ) {
$self->SUPER::add( $child );
}
}
sub add
{
my $self = shift;
croak "Already have a child; cannot add another" if $self->child;
$self->set_child( $_[0] );
}
lib/Tickit/Widget/GridBox.pm view on Meta::CPAN
=back
=cut
method add
{
my ( $row, $col, $child, %opts ) = @_;
if( my $old_child = $_grid[$row][$col] ) {
$self->SUPER::remove( $old_child );
}
$_max_col = $col if $col > $_max_col;
$_grid[$row][$col] = $child;
$self->SUPER::add( $child,
col_expand => $opts{col_expand} || 0,
row_expand => $opts{row_expand} || 0,
);
}
=head2 $gridbox->remove( $row, $col )
Removes the child widget on display in the given cell. May shrink the grid if
this was the last child widget in the given row or column.
lib/Tickit/Widget/GridBox.pm view on Meta::CPAN
$max_row = $row+1;
last;
}
splice @_grid, $max_row;
$_max_col = max map { $_ ? $#$_ : 0 } @_grid;
my $childrect = $child->window ? $child->window->rect : undef;
$self->SUPER::remove( $child );
$self->window->expose( $childrect ) if $childrect;
}
=head2 $child = $gridbox->get( $row, $col )
Returns the child widget at the given cell in the grid. If the row or column
index are beyond the bounds of the grid, or if there is no widget in the given
cell, returns C<undef>.
lib/Tickit/Widget/LinearBox.pm view on Meta::CPAN
reference or by index.
=cut
method child_opts
{
my $child = ref $_[0] ? shift : $_children[shift];
return unless $child;
return $self->SUPER::child_opts( $child );
}
=head2 $widget->set_child( $index, $child )
Replaces the child widget at the given index with the given new one;
preserving any options that are set on it.
=cut
method set_child
{
my ( $index, $child ) = @_;
my $old_child = $_children[$index];
my %opts;
if( $old_child ) {
%opts = $self->child_opts( $old_child );
dynamically $self->{suppress_redistribute} = 1;
$self->SUPER::remove( $old_child );
}
$_children[$index] = $child;
$self->SUPER::add( $child, %opts );
}
=head2 $widget->set_child_opts( $child_or_index, %newopts )
Sets new options on the given child, specified either by reference or by
index. Any options whose value is given as C<undef> are deleted.
=cut
method set_child_opts
{
my $child = ref $_[0] ? shift : $_children[shift];
return unless $child;
return $self->SUPER::set_child_opts( $child, @_ );
}
method render_to_rb
{
my ( $rb, $rect ) = @_;
$rb->eraserect( $rect );
}
=head2 $widget->add( $child, %opts )
lib/Tickit/Widget/LinearBox.pm view on Meta::CPAN
Adds the widget as a new child of this one, with the given options
=cut
method add
{
my ( $child, %opts ) = @_;
push @_children, $child;
$self->SUPER::add( $child,
expand => $opts{expand} || 0,
force_size => $opts{force_size},
);
}
=head2 $widget->remove( $child_or_index )
Removes the given child widget if present, by reference or index
=cut
method remove
{
my $index = $self->_any2index( shift );
my ( $child ) = splice @_children, $index, 1, ();
$self->SUPER::remove( $child ) if $child;
}
method reshape
{
$self->{suppress_redistribute} and return;
my $window = $self->window;
return unless $self->children;
lib/Tickit/Widget/Spinner.pm view on Meta::CPAN
=cut
method stop
{
$_running = 0;
}
method window_gained
{
$self->SUPER::window_gained( @_ );
$self->start;
}
# precache position
method reshape
{
my $win = $self->window or return;
( $_x, $_y ) = map int($_ / 2), $win->cols - $self->cols, $win->lines - $self->lines;
t/02widget-window.t view on Meta::CPAN
$rb->text_at( 0, 0, "Hello" );
}
sub lines { 1 }
sub cols { 5 }
sub window_gained
{
my $self = shift;
( $gained_window ) = @_;
$self->SUPER::window_gained( @_ );
}
sub window_lost
{
my $self = shift;
( $lost_window ) = @_;
$self->SUPER::window_lost( @_ );
}
t/03widget-container.t view on Meta::CPAN
sub cols { $cols }
package TestContainer;
use base qw( Tickit::ContainerWidget );
use constant WIDGET_PEN_FROM_STYLE => 1;
sub new
{
my $class = shift;
my $self = $class->SUPER::new( @_ );
$self->{children} = [];
return $self;
}
sub render_to_rb {}
sub lines { 2 }
sub cols { 10 }
sub children
{
my $self = shift;
return @{ $self->{children} }
}
sub add
{
my $self = shift;
my ( $child ) = @_;
push @{ $self->{children} }, $child;
$self->SUPER::add( @_ );
}
sub remove
{
my $self = shift;
my ( $child ) = @_;
@{ $self->{children} } = grep { $_ != $child } @{ $self->{children} };
$self->SUPER::remove( @_ );
}
sub child_resized { $resized++ }
sub children_changed { $changed++ }
t/05widget-focus.t view on Meta::CPAN
sub render_to_rb {}
sub lines { 1 }
sub cols { 1 }
sub window_gained
{
my $self = shift;
my ( $win ) = @_;
$self->SUPER::window_gained( @_ );
$win->cursor_at( 0, 2 );
}
t/06widget-input.t view on Meta::CPAN
sub lines { 1 }
sub cols { 1 }
sub render_to_rb {}
sub window_gained
{
my $self = shift;
my ( $win ) = @_;
$self->SUPER::window_gained( $win );
$win->cursor_at( 0, 0 );
}
use constant KEYPRESSES_FROM_STYLE => 1;
BEGIN {
style_definition base =>
'<Enter>' => 'do_thing';
}