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
|
#!/usr/bin/perl
use v5.26;
use warnings;
use Test2::V0;
use Tickit::Test 0.12;
use Tickit::RenderBuffer;
use Tickit::Widget::Scroller::Item::Text;
my $term = mk_term;
my $item = Tickit::Widget::Scroller::Item::Text->new( "My message here" );
# margin_left
{
my $item = Tickit::Widget::Scroller::Item::Text->new( "ABCDE " x 10, margin_left => 5 );
is( $item->height_for_width( 40 ), 2, 'height_for_width 40' );
my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 40, height => 25 );
$rb->flush_to_term( $term );
is_termlog( [ GOTO(0,0),
SETPEN,
ERASECH(5,1),
SETPEN,
PRINT("ABCDE "x5 . "ABCDE"),
GOTO(1,0),
SETPEN,
ERASECH(5,1),
SETPEN,
PRINT("ABCDE "x4),
SETPEN,
ERASECH(11) ],
'Termlog for render margin_left' );
is_display( [ [TEXT(" ABCDE ABCDE ABCDE ABCDE ABCDE ABCDE")],
[TEXT(" ABCDE ABCDE ABCDE ABCDE")]],
'Display for render margin_left' );
}
# margin_right
{
my $item = Tickit::Widget::Scroller::Item::Text->new( "ABCDE " x 10, margin_right => 5 );
is( $item->height_for_width( 40 ), 2, 'height_for_width 40' );
my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 40, height => 25 );
$rb->flush_to_term( $term );
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("ABCDE "x5 . "ABCDE"),
SETPEN,
ERASECH(5),
GOTO(1,0),
SETPEN,
PRINT("ABCDE "x4),
SETPEN,
ERASECH(16) ],
'Termlog for render margin_right' );
is_display( [ [TEXT("ABCDE ABCDE ABCDE ABCDE ABCDE ABCDE")],
[TEXT("ABCDE ABCDE ABCDE ABCDE")]],
'Display for render margin_right' );
}
# margin sets both
{
my $item = Tickit::Widget::Scroller::Item::Text->new( "ABCDE " x 10, margin => 5 );
is( $item->height_for_width( 40 ), 2, 'height_for_width 40' );
my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 40, height => 25 );
$rb->flush_to_term( $term );
is_termlog( [ GOTO(0,0),
SETPEN,
ERASECH(5,1),
SETPEN,
PRINT("ABCDE "x5),
SETPEN,
ERASECH(5),
GOTO(1,0),
SETPEN,
ERASECH(5,1),
SETPEN,
PRINT("ABCDE "x5),
SETPEN,
ERASECH(5) ],
'Termlog for render margin' );
is_display( [ [TEXT(" ABCDE ABCDE ABCDE ABCDE ABCDE")],
[TEXT(" ABCDE ABCDE ABCDE ABCDE ABCDE")]],
'Display for render margin' );
}
# margin excludes pen
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "Red with green BG",
margin => 10,
pen => Tickit::Pen->new( fg => "red", bg => "green" )
);
$item->height_for_width( 80 );
my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 1 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
ERASECH(10,1),
SETPEN(fg=>1,bg=>2),
PRINT("Red with green BG"),
SETPEN(fg=>1,bg=>2),
ERASECH(43,1),
SETPEN,
ERASECH(10) ],
'Termlog for render with pen and margin' );
}
done_testing;
|