File: 03hide-show.t

package info (click to toggle)
libtickit-widget-floatbox-perl 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 346; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Identity;

use Tickit::Test;

use Tickit::Widget::FloatBox;
use Tickit::Widget::Static;

my $win = mk_window;

my $widget = Tickit::Widget::FloatBox->new
   ->set_base_child( TestWidget->new );

$widget->set_window( $win );

{
   my $float = $widget->add_float(
      child => Tickit::Widget::Static->new( text => "Hello, world!" ),
      top => 0, left => 0,
   );

   flush_tickit;

   is_display( [ [TEXT("Hello, world!"), TEXT("C" x 67)],
                 ( [TEXT("C" x 80)] ) x 24 ],
      'Display with single float' );
   ok ( $float->is_visible, '$float->is_visible true initially' );

   $float->hide;
   flush_tickit;

   is_display( [ ( [TEXT("C" x 80)] ) x 25 ],
      'Display after hiding float' );
   ok ( !$float->is_visible, '$float->is_visible false after hiding float' );

   $float->show;
   flush_tickit;

   is_display( [ [TEXT("Hello, world!"), TEXT("C" x 67)],
                 ( [TEXT("C" x 80)] ) x 24 ],
      'Display after showing float again' );

   $float->remove;
}

# initially-hidden
{
   my $float = $widget->add_float(
      child => Tickit::Widget::Static->new( text => "Hello, world!" ),
      top => 0, right => -1,
      hidden => 1,
   );

   flush_tickit;

   is_display( [ ( [TEXT("C" x 80)] ) x 25 ],
      'Display after creating initially-hidden float' );

   $float->show;
   flush_tickit;

   is_display( [ [TEXT("C" x 67), TEXT("Hello, world!")],
                 ( [TEXT("C" x 80)] ) x 24 ],
      'Display after showing float again' );

   $float->remove;
}

done_testing;

package TestWidget;

use base qw( Tickit::Widget );
use constant WIDGET_PEN_FROM_STYLE => 1;

sub render_to_rb
{
   my $self = shift;
   my ( $rb, $rect ) = @_;

   foreach my $line ( $rect->linerange ) {
      $rb->text_at( $line, $rect->left, "C" x $rb->cols );
   }
}

sub lines { 1 }
sub cols  { 1 }