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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test::More;
use Tickit::Test;
my $rootwin = mk_window;
{
my $win = $rootwin->make_sub( 3, 10, 4, 30 );
ok( !$win->scroll( 1, 0 ), '$win does not support scrolling' );
drain_termlog;
$win->close; undef $win;
flush_tickit;
}
# Scrollable window probably needs to be fullwidth
my $win = $rootwin->make_sub( 5, 0, 10, 80 );
flush_tickit;
my @exposed_rects;
$win->bind_event( expose => sub { push @exposed_rects, $_[2]->rect } );
# scroll down
{
ok( $win->scroll( 1, 0 ), 'Fullwidth $win supports vertical scrolling' );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80,1,0) ],
'Termlog after fullwidth $win->scroll downward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 9, lines => 1, left => 0, cols => 80 ) ],
'Exposed area after ->scroll downward' );
undef @exposed_rects;
}
# scroll up
{
$win->scroll( -1, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80,-1,0) ],
'Termlog after fullwidth $win->scroll upward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, lines => 1, left => 0, cols => 80 ) ],
'Exposed area after ->scroll upward' );
undef @exposed_rects;
}
# scroll right
{
ok( $win->scroll( 0, 1 ), 'Fullwidth $win supports horizontal scrolling' );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80, 0,1) ],
'Termlog after fullwidth $win->scroll rightward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, lines => 10, left => 79, cols => 1 ) ],
'Exposed area after ->scroll rightward' );
undef @exposed_rects;
}
# scroll left
{
$win->scroll( 0, -1 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80, 0,-1) ],
'Termlog after fullwidth $win->scroll leftward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, lines => 10, left => 0, cols => 1 ) ],
'Exposed area after ->scroll leftward' );
undef @exposed_rects;
}
# scrollrect up
{
ok( $win->scrollrect( Tickit::Rect->new( top => 2, left => 0, lines => 3, cols => 80 ),
-1, 0 ),
'Fullwidth $win supports scrolling a region' );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(7,0,3,80,-1,0) ],
'Termlog after fullwidth $win->scrollrect downward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 2, lines => 1, left => 0, cols => 80 ) ],
'Exposed area after ->scroll downward' );
undef @exposed_rects;
}
# scrollrect down
{
$win->scrollrect( Tickit::Rect->new( top => 2, left => 0, lines => 3, cols => 80 ),
1, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(7,0,3,80,1,0) ],
'Termlog after fullwidth $win->scrollrect upward' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 4, lines => 1, left => 0, cols => 80 ) ],
'Exposed area after ->scroll upward' );
undef @exposed_rects;
}
# scrollrect further than area just exposes
{
$win->scrollrect( Tickit::Rect->new( top => 2, left => 0, lines => 3, cols => 80 ),
5, 0 );
flush_tickit;
is_termlog( [],
'Termlog empty after scrollrect further than area' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 2, left => 0, lines => 3, cols => 80 ) ],
'Exposed area after ->scrollrect further than area' );
undef @exposed_rects;
}
# scrollrect with pending damage
{
# outside
$win->expose( Tickit::Rect->new( top => 1, left => 4, lines => 2, cols => 10 ) );
# split
$win->expose( Tickit::Rect->new( top => 3, left => 10, lines => 3, cols => 5 ) );
# inside
$win->expose( Tickit::Rect->new( top => 5, left => 20, lines => 2, cols => 10 ) );
$win->scrollrect( Tickit::Rect->new( top => 4, left => 0, lines => 6, cols => 80 ),
2, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(9,0,6,80, 2,0) ],
'Termlog after ->scrollrect with pending damage' );
is_deeply( \@exposed_rects,
[ # outside
Tickit::Rect->new( top => 1, left => 4, lines => 2, cols => 10 ),
# split part outside
Tickit::Rect->new( top => 3, left => 10, lines => 1, cols => 5 ),
# translated+truncated inside
Tickit::Rect->new( top => 4, left => 20, lines => 1, cols => 10 ),
# exposed
Tickit::Rect->new( top => 8, left => 0, lines => 2, cols => 80 ),
],
'Exposed area after ->scrollrect with pending damage' );
undef @exposed_rects;
}
# Child to obscure part of it
{
my $child = $win->make_sub( 0, 0, 3, 10 );
flush_tickit;
undef @exposed_rects;
$win->scroll( 0, 4 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,10,3,70, 0,4),
SCROLLRECT(8, 0,7,80, 0,4) ],
'Termlog after scroll with obscuring child' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, left => 76, lines => 10, cols => 4 ) ],
'Exposed area after scroll with obscuring child' );
$child->hide;
flush_tickit;
undef @exposed_rects;
$win->scroll( 0, 4 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80, 0,4) ],
'Termlog after scroll with hidden obscuring child' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, left => 76, lines => 10, cols => 4 ) ],
'Exposed area after scroll with hidden obscuring child' );
$child->close;
flush_tickit;
undef @exposed_rects;
}
# scroll_with_children up
{
my $child = $win->make_sub( 0, 70, 1, 10 );
flush_tickit;
undef @exposed_rects;
$win->scroll_with_children( -2, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80, -2,0) ],
'Termlog after ->scroll_with_children' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, left => 0, lines => 2, cols => 80 ) ],
'Exposed area after ->scroll_with_children' );
$child->close;
flush_tickit;
undef @exposed_rects;
}
# Sibling to obscure part of it
{
my $sibling = $rootwin->make_sub( 0, 0, 10, 20 );
flush_tickit;
$sibling->raise;
flush_tickit;
undef @exposed_rects;
$win->scroll_with_children( -2, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(10,0,5,80, -2,0) ],
'Termlog after ->scroll_with_children with sibling' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, left => 20, lines => 5, cols => 60 ),
Tickit::Rect->new( top => 5, left => 0, lines => 2, cols => 80 ) ],
'Exposed area after ->scroll_with_children with sibling' );
undef @exposed_rects;
# Hiding the sibling makes it ignored
$sibling->hide;
flush_tickit;
undef @exposed_rects;
$win->scroll_with_children( -2, 0 );
flush_tickit;
is_termlog( [ SETPEN,
SCROLLRECT(5,0,10,80, -2,0) ],
'Termlog after ->scroll_with_children with hidden sibling' );
is_deeply( \@exposed_rects,
[ Tickit::Rect->new( top => 0, left => 0, lines => 2, cols => 80 ) ],
'Exposed area after ->scroll_with_children with hidden sibling' );
$win->close;
$sibling->close;
flush_tickit;
}
# Hidden windows should be ignored
{
$win->hide;
flush_tickit;
$win->scroll( 2, 0 );
is_termlog( [],
'Termlog empty after ->scroll on hidden window' );
}
done_testing;
|