File: demo-tabs.pl

package info (click to toggle)
libtickit-widget-tabbed-perl 0.028-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 1,851; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download
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
#!/usr/bin/perl

use v5.26;
use warnings;

use Tickit;

use Tickit::Widget::Static;
use Tickit::Widget::Tabbed;

use Getopt::Long;
GetOptions(
        'position|p=s' => \(my $position = "bottom"),
) or exit(1);

my $tabbed = Tickit::Widget::Tabbed->new(
        tab_position => $position,
        style => {
                active_b => 1,
                active_u => 1,
        },
);

my $counter = 1;
sub add_tab
{
        $tabbed->add_tab(
                Tickit::Widget::Static->new( text => "Content for tab $counter" ),
                label => "tab$counter",
        );
        $counter++
}

add_tab for 1 .. 3;

my $tickit = Tickit->new();

$tickit->set_root_widget( $tabbed );

$tickit->bind_key(
        'C-a' => \&add_tab
);
$tickit->bind_key(
        'C-d' => sub {
                $tabbed->remove_tab( $tabbed->active_tab );
        },
);

$tickit->bind_key( 'M-Up'    => sub { $tabbed->tab_position( "top"    ) } );
$tickit->bind_key( 'M-Down'  => sub { $tabbed->tab_position( "bottom" ) } );
$tickit->bind_key( 'M-Left'  => sub { $tabbed->tab_position( "left"   ) } );
$tickit->bind_key( 'M-Right' => sub { $tabbed->tab_position( "right"  ) } );

$tickit->run;