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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Test::More;
use Tickit::Test;
use Tickit::Widget::ScrollBox;
my $win = mk_window;
my ( $vextent, $hextent );
my ( $downward, $rightward ) = (0) x 2;
{
package ScrollableWidget;
use base qw( Tickit::Widget );
use constant CAN_SCROLL => 1;
use constant WIDGET_PEN_FROM_STYLE => 1;
sub lines { 1 }
sub cols { 1 }
sub set_scrolling_extents
{
shift;
( $vextent, $hextent ) = @_;
$vextent->set_total( 100 );
$hextent->set_total( 50 )
}
sub scrolled
{
shift;
$downward += $_[0];
$rightward += $_[1];
}
sub render_to_rb {}
}
my $child = ScrollableWidget->new;
my $widget = Tickit::Widget::ScrollBox->new(
horizontal => 1,
vertical => 1,
)->set_child( $child );
$widget->set_window( $win );
flush_tickit;
ok( defined $vextent, '$vextent set' );
ok( defined $hextent, '$hextent set' );
ok( defined $child->window, '$child has window after $widget->set_window' );
is( $child->window->top, 0, '$child window starts on line 0' );
is( $child->window->left, 0, '$child window starts on column 0' );
is( $child->window->lines, 25, '$child given 25 line window' );
is( $child->window->cols, 79, '$child given 79 column window' );
is_display( [ [ BLANK(79), TEXT(" ",rv=>1)],
([BLANK(79), TEXT(" ",bg=>4)]) x 6,
([BLANK(79), TEXT("║",fg=>4)]) x 17,
[ BLANK(79), TEXT("▾",rv=>1)] ],
'Display initially' );
$widget->scroll( +10 );
flush_tickit;
is( $downward, 10, '$child informed of scroll +10' );
$downward = 0;
is( $child->window->top, 0, '$child window still starts on line 0 after scroll +10' );
$widget->scroll_to( 25 );
flush_tickit;
is( $downward, 15, '$child informed of scroll_to 25' );
is( $child->window->top, 0, '$child window still starts on line 0 after scroll_to 25' );
is_display( [ [ BLANK(79), TEXT("▴",rv=>1)],
([BLANK(79), TEXT("║",fg=>4)]) x 6,
([BLANK(79), TEXT(" ",bg=>4)]) x 6,
([BLANK(79), TEXT("║",fg=>4)]) x 11,
[ BLANK(79), TEXT("▾",rv=>1)] ],
'Display after scrolls' );
$vextent->set_total( 50 );
flush_tickit;
is_display( [ [ BLANK(79), TEXT("▴",rv=>1)],
([BLANK(79), TEXT("║",fg=>4)]) x 12,
([BLANK(79), TEXT(" ",bg=>4)]) x 11,
[ BLANK(79), TEXT(" ",rv=>1)] ],
'Display after ->set_total 50' );
done_testing;
|