Alt-Tickit-Widgets-ObjectPad

 view release on metacpan or  search on metacpan

examples/demo-gridbox.pl  view on Meta::CPAN

   },
);

foreach my $row ( 0 .. 9 ) {
   foreach my $col ( 0 .. 5 ) {
      $gridbox->add( $row, $col, Tickit::Widget::Static->new(
            text => chr( 65 + rand 26 ) x ( 2 + rand 12 ),
            align => 0.5, valign => 0.5,
            bg => (qw( red blue green yellow ))[($row+$col) % 4],
      ),
         row_expand => 1,
         col_expand => 1,
      );
   }
}

Tickit->new( root => $gridbox )->run;

examples/demo-hbox.pl  view on Meta::CPAN

      spacing => 1,
   },
);

foreach ( 1 .. 6 ) {
   $hbox->add(
      Tickit::Widget::Static->new(
         text => "$_", bg => $_, fg => "hi-white",
         align => "centre", valign => "middle",
      ),
      expand => 1,
   )
}

Tickit->new( root => $hbox )->run;

examples/demo-spinner.pl  view on Meta::CPAN


use Tickit;
use Tickit::Widgets qw( Spinner Button HBox VBox );

my $vbox = Tickit::Widget::VBox->new;

$vbox->add( my $spinner = Tickit::Widget::Spinner->new(
      chars => [ map { substr( "-=X=-     -=X=-", 9-$_, 10 ) } 0 .. 9 ],
      interval => 0.1,
   ),
   expand => 3,
);

$vbox->add( my $hbox = Tickit::Widget::HBox->new,
   expand => 1,
);

$hbox->add(
   Tickit::Widget::Button->new( label => "Start", on_click => sub { $spinner->start } ),
   expand => 1
);
$hbox->add(
   Tickit::Widget::Button->new( label => "Stop",  on_click => sub { $spinner->stop  } ),
   expand => 1,
);

Tickit->new( root => $vbox )->run;

examples/demo-vbox.pl  view on Meta::CPAN

      spacing => 1,
   },
);

foreach ( 1 .. 6 ) {
   $vbox->add(
      Tickit::Widget::Static->new(
         text => "Row $_", bg => $_, fg => "hi-white",
         align => "centre", valign => "middle",
      ),
      expand => 1,
   )
}

Tickit->new( root => $vbox )->run;

examples/focus.pl  view on Meta::CPAN


my $gridbox = Tickit::Widget::GridBox->new(
   style => {
      row_spacing => 1,
      col_spacing => 2,
   },
);

foreach my $row ( 0 .. 2 ) {
   $gridbox->add( $row, 0, Tickit::Widget::Static->new( text => "Entry $row" ) );
   $gridbox->add( $row, 1, Tickit::Widget::Entry->new, col_expand => 1 );
}

{
   $gridbox->add( 3, 0, Tickit::Widget::Static->new( text => "Buttons" ) );
   $gridbox->add( 3, 1, Tickit::Widget::Frame->new(
      child => my $hbox = Tickit::Widget::HBox->new( spacing => 2 ),
   ) );

   foreach my $label (qw( One Two Three )) {
      $hbox->add( Tickit::Widget::Button->new( label => $label, on_click => sub {} ), expand => 1 );
   }
}

{
   $gridbox->add( 4, 0, Tickit::Widget::Static->new( text => "Checks" ) );
   $gridbox->add( 4, 1, Tickit::Widget::Frame->new(
      child => my $hbox = Tickit::Widget::HBox->new( spacing => 2 ),
   ) );

   foreach ( 0 .. 2 ) {

lib/Tickit/Widget/GridBox.pm  view on Meta::CPAN

}

method colcount
{
   return $_max_col + 1;
}

=head2 $gridbox->add( $row, $col, $child, %opts )

Sets the child widget to display in the given grid cell. Cells do not need to
be explicitly constructed; the grid will automatically expand to the size
required. This method can also be used to replace an existing child at the
given cell location. To remove a cell entirely, use the C<remove> method.

The following options are recognised:

=over 8

=item col_expand => INT

=item row_expand => INT

Values for the C<expand> setting for this column or row of the table. The
largest C<expand> setting for any cell in a given column or row sets the value
used to distribute space to that column or row.

=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.

=cut

lib/Tickit/Widget/GridBox.pm  view on Meta::CPAN


   my $max_row = $self->rowcount - 1;
   my $max_col = $self->colcount - 1;

   my ( $row_spacing, $col_spacing ) = $self->get_style_values(qw( row_spacing col_spacing ));

   foreach my $row ( 0 .. $max_row ) {
      push @row_buckets, { fixed => $row_spacing } if @row_buckets;

      my $base = 0;
      my $expand = 0;

      foreach my $col ( 0 .. $max_col ) {
         my $child = $_grid[$row][$col] or next;

         $base   = max $base, $child->requested_lines;
         $expand = max $expand, $self->child_opts( $child )->{row_expand};
      }

      push @row_buckets, {
         row    => $row,
         base   => $base,
         expand => $expand,
      };
   }

   foreach my $col ( 0 .. $max_col ) {
      push @col_buckets, { fixed => $col_spacing } if @col_buckets;

      my $base = 0;
      my $expand = 0;

      foreach my $row ( 0 .. $max_row ) {
         my $child = $_grid[$row][$col] or next;

         $base   = max $base, $child->requested_cols;
         $expand = max $expand, $self->child_opts( $child )->{col_expand};
      }

      push @col_buckets, {
         col    => $col,
         base   => $base,
         expand => $expand,
      };
   }

   distribute( $win->lines, @row_buckets );
   distribute( $win->cols,  @col_buckets );

   my @rows;
   foreach ( @row_buckets ) {
      $rows[$_->{row}] = [ $_->{start}, $_->{value} ] if defined $_->{row};
   }

lib/Tickit/Widget/HBox.pm  view on Meta::CPAN


 my $hbox = Tickit::Widget::HBox->new;

 foreach my $position (qw( left centre right )) {
    $hbox->add(
       Tickit::Widget::Static->new(
          text   => $position,
          align  => $position,
          valign => "middle",
       ),
       expand => 1
    );
 }

 Tickit->new( root => $hbox )->run;

=head1 DESCRIPTION

This subclass of L<Tickit::Widget::LinearBox> distributes its children in a
horizontal row. Its height will be the height of the tallest child, and its
width will be the sum of the widths of all the children, plus the inter-child

lib/Tickit/Widget/LinearBox.pm  view on Meta::CPAN

=head1 DESCRIPTION

This class is a base class for both L<Tickit::Widget::HBox> and
L<Tickit::Widget::VBox>. It is not intended to be used directly.

It maintains an ordered list of child widgets, and implements the following
child widget options:

=over 8

=item expand => NUM

A number used to control how extra space is distributed among child widgets,
if the window containing this widget has more space available to it than the
children need. The actual value is unimportant, but extra space will be
distributed among the children in proportion with their C<expand> value.

For example, if all the children have a C<expand> value of 1, extra space is
distributed evenly. If one child has a value of 2, it will gain twice as much
extra space as its siblings. Any child with a value of 0 will obtain no extra
space.

=item force_size => NUM

If provided, forces the size of this child widget, overriding the value
returned by C<get_child_base>.

=back

lib/Tickit/Widget/LinearBox.pm  view on Meta::CPAN


=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

lib/Tickit/Widget/LinearBox.pm  view on Meta::CPAN

         fixed => $spacing,
      } if @buckets; # gap

      my $base = defined $opts{force_size} ? $opts{force_size}
                                           : $self->get_child_base( $child );
      warn "Child $child did not define a base size for $self\n", $base = 0
         unless defined $base;

      push @buckets, {
         base   => $base,
         expand => $opts{expand},
         child  => $child,
      };
   }

   distribute( $self->get_total_quota( $window ), @buckets );

   foreach my $b ( @buckets ) {
      my $child = $b->{child} or next;

      $self->set_child_window( $child, $b->{start}, $b->{value}, $window );

lib/Tickit/Widget/VBox.pm  view on Meta::CPAN


 my $vbox = Tickit::Widget::VBox->new;

 foreach my $position (qw( top middle bottom )) {
    $vbox->add(
       Tickit::Widget::Static->new(
          text   => $position,
          align  => "centre",
          valign => $position,
       ),
       expand => 1
    );
 }

 Tickit->new( root => $vbox )->run;

=head1 DESCRIPTION

This subclass of L<Tickit::Widget::LinearBox> distributes its children in a
vertical column. Its width will be the width of the widest child, and its
height will be the sum of the heights of all the children, plus the

t/33hbox.t  view on Meta::CPAN


flush_tickit;

is_display( [ [TEXT("Widget 0"),
               BLANK(2),
               TEXT("Widget 1"),
               BLANK(2),
               TEXT("Widget 2")] ],
            'Display initially' );

$widget->set_child_opts( 1, expand => 1 );

flush_tickit;

is_display( [ [TEXT("Widget 0"),
               BLANK(2),
               TEXT("Widget 1"),
               BLANK(54),
               TEXT("Widget 2")] ],
            'Display after expand change' );

$statics[0]->set_text( "A longer piece of text for the static" );

flush_tickit;

is_display( [ [TEXT("A longer piece of text for the static"),
               BLANK(2),
               TEXT("Widget 1"),
               BLANK(25),
               TEXT("Widget 2")] ],

t/33vbox.t  view on Meta::CPAN

is( "".$statics[1]->window, 'Tickit::Window[80x1 abs@0,1]', '$statics[1] has correct window' );
is( "".$statics[2]->window, 'Tickit::Window[80x1 abs@0,2]', '$statics[2] has correct window' );

flush_tickit;

is_display( [ [TEXT("Widget 0")],
              [TEXT("Widget 1")],
              [TEXT("Widget 2")] ],
            'Display initially' );

$widget->set_child_opts( 1, expand => 1 );

flush_tickit;

is_display( [ [TEXT("Widget 0")],
              [TEXT("Widget 1")],
              BLANKLINES(22),
              [TEXT("Widget 2")] ],
            'Display after expand change' );

$statics[0]->set_text( "A longer piece of text for the static" );

flush_tickit;

is_display( [ [TEXT("A longer piece of text for the static")],
              [TEXT("Widget 1")],
              BLANKLINES(22),
              [TEXT("Widget 2")] ],
            'Display after static text change' );

t/34gridbox.t  view on Meta::CPAN

use Tickit::Widget::GridBox;

my $win = mk_window;

my @statics = map { Tickit::Widget::Static->new( text => "Widget $_" ) } 0 .. 5;

my $widget = Tickit::Widget::GridBox->new;

ok( defined $widget, 'defined $widget' );

$widget->add( 0, 0, $statics[0], col_expand => 1, row_expand => 1 );
$widget->add( 0, 1, $statics[1], col_expand => 1, row_expand => 1 );
$widget->add( 1, 0, $statics[2], col_expand => 1, row_expand => 1 );
$widget->add( 1, 1, $statics[3], col_expand => 1, row_expand => 1 );

is( $widget->lines, 2, '$widget->lines after ->add' );
is( $widget->cols, 16, '$widget->cols after ->add' );

is( $widget->rowcount, 2, '$widget->rowcount' );
is( $widget->colcount, 2, '$widget->colcount' );

identical( $widget->get( 0, 0 ), $statics[0], '->get( 0, 0 )' );
identical( $widget->get( 1, 1 ), $statics[3], '->get( 1, 1 )' );

t/34gridbox.t  view on Meta::CPAN

);

flush_tickit;

is_display( [ [TEXT("Widget 0"), BLANK(27+10), TEXT("Widget 1"), BLANK(27)],
              BLANKLINES(10+3),
              [TEXT("Widget 2"), BLANK(27+10), TEXT("Widget 3"), BLANK(27)],
              BLANKLINES(10) ],
            'Display after changing spacing' );

$widget->add( 0, 2, $statics[4] ); # no expand
$widget->add( 1, 2, $statics[5] ); # no expand

is( $widget->colcount, 3, '$widget->colcount after adding column' );

flush_tickit;

is_display( [ [TEXT("Widget 0"), BLANK(18+10), TEXT("Widget 1"), BLANK(18+10), TEXT("Widget 4")],
              BLANKLINES(10+3),
              [TEXT("Widget 2"), BLANK(18+10), TEXT("Widget 3"), BLANK(18+10), TEXT("Widget 5")],
              BLANKLINES(10) ],
            'Display after adding more cells without expand' );

$widget->remove( 1, 1 );

flush_tickit;

is_display( [ [TEXT("Widget 0"), BLANK(18+10), TEXT("Widget 1"), BLANK(18+10), TEXT("Widget 4")],
              BLANKLINES(10+3),
              [TEXT("Widget 2"), BLANK(18+10), BLANK(8), BLANK(18+10), TEXT("Widget 5")],
              BLANKLINES(10) ],
            'Display after removing a cell' );



( run in 1.267 second using v1.01-cache-2.11-cpan-5623c5533a1 )