Tickit-Widget-Tabbed-0.026/0000755000175000017500000000000014200222124013455 5ustar leoleoTickit-Widget-Tabbed-0.026/README0000644000175000017500000000045714200221670014350 0ustar leoleo This archive contains the distribution Tickit-Widget-Tabbed, version 0.001: Basic tabbed window support This software is copyright (c) 2011 by Tom Molesworth. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Tickit-Widget-Tabbed-0.026/lib/0000755000175000017500000000000014200222124014223 5ustar leoleoTickit-Widget-Tabbed-0.026/lib/Tickit/0000755000175000017500000000000014200222124015452 5ustar leoleoTickit-Widget-Tabbed-0.026/lib/Tickit/Widget/0000755000175000017500000000000014200222124016675 5ustar leoleoTickit-Widget-Tabbed-0.026/lib/Tickit/Widget/Tabbed.pm0000644000175000017500000003365514200222067020436 0ustar leoleo# You may distribute under the terms of the Artistic License (the same terms # as Perl itself) # # (C) Tom Molesworth 2011, # Paul Evans, 2011-2015 -- leonerd@leonerd.org.uk use v5.26; use Object::Pad 0.57; package Tickit::Widget::Tabbed 0.026; class Tickit::Widget::Tabbed :isa(Tickit::ContainerWidget); Tickit::Widget->VERSION("0.12"); Tickit::Window->VERSION("0.23"); use Tickit::Style; use constant KEYPRESSES_FROM_STYLE => 1; use Carp; use Tickit::Pen; use List::Util qw(max); use Tickit::Widget::Tabbed::Ribbon; =head1 NAME Tickit::Widget::Tabbed - provide tabbed window support =head1 SYNOPSIS use Tickit::Widget::Tabbed; my $tabbed = Tickit::Widget::Tabbed->new; $tabbed->add_tab(Tickit::Widget::Static->new(text => 'some text'), label => 'First tab'); $tabbed->add_tab(Tickit::Widget::Static->new(text => 'some text'), label => 'Second tab'); =head1 DESCRIPTION Provides a container that operates as a tabbed window. Subclass of L. =cut =head1 STYLE The default style pen is used as the widget pen. The following style pen prefixes are also used: =over 4 =item ribbon => PEN The pen used for the ribbon =item active => PEN The pen attributes used for the active tab on the ribbon =item more => PEN The pen used for "more" ribbon scroll markers =back The following style keys are used: =over 4 =item more_left => STRING =item more_right => STRING The text used to indicate that there is more content scrolled to the left or right, respectively, in the ribbon =back =cut style_definition base => ribbon_fg => 7, ribbon_bg => 4, active_fg => 14, more_fg => "cyan", more_left => "<..", more_right => "..>", '' => "next_tab", '' => "prev_tab", '' => "next_tab", '' => "prev_tab"; use constant WIDGET_PEN_FROM_STYLE => 1; =head1 METHODS =cut =head2 new Instantiate a new tabbed window. Takes the following named parameters: =over 4 =item * tab_position - (optional) location of the tabs, should be one of left, top, right, bottom. =back =cut has $_tab_class :param = undef; method TAB_CLASS { $_tab_class || "Tickit::Widget::Tabbed::Tab" } has $_ribbon_class :param = undef; method RIBBON_CLASS { $_ribbon_class || "Tickit::Widget::Tabbed::Ribbon" } has $_ribbon :reader; has @_child_window_geometry; ADJUSTPARAMS ( $params ) { $self->tab_position(delete($params->{tab_position}) || 'top'); # sets $_ribbon $_ribbon->set_style( $self->get_style_pen("ribbon")->getattrs ); } # Positions for the four screen edges - these will return appropriate sizes # for the tab and child subwindows method _window_position_left () { my $label_width = $_ribbon->cols; return 0, 0, $self->window->lines, $label_width, 0, $label_width, $self->window->lines, $self->window->cols - $label_width; } method _window_position_right () { my $label_width = $_ribbon->cols; return 0, $self->window->cols - $label_width, $self->window->lines, $label_width, 0, 0, $self->window->lines, $self->window->cols - $label_width; } method _window_position_top () { my $label_height = $_ribbon->lines; $label_height = 1 unless $self->window->lines > $label_height; return 0, 0, $label_height, $self->window->cols, $label_height, 0, max(1, $self->window->lines - $label_height), $self->window->cols; } method _window_position_bottom () { my $label_height = $_ribbon->lines; $label_height = 1 unless $self->window->lines > $label_height; return $self->window->lines - $label_height, 0, $label_height, $self->window->cols, 0, 0, max(1, $self->window->lines - $label_height), $self->window->cols; } method on_style_changed_values (%values) { if( grep { $_ =~ m/^ribbon_/ } keys %values ) { $_ribbon->set_style( $self->get_style_pen("ribbon")->getattrs ); } } method reshape () { my $window = $self->window or return; my $tab_position = $self->tab_position; my @positions = $self->${\"_window_position_$tab_position"}(); if( my $ribbon_window = $_ribbon->window ) { $ribbon_window->change_geometry( @positions[0..3] ); } else { my $ribbon_window = $window->make_sub( @positions[0..3] ); $_ribbon->set_window( $ribbon_window ); } @_child_window_geometry = @positions[4..7]; foreach my $tab ( $_ribbon->tabs ) { my $child = $tab->widget; if( my $child_window = $child->window ) { $child_window->change_geometry( @positions[4..7] ); } else { $child_window = $self->_new_child_window( $child == $self->active_tab->widget ); $child->set_window($child_window); } } } method _max_child_lines () { return max( 1, map { $_->widget->requested_lines } $_ribbon->tabs ); } method _max_child_cols () { return max( 1, map { $_->widget->requested_cols } $_ribbon->tabs ); } method lines () { if( $_ribbon->orientation eq "horizontal" ) { return $_ribbon->lines + $self->_max_child_lines; } else { return max( $_ribbon->lines, $self->_max_child_lines ); } } method cols () { if( $_ribbon->orientation eq "horizontal" ) { return max( $_ribbon->cols, $self->_max_child_cols ); } else { return $_ribbon->cols + $self->_max_child_cols; } } # All the child widgets method children () { return $_ribbon, map { $_->widget } $_ribbon->tabs; } # The only focusable child widget is the active one method children_for_focus () { return $self->active_tab_widget; } method _new_child_window ( $visible ) { my $window = $self->window or return undef; my $child_window = $window->make_hidden_sub( @_child_window_geometry ); $child_window->show if $visible; return $child_window; } method window_lost ( $win ) { $self->SUPER::window_lost( $win ); $_->widget->set_window(undef) for $_ribbon->tabs; undef @_child_window_geometry; $_ribbon->set_window(undef); } =head2 tab_position Accessor for the tab position (top, left, right, bottom). =cut has $_tab_position; method tab_position ( $pos = return $_tab_position ) { my $orientation = ( $pos eq "top" or $pos eq "bottom" ) ? "horizontal" : ( $pos eq "left" or $pos eq "right" ) ? "vertical" : croak "Unrecognised value for ->tab_position: $pos"; if( !$_ribbon or $_ribbon->orientation ne $orientation ) { my %args = ( tabbed => $self, tab_position => $pos, ); if( my $old_ribbon = $_ribbon ) { $old_ribbon->window->close; $old_ribbon->set_window( undef ); $args{tabs} = [ $old_ribbon->tabs ]; $args{active_tab_index} = $old_ribbon->active_tab_index; $args{pen} = $old_ribbon->pen; $args{active_pen} = $old_ribbon->active_pen; undef $_ribbon; } $_ribbon = $self->RIBBON_CLASS->new_for_orientation( $orientation, %args ); $_ribbon->set_style( $args{pen}->getattrs ) if $args{pen}; } $_tab_position = $pos; undef @_child_window_geometry; $self->reshape if $self->window; $self->redraw; return $_tab_position; } method _tabs_changed () { $self->reshape if $self->window; $_ribbon->redraw if $_ribbon->window; } =head2 active_tab_index Returns the 0-based index of the currently-active tab. =cut method active_tab_index () { $_ribbon->active_tab_index } =head2 active_tab Returns the currently-active tab as a tab object. See below. =cut method active_tab () { $_ribbon->active_tab } =head2 active_tab_widget Returns the widget in the currently active tab. =cut # Old name *tab = \&active_tab_widget; method active_tab_widget () { $self->active_tab && $self->active_tab->widget } =head2 add_tab Add a new tab to this tabbed widget. Returns an object representing the tab; see L below. First parameter is the widget to use. Remaining form a hash: =over 4 =item label - label to show on the new tab =back =cut method add_tab ( $child, %opts ) { my $tab = $self->TAB_CLASS->new( $self, widget => $child, %opts ); $_ribbon->append_tab( $tab ); return $tab; } =head2 remove_tab Remove tab given by 0-based index or tab object. =cut method remove_tab { $_ribbon->remove_tab( @_ ) } =head2 move_tab Move tab given by 0-based index or tab object forward the given number of positions. =cut method move_tab { $_ribbon->move_tab( @_ ) } =head2 activate_tab Switch to the given tab; by 0-based index, or object. =cut method activate_tab { $_ribbon->activate_tab( @_ ) } =head2 next_tab Switch to the next tab. This may be bound as a key action. =cut *key_next_tab = \&next_tab; method next_tab (@) { $_ribbon->next_tab } =head2 prev_tab Switch to the previous tab. This may be bound as a key action. =cut *key_prev_tab = \&prev_tab; method prev_tab (@) { $_ribbon->prev_tab } method child_resized () { $self->reshape; } method on_key ( $ev ) { return 1 if $_ribbon->on_key( $ev ); return 0 unless $ev->type eq "key"; my $str = $ev->str; if($str =~ m/^M-(\d)$/ ) { my $index = $1 - 1; $self->activate_tab( $index ) if $index < $_ribbon->tabs; return 1; } return 0; } method render_to_rb ( $rb, $rect ) { # Just clear the child area if we have nothing better to do $rb->eraserect( $rect ); } class # hide from indexer Tickit::Widget::Tabbed::Tab :repr(HASH); use Tickit::Utils qw( textwidth ); =head1 METHODS ON TAB OBJECTS The following methods may be called on the objects returned by C or C. =cut sub BUILDARGS ( $class, $tabbed, %args ) { return ( tabbed => $tabbed, %args ); } has $_tabbed :param :weak; has $_widget :param :reader; has $_label :param :reader; has $_active = 0; has $_on_activated :writer; has $_on_deactivated :writer; =head2 index Returns the 0-based index of this tab =cut method index () { return $_tabbed->ribbon->_tab2index( $self ); } =head2 widget Returns the C contained by this tab =cut # generated accessor =head2 label Returns the current label text =cut has $_label_width; method label_width () { return $_label_width //= textwidth( $_label ); } # generated accessor =head2 set_label Set new label text for the tab =cut method set_label ( $label ) { $_label = $label; undef $_label_width; $_tabbed->_tabs_changed if $_tabbed; } =head2 is_active Returns true if this tab is the currently active one =cut method is_active () { return $_tabbed->active_tab == $self; } =head2 activate Activate this tab =cut method activate () { $_tabbed->activate_tab( $self ); } method _activate () { $self->widget->window->show if $self->widget->window; $self->$_on_activated() if $_on_activated; } method _deactivate () { $self->$_on_deactivated() if $_on_deactivated; $self->widget->window->hide if $self->widget->window; } =head2 set_on_activated Set a callback or method name to invoke when the tab is activated =cut # Generated accessor =head2 set_on_deactivated Set a callback or method name to invoke when the tab is deactivated =cut # Generated accessor =head2 pen Returns the C used to draw the label. Pen observers are no longer registered on the return value; to set a different pen on the tab, use the C method instead. =cut has $_pen :reader; method _has_pen () { defined $_pen } method set_pen ( $pen ) { $_pen = $pen; $_tabbed->_tabs_changed if $_tabbed; } method on_mouse ( $type, $button, $line, $col ) { return 0 unless $type eq "press" && $button == 1; $_tabbed->activate_tab( $self ); return 1; } 1; __END__ =head1 CUSTOM TAB CLASS Rather than use the default built-in object class for tab objects, a C or subclass thereof can return objects in another class instead. This is most useful for subclasses of the tabbed widget itself. To perform this, create a subclass of C. Since version 0.022 this module is implemented using L, so you can rely on having that available for implementing a subclass: use Object::Pad; class MyCustomTabClass extends Tickit::Widget::Tabbed::Tab; Arrange for this class to be used by the tabbed widget either by passing its name as a constructor argument called C, or by overriding a method called C. my $tabbed = Tickit::Widget::Tabbed->new( tab_class => "MyCustomTabClass" ); or use constant TAB_CLASS => "MyCustomTabClass"; =head1 CUSTOM RIBBON CLASS Rather than use the default built-in object class for the ribbon object, a C or subclass thereof can use an object in another subclass instead. This is most useful for subclasses of the tabbed widget itself. For more detail, see the documentation in L. =cut =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =back =head1 AUTHOR Tom Molesworth , Paul Evans =head1 LICENSE Copyright Tom Molesworth 2011; Paul Evans 2014. Licensed under the same terms as Perl itself. Tickit-Widget-Tabbed-0.026/lib/Tickit/Widget/Tabbed/0000755000175000017500000000000014200222124020056 5ustar leoleoTickit-Widget-Tabbed-0.026/lib/Tickit/Widget/Tabbed/Ribbon.pm0000644000175000017500000004337014200222067021644 0ustar leoleo# You may distribute under the terms of the Artistic License (the same terms # as Perl itself) # # (C) Paul Evans, 2011-2021 -- leonerd@leonerd.org.uk use v5.26; use Object::Pad 0.58; package Tickit::Widget::Tabbed::Ribbon 0.026; class Tickit::Widget::Tabbed::Ribbon :isa(Tickit::Widget); Tickit::Window->VERSION( '0.57' ); # ->bind_event use Tickit::Utils qw( textwidth ); use Carp; # It isn't really; we only use the direct style setting directly from the # containing Tickit::Widget::Tabbed use constant WIDGET_PEN_FROM_STYLE => 1; use Struct::Dumb; struct MoreMarker => [qw( text width window )]; =head1 NAME C - base class for C control ribbon =head1 DESCRIPTION This class contains the default implementation for the control ribbon used by L, and also acts as a base class to assist in the creation of a custom ribbon. Details of this class and its operation are useful to know when implenting a custom control ribbon. It is not necessary to consider this class if simply using the C with its default control ribbon. =head1 CUSTOM RIBBON CLASS To perform create a custom ribbon class, create a subclass of C with a constructor having the following behaviour: package Custom::Ribbon::Class; use base qw( Tickit::Widget::Tabbed::Ribbon ); sub new_for_orientation { my $class = shift; my ( $orientation, %args ) = @_; ... return $self; } Alternatively if this is not done, then one of two subclasses will be used for the constructor, by appending C<::horizontal> or C<::vertical> to the class name. In this case, the custom class should provide these as well. package Custom::Ribbon::Class; use base qw( Tickit::Widget::Tabbed::Ribbon ); package Custom::Ribbon::Class::horizontal; use base qw( Custom::Ribbon::Class ); ... package Custom::Ribbon::Class::vertical; use base qw( Custom::Ribbon::Class ); ... Arrange for this class to be used by the tabbed widget either by passing its name as a constructor argument called C, or by overriding a method called C. my $tabbed = Tickit::Widget::Tabbed->new( ribbon_class => "Ribbon::Class::Name" ); or use constant RIBBON_CLASS => "Ribbon::Class::Name"; =cut =head1 METHODS =cut sub new_for_orientation ( $class, $orientation, @args ) { return ${\"${class}::${orientation}"}->new( @args ); } { my $orig = __PACKAGE__->can( "new" ); no warnings 'redefine'; *new = sub ( $class, %args ) { foreach my $method (qw( scroll_to_visible on_key on_mouse )) { $class->can( $method ) or croak "$class cannot ->$method - do you subclass and implement it?"; } return $class->$orig( %args ); }; } has $_tabbed :param :weak; method tabbed { $_tabbed } has $_prev_more :reader; has $_next_more :reader; has $_active_tab_index :param :reader = 0; has @_tabs; ADJUSTPARAMS ( $params ) { push @_tabs, (delete $params->{tabs})->@* if exists $params->{tabs}; } ADJUST { my ( $prev_more, $next_more ) = $_tabbed->get_style_values(qw( more_left more_right )); $_prev_more = MoreMarker( $prev_more, textwidth( $prev_more ), undef ); $_next_more = MoreMarker( $next_more, textwidth( $next_more ), undef ); $self->scroll_to_visible( $_active_tab_index ); } method active_pen () { return $_tabbed->get_style_pen( "active" ); } =head2 tabs @tabs = $ribbon->tabs $count = $ribbon->tabs Returns a list of the contained L tab objects in list context, or the count of them in scalar context. =cut method tabs () { @_tabs } method _tab2index ( $tab_or_index ) { if( !ref $tab_or_index ) { croak "Invalid tab index" if $tab_or_index < 0 or $tab_or_index >= @_tabs; return $tab_or_index; } return ( grep { $tab_or_index == $_tabs[$_] } 0 .. $#_tabs )[0]; } method _pen_for_tab ( $tab ) { if( $tab->_has_pen and $tab->is_active ) { return Tickit::Pen->new($tab->pen->getattrs, $self->active_pen->getattrs); } elsif( $tab->_has_pen ) { return $tab->pen; } elsif( $tab->is_active ) { return $self->active_pen; } else { return (); # empty in list context } } =head2 active_tab_index $index = $ribbon->active_tab_index Returns the index of the currently-active tab =cut # generated accessor =head2 active_tab $tab = $ribbon->active_tab Returns the currently-active tab as a C tab object. =cut method active_tab { return $_tabs[$_active_tab_index]; } method append_tab ( $tab ) { push @_tabs, $tab; $_tabbed->_tabs_changed; $self->scroll_to_visible( undef ); } method remove_tab { my $del_index = $self->_tab2index( shift ); my ( $tab ) = splice @_tabs, $del_index, 1, (); $tab->widget->window->close; if( $_active_tab_index > $del_index ) { $_active_tab_index--; } elsif( $_active_tab_index == $del_index ) { $_active_tab_index-- if $del_index == @_tabs; if( $self->active_tab ) { $self->active_tab->_activate; } else { $_tabbed->window->expose; } } $_tabbed->_tabs_changed; $self->scroll_to_visible( undef ); } method move_tab { my $old_index = $self->_tab2index( shift ); my $delta = shift; if( $delta < 0 ) { $delta = -$old_index if $delta < -$old_index; } elsif( $delta > 0 ) { my $spare = $#_tabs - $old_index; $delta = $spare if $delta > $spare; } else { # delta == 0 return; } splice @_tabs, $old_index + $delta, 0, ( splice @_tabs, $old_index, 1, () ); # Adjust the active_tab_index to cope with tab move $_active_tab_index += $delta if $_active_tab_index == $old_index; $_active_tab_index++ if $_active_tab_index < $old_index and $_active_tab_index >= $old_index + $delta; $_active_tab_index-- if $_active_tab_index > $old_index and $_active_tab_index <= $old_index + $delta; $self->redraw; } method activate_tab { my $new_index = $self->_tab2index( shift ); return if $new_index == $_active_tab_index; if(my $old_widget = $self->active_tab->widget) { $self->active_tab->_deactivate; } $_active_tab_index = $new_index; $self->scroll_to_visible( $_active_tab_index ); $self->redraw; if(my $tab = $self->active_tab) { $tab->_activate; } else { $self->window->clear; } return $self; } method next_tab { $self->activate_tab( ( $self->active_tab_index + 1 ) % $self->tabs ); } method prev_tab { $self->activate_tab( ( $self->active_tab_index - 1 ) % $self->tabs ); } method on_pen_changed ( $pen, $id ) { $self->redraw; return $self->SUPER::on_pen_changed( $pen, $id ); } method on_key { 0 } method on_mouse { 0 } class # hide from indexer Tickit::Widget::Tabbed::Ribbon::horizontal :isa(Tickit::Widget::Tabbed::Ribbon); use constant orientation => "horizontal"; use List::Util qw( sum0 ); has $_active_marker :param { [ "[", "]" ] }; has $_scroll_offset = 0; method lines { 1 } method cols { return sum0(map { $_->label_width + 1 } $self->tabs) + 1; } method reshape { my $win = $self->window or return; $self->scroll_to_visible( undef ); my $prev_more = $self->prev_more; if( $prev_more->window ) { $prev_more->window->change_geometry( 0, 0, 1, $prev_more->width, ); } my $next_more = $self->next_more; if( $next_more->window ) { $next_more->window->change_geometry( 0, $win->cols - $next_more->width, 1, $next_more->width, ); } } method render_to_rb ( $rb, $rect ) { $rect->top == 0 or return; $rect->bottom == 1 or return; $rb->goto(0, -$_scroll_offset); my $prev_active; foreach my $tab ($self->tabs) { my $active = $tab->is_active; $rb->text($active ? $_active_marker->[0] : $prev_active ? $_active_marker->[1] : ' '); $rb->text($tab->label, $self->_pen_for_tab($tab)); $prev_active = $active; } if($prev_active) { $rb->text($_active_marker->[1]); } $rb->erase_to($self->window->cols); } method _col2tab ( $col ) { $col += $_scroll_offset; $col--; return if $col < 0; foreach my $tab ( $self->tabs ) { if( $col < $tab->label_width ) { return $tab, $col if wantarray; return $tab; } $col -= $tab->label_width; return if $col == 0; $col--; } return; } method scroll_to_visible ( $target_idx ) { my $win = $self->window or return; my $cols = $win->cols; my $prev_more = $self->prev_more or return; my $next_more = $self->next_more or return; my @tabs = $self->tabs; my $halfwidth = int( $cols / 2 ); my $ofs = $_scroll_offset; my $want_prev_more = defined $prev_more->window; my $want_next_more = defined $next_more->window; { my $col = -$ofs; $col++; # initial space my $start_of_idx; my $end_of_idx; my $i = 0; if( defined $target_idx ) { for( ; $i < $target_idx; $i++ ) { $col += $tabs[$i]->label_width + 1; } $start_of_idx = $col; $col += $tabs[$i++]->label_width; $end_of_idx = $col; $col++; } for( ; $i < @tabs; $i++ ) { $col += $tabs[$i]->label_width + 1; } $col--; $want_prev_more = ( $ofs > 0 ); $want_next_more = ( $col > $cols ); my $left_margin = $want_prev_more ? $prev_more->width : 0; my $right_margin = $want_next_more ? $cols - $next_more->width : $cols; if( defined $start_of_idx and $start_of_idx < $left_margin ) { $ofs -= $halfwidth; $ofs = 0 if $ofs < 0; redo; } if( defined $end_of_idx and $end_of_idx >= $right_margin ) { $ofs += $halfwidth; redo; } } $_scroll_offset = $ofs; if( $want_prev_more and !$prev_more->window ) { my $w = $win->make_float( 0, 0, 1, $prev_more->width, ); $prev_more->window = $w; $w->set_pen( $self->tabbed->get_style_pen( "more" ) ); $w->bind_event( expose => sub ( $win, $, $info, $ ) { $info->rb->text_at( 0, 0, $prev_more->text ); }); $w->bind_event( mouse => sub ( $win, $, $info, $ ) { $self->_scroll_left if $info->type eq "press" && $info->button == 1; return 1; } ); } elsif( !$want_prev_more and $prev_more->window ) { $prev_more->window->hide; undef $prev_more->window; } if( $want_next_more and !$next_more->window ) { my $w = $win->make_float( 0, $win->cols - $next_more->width, 1, $next_more->width, ); $next_more->window = $w; $w->set_pen( $self->tabbed->get_style_pen( "more" ) ); $w->bind_event( expose => sub ( $win, $, $info, $ ) { $info->rb->text_at( 0, 0, $next_more->text ); } ); $w->bind_event( mouse => sub ( $win, $, $info, $ ) { $self->_scroll_right if $info->type eq "press" && $info->button == 1; return 1; } ); } elsif( !$want_next_more and $next_more->window ) { $next_more->window->hide; undef $next_more->window; } } method _scroll_left { my $win = $self->window or return; $_scroll_offset -= int( $win->cols / 2 ); $_scroll_offset = 0 if $_scroll_offset < 0; $self->scroll_to_visible( undef ); $self->redraw; } method _scroll_right { my $win = $self->window or return; $_scroll_offset += int( $win->cols / 2 ); $self->scroll_to_visible( undef ); $self->redraw; } method on_key ( $ev ) { return unless $ev->type eq "key"; my $str = $ev->str; if($str eq 'Right') { $self->next_tab; return 1; } elsif($str eq 'Left') { $self->prev_tab; return 1; } } method on_mouse ( $ev ) { return 0 unless $ev->line == 0; return 0 unless my ( $tab, $tab_col ) = $self->_col2tab( $ev->col ); return $tab->on_mouse( $ev->type, $ev->button, 0, $tab_col ); } class # hide from indexer Tickit::Widget::Tabbed::Ribbon::vertical :isa(Tickit::Widget::Tabbed::Ribbon); use constant orientation => "vertical"; use List::Util qw( max ); has $_tab_position :param; has $_scroll_offset = 0; method lines { return scalar $self->tabs; } method cols { return 2 + max(0, map { $_->label_width } $self->tabs); } method reshape { my $win = $self->window or return; $self->scroll_to_visible( undef ); my $prev_more = $self->prev_more; if( $prev_more->window ) { $prev_more->window->change_geometry( 0, 0, 1, $win->cols, ); } my $next_more = $self->next_more; if( $next_more->window ) { $next_more->window->change_geometry( $win->lines - 1, $win->cols, 1, $win->cols, ); } } method render_to_rb ( $rb, $rect ) { my $lines = $self->window->lines; my $cols = $self->window->cols; my $next_line = -$_scroll_offset; foreach my $tab ($self->tabs) { my $active = $tab->is_active; my $this_line = $next_line; $next_line++; next if $this_line < $rect->top; return if $this_line >= $rect->bottom; $rb->goto($this_line, 0); my $spare = $cols - $tab->label_width; if($_tab_position eq 'left') { $rb->text($tab->label, $self->_pen_for_tab($tab)); $rb->text($active ? (' ' . ('>' x ($spare - 1))) : (' ' x $spare)); } elsif($_tab_position eq 'right') { $rb->text($active ? (('<' x ($spare - 1)) . ' ') : (' ' x $spare)); $rb->text($tab->label, $self->_pen_for_tab($tab)); } } while($next_line < $lines) { $rb->goto($next_line, 0); $rb->erase_to($cols); ++$next_line; } } method scroll_to_visible ( $idx ) { defined $idx or return; my $win = $self->window or return; my $lines = $win->lines; my $halfheight = int( $lines / 2 ); my $ofs = $_scroll_offset; { my $line = -$ofs; $line += $idx; if( $line < 0 ) { $ofs -= $halfheight; $ofs = 0 if $ofs < 0; redo; } if( $line >= $lines ) { $ofs += $halfheight; redo; } } $_scroll_offset = $ofs; } method _showhide_more_markers { } method on_key ( $ev ) { return unless $ev->type eq "key"; my $str = $ev->str; if($str eq 'Down') { $self->next_tab; return 1; } elsif($str eq 'Up') { $self->prev_tab; return 1; } } method on_mouse ( $ev ) { my $line = $ev->line; $line += $_scroll_offset; my @tabs = $self->tabs; return 0 unless $line < @tabs; return $tabs[$line]->on_mouse( $ev->type, $ev->button, 0, $ev->col ); } 1; =head1 SUBCLASS METHODS The subclass will need to provide implementations of the following methods. =cut =head2 render $ribbon->render( %args ) =head2 lines $lines = $ribbon->lines =head2 cols $cols = $ribbon->cols As per the L methods. =head2 on_key $handled = $ribbon->on_key( $ev ) =head2 on_mouse $handled = $ribbon->on_mouse( $ev ) As per the L methods. Optional. If not supplied then the ribbon will not respond to keyboard or mouse events. =head2 scroll_to_visible $ribbon->scroll_to_visible( $index ) Requests that a scrollable control ribbon scrolls itself so that the given C<$index> tab is visible. =cut =head1 AUTHOR Paul Evans =cut Tickit-Widget-Tabbed-0.026/examples/0000755000175000017500000000000014200222124015273 5ustar leoleoTickit-Widget-Tabbed-0.026/examples/demo-custom-ribbon.pl0000644000175000017500000000345614200221670021352 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Tickit; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $tabbed = Tickit::Widget::Tabbed->new( tab_position => "bottom", ribbon_class => "CustomRibbon", 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->run; use 5.026; use Object::Pad 0.22; class CustomRibbon extends Tickit::Widget::Tabbed::Ribbon; use Tickit::Style -copy; BEGIN { style_definition base => current_fg => 8; } class CustomRibbon::horizontal extends CustomRibbon; use Tickit::Utils qw( textwidth ); method lines () { 1 } method cols () { 1 } method render_to_rb ( $rb, $rect ) { my @tabs = $self->tabs; $rb->goto( 0, 0 ); $rb->text( sprintf "[%d tabs]: ", scalar @tabs ); my $active = $self->active_tab; $rb->text( $active->label, $self->active_pen ); $rb->text( " [also:" ); foreach my $tab ( @tabs ) { $rb->erase( 1 ); if( $tab == $active ) { $rb->text( "x" x textwidth( $tab->label ), $self->get_style_pen( "current" ) ); } else { $rb->text( $tab->label ); } } $rb->text( "]" ); $rb->erase_to( $self->window->cols ); } method scroll_to_visible ($) { } Tickit-Widget-Tabbed-0.026/examples/demo-logtail.pl0000644000175000017500000000306314200221670020214 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Tickit::Async; use Tickit::Widget::Tabbed; use Tickit::Widget::Scroller; use Tickit::Widget::Scroller::Item::Text; use IO::Async::Loop; use IO::Async::FileStream; use IO::Async::Protocol::LineStream; my $tabbed = Tickit::Widget::Tabbed->new( tab_position => "bottom", pen_active => Tickit::Pen->new( u => 1 ), ); my $loop = IO::Async::Loop->new; foreach my $path ( @ARGV ) { open my $fh, "<", $path or die "Cannot open $path for reading - $!"; my $scroller = Tickit::Widget::Scroller->new; my $tab = $tabbed->add_tab( $scroller, label => $path ); my $stream = IO::Async::Protocol::LineStream->new( transport => IO::Async::FileStream->new( read_handle => $fh, on_initial => sub { my ( $self ) = @_; $self->seek_to_last( "\n" ); }, ), on_read_line => sub { my ( $self, $line ) = @_; my $item = Tickit::Widget::Scroller::Item::Text->new( $line ); $scroller->push( $item ); $tab->pen->chattr( fg => 5 ); }, ); $tab->set_on_activated( sub { my $self = shift; $self->pen->delattr( 'fg' ); } ); $loop->add( $stream ); } my $tickit = Tickit::Async->new; $loop->add( $tickit ); $tickit->set_root_widget( $tabbed ); $tickit->run; Tickit-Widget-Tabbed-0.026/examples/demo-multiline-ribbon.pl0000644000175000017500000000432314200221670022034 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Tickit; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $tabbed = Tickit::Widget::Tabbed->new( tab_position => "top", ribbon_class => "IndexCard", style => { active_fg => "hi-green", active_bg => "black", }, ); 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->run; use 5.026; use Object::Pad 0.22; class IndexCard extends Tickit::Widget::Tabbed::Ribbon; method lines () { 3 } use Tickit::Style -copy; BEGIN { style_definition base => tab_fg => "grey", tab_bg => 0, tab_b => 0; } class IndexCard::horizontal extends IndexCard; use Tickit::RenderBuffer qw(LINE_SINGLE); use Tickit::Utils qw( textwidth ); method lines () { 2 } method cols () { 1 } method render_to_rb ( $rb, $rect ) { my @tabs = $self->tabs; my $win = $self->window; $rb->clip( $rect ); my $pen = $self->get_style_pen( "tab" ); my $x = 1; $rb->erase_at(0, 0, $win->cols, $pen); $rb->hline_at(1, 0, $win->cols - 1, LINE_SINGLE, $pen); foreach my $tab (@tabs) { my $len = textwidth $tab->label; $rb->erase_at(1, $x, $len + 4, $pen) if $tab->is_active; $rb->hline_at(1, $x - 1, $x, LINE_SINGLE, $pen); $rb->hline_at(1, $x + $len + 3, $x + $len + 5, LINE_SINGLE, $pen); $rb->hline_at(0, $x, $x + $len + 3, LINE_SINGLE, $pen); $rb->vline_at(0, 1, $x, LINE_SINGLE, $pen); $rb->vline_at(0, 1, $x + $len + 3, LINE_SINGLE, $pen); $rb->text_at(0, $x + 2, $tab->label, $tab->is_active ? $self->active_pen : $pen); $x += $len + 4; } } method scroll_to_visible ($) { } Tickit-Widget-Tabbed-0.026/examples/demo-tabs.pl0000644000175000017500000000223014200221670017505 0ustar leoleo#!/usr/bin/perl use strict; 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; Tickit-Widget-Tabbed-0.026/META.json0000644000175000017500000000332314200222124015077 0ustar leoleo{ "abstract" : "Basic tabbed window support", "author" : [ "Tom Molesworth " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Tickit-Widget-Tabbed", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::Identity" : "0", "Test::More" : "0.88", "Test::Refcount" : "0", "Tickit::Test" : "0.43", "Tickit::Widget::Static" : "0", "Tickit::Widget::VBox" : "0", "Tickit::Window" : "0.57" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "runtime" : { "requires" : { "List::Util" : "1.26", "Object::Pad" : "0.58", "Scalar::Util" : "0", "Struct::Dumb" : "0", "Tickit::ContainerWidget" : "0.44", "Tickit::Widget" : "0.36", "Tickit::Window" : "0.28", "parent" : "0", "perl" : "5.026" } } }, "provides" : { "Tickit::Widget::Tabbed" : { "file" : "lib/Tickit/Widget/Tabbed.pm", "version" : "0.026" }, "Tickit::Widget::Tabbed::Ribbon" : { "file" : "lib/Tickit/Widget/Tabbed/Ribbon.pm", "version" : "0.026" } }, "release_status" : "stable", "version" : "0.026", "x_serialization_backend" : "JSON::PP version 4.04" } Tickit-Widget-Tabbed-0.026/Changes0000644000175000017500000001170614200222067014763 0ustar leoleoRevision history for Tickit-Widget-Tabbed 0.026 2022-02-07 [CHANGES] * Updates for perl 5.35.9: + Avoid use of @_ in signatured methods 0.025 2021-11-20 [CHANGES] * Updates for Object::Pad 0.57 + Use :isa instead of legacy `extends` + Use slot initialisation blocks and ADJUSTPARAMS instead of BUILD + Use :reader to tidy up many simple accessor methods + Use :weak slots * Depend on Object::Pad 0.58 because of bugfixes 0.024 2021-07-06 [CHANGES] * Update to Object::Pad 0.43 + Make use of :param and ADJUST to reduce/remove BUILD blocks 0.023 2020-06-13 [CHANGES] * Update to Object::Pad 0.27 + BUILD block syntax + package+class declaration to keep metadata parsers happy 0.022 2020-04-17 [CHANGES] * Use Object::Pad 0.021 2017-02-15 15:14:05 [CHANGES] * Use Style-directed keybindings * Also bind and for tab switching [BUGFIXES] * Remember to ->close old ribbon window when removing it 0.020 2016-08-08 14:21:33 [CHANGES] * Updated for Tickit 0.57: + Use $win->bind_event instead of $win->set_on_* 0.019 2015-06-11 23:23:15 [CHANGES] * Avoid using pen observers and instead provide a $tab->set_pen method to set a pen for a tab. This is a short-term temporary measure until a better solution is found, likely involving the style system. 0.018 2015-03-23 23:23:16 [CHANGES] * Use ->set_style instead of ->set_pen and declare WIDGET_PEN_FROM_STYLE to keep Tickit 0.50 deprecations happy 0.017 2015-02-04 00:35:56 [BUGFIXES] * Remember to declare that sum0 needs List::Util 1.26 * Avoid ->window->clear now it's dead; implement a render_to_rb method that just does ->eraserect instead * Fix off-by-one error that causes Alt+{digit} shortcut to crash 0.016 2014-08-06 16:10:44 [BUGFIXES] * Use List::Util::sum0 instead of sum so as not to print undef warnings when there are no tabs defined 0.015 2014-04-15 02:41:29 [CHANGES] * Prepare unit tests for Tickit 0.45's optimisation away of ->expose on invisible windows 0.014 2014-04-07 19:08:55 [CHANGES] * Rename ->tab to ->active_tab_widget * Subclass from ContainerWidget properly * Provide accurate ->lines and ->cols methods 0.013 2014-04-03 23:45:05 UTC [CHANGES] * Use Tickit 0.32-style structures for key/mouse events * Prepare for Tickit 0.44's whole-tree RB rendering order 0.012 2014-04-01 22:53:51 UTC [CHANGES] * Use new Window expose with_rb and mouse with_ev events from Tickit 0.42 * Use new associative is_termlog() to avoid rendering order upsetting unit tests 0.011 2013-11-06 17:21:12 UTC [CHANGES] * Support horizontal ribbons taller than 1 line (RT88081) * Updated demos to use Tickit::RenderBuffer [BUGFIXES] * Remember to pass constructor arguments to SUPER::new (RT89104) * Updated demos to use new Tickit::Style-based API (RT90082) * Need to use 'read_handle' for IO::Async::FileStream, not just 'handle' 0.010 2013-07-15 03:11:21 Europe/London Use Tickit::Style for configuration Updated to use Tickit 0.36's ->render_to_rb 0.009 2013-03-15 21:48:11 Europe/London Make sure to ->close windows of removed tabs 0.008 2012-12-16 18:33:39 Europe/London Allow Tab on_{de,}activated to be a method name or a coderef Set minimal perl version correctly in Makefile.PL (RT81862) 0.007 2012-11-11 14:33:26 Europe/London Disable the deprecated CLEAR_BEFORE_RENDER behaviour Don't create two sets of child windows for widgets Use Tickit 0.23's make_hidden_sub Window method 0.006 2012-11-09 19:02:50 Europe/London Have ->activate_index croak on out-of-bounds tab indexes. 0.005 2012-09-11 06:00:23 Europe/London New ribbon model - allow custom subclasses Indicate selected tab with [] brackets Allow mouse click on tab labels Scroll tab ribbon if there's too many labels for the window width Various small bugfixes relating to tab move and removal 0.004 2012-06-12 09:50:32 Europe/London Use Tickit 0.17's hidden windows to give every child a window with all but one hidden, rather than only one child having a window. 0.003 2011-12-31 01:34:18 Europe/London Added ability to build subclasses of tab objects 0.002 2011-11-26 13:48:42 Europe/London Bugfix: remember to activate the initial tab immediately if we already have a window. 0.001 2011-10-21 22:03:32 Europe/London Initial CPAN release Tickit-Widget-Tabbed-0.026/MANIFEST0000644000175000017500000000146514200222124014614 0ustar leoleoChanges dist.ini examples/demo-custom-ribbon.pl examples/demo-logtail.pl examples/demo-multiline-ribbon.pl examples/demo-tabs.pl lib/Tickit/Widget/Tabbed.pm lib/Tickit/Widget/Tabbed/Ribbon.pm LICENSE Makefile.PL MANIFEST This list of files README t/00-pod.t t/00-use.t t/10-render-bottom.t t/10-render-left.t t/10-render-right.t t/10-render-top.t t/11-labels-horizontal.t t/11-labels-vertical.t t/12-pens-horizontal.t t/12-pens-vertical.t t/13-children-horizontal.t t/13-children-vertical.t t/14-input-horizontal.t t/14-input-vertical.t t/20-tabs.t t/21-tab-activate.t t/22-tabs-late.t t/23-tab-subclass.t t/30-remove-last.t t/31-change-orientation.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Tickit-Widget-Tabbed-0.026/LICENSE0000644000175000017500000004370614200221670014501 0ustar leoleoThis software is copyright (c) 2011 by Tom Molesworth. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2011 by Tom Molesworth. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2011 by Tom Molesworth. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Tickit-Widget-Tabbed-0.026/META.yml0000644000175000017500000000210214200222124014721 0ustar leoleo--- abstract: 'Basic tabbed window support' author: - 'Tom Molesworth ' build_requires: Test::Identity: '0' Test::More: '0.88' Test::Refcount: '0' Tickit::Test: '0.43' Tickit::Widget::Static: '0' Tickit::Widget::VBox: '0' Tickit::Window: '0.57' configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Tickit-Widget-Tabbed no_index: directory: - t - inc provides: Tickit::Widget::Tabbed: file: lib/Tickit/Widget/Tabbed.pm version: '0.026' Tickit::Widget::Tabbed::Ribbon: file: lib/Tickit/Widget/Tabbed/Ribbon.pm version: '0.026' requires: List::Util: '1.26' Object::Pad: '0.58' Scalar::Util: '0' Struct::Dumb: '0' Tickit::ContainerWidget: '0.44' Tickit::Widget: '0.36' Tickit::Window: '0.28' parent: '0' perl: '5.026' version: '0.026' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Tickit-Widget-Tabbed-0.026/Makefile.PL0000644000175000017500000000417314200221670015441 0ustar leoleo use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Basic tabbed window support", "AUTHOR" => "Tom Molesworth ", "BUILD_REQUIRES" => { "Test::Identity" => 0, "Test::More" => "0.88", "Test::Refcount" => 0, "Tickit::Test" => "0.43", "Tickit::Widget::Static" => 0, "Tickit::Widget::VBox" => 0, "Tickit::Window" => "0.57", }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Tickit-Widget-Tabbed", "EXE_FILES" => [], "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.026", "NAME" => "Tickit::Widget::Tabbed", "PREREQ_PM" => { "Object::Pad" => "0.58", "List::Util" => "1.26", "Scalar::Util" => 0, "Struct::Dumb" => 0, "Tickit::ContainerWidget" => "0.44", "Tickit::Widget" => "0.36", "Tickit::Window" => "0.28", "parent" => 0, }, "VERSION_FROM" => "lib/Tickit/Widget/Tabbed.pm", "test" => { "TESTS" => "t/*.t" } ); if( eval { require Module::Metadata } ) { # EU:MM won't understand the `class` syntax used here. We'll have to # use the locally-patched Module::Metadata at author-time to find it my $provides = Module::Metadata->provides( dir => "lib", version => 2, ); $WriteMakefileArgs{META_MERGE}{provides} = $provides; # Try to get VERSION foreach my $p ( values %$provides ) { next unless $p->{file} eq $WriteMakefileArgs{VERSION_FROM}; delete $WriteMakefileArgs{VERSION_FROM}; $WriteMakefileArgs{VERSION} = $p->{version}; last; } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Tickit-Widget-Tabbed-0.026/t/0000755000175000017500000000000014200222124013720 5ustar leoleoTickit-Widget-Tabbed-0.026/t/30-remove-last.t0000644000175000017500000000132414200221670016570 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); $widget->set_window( $win ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget content" ), label => "label" ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("label",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4),TEXT("",bg=>4)], [TEXT("Widget content")] ], 'Display initially' ); $widget->remove_tab( 0 ); flush_tickit; is_display( [ [TEXT("",bg=>4)], [TEXT("")] ], 'Display blanked after removing last tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/00-use.t0000755000175000017500000000015614200221670015130 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use_ok('Tickit::Widget::Tabbed'); done_testing; Tickit-Widget-Tabbed-0.026/t/21-tab-activate.t0000644000175000017500000000170214200221670016676 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Identity; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); my @tabs = map { $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) } 0 .. 2; my $activated_self; my $activated = 0; $tabs[1]->set_on_activated( sub { ( $activated_self ) = @_; $activated++ } ); is( $activated, 0, '$activated initially' ); $widget->activate_tab( 1 ); is( $activated, 1, '$activated after ->activate_tab' ); identical( $activated_self, $tabs[1], '$activate_self' ); $widget->activate_tab( 0 ); is( $activated, 1, '$activated unchanged after ->activate_tab on a different tab' ); my $deactivated = 0; $tabs[0]->set_on_deactivated( sub { $deactivated++ } ); $widget->activate_tab( 1 ); is( $deactivated, 1, '$deactivated after ->activate_tab elsewhere' ); done_testing; Tickit-Widget-Tabbed-0.026/t/10-render-left.t0000644000175000017500000001175014200221670016543 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; # Account for Tickit 0.44's whole-tree RB rendering sub TERMLINE { my $line = shift; my @ret; while(@_) { my $col = shift; my $exp = shift; if( $Tickit::Window::VERSION >= '0.44' ) { push( @ret, "$line,$col" => [ @$exp ] ), next if !@ret; # If the previous code ends in an erasech, it must be moveend=1 $ret[-1][-1][2] = 1 if $ret[-1][-1][0] eq "erasech"; push @{ $ret[-1] }, @$exp; } else { push @ret, "$line,$col" => $exp; } } return @ret; } my $win = mk_window; my @statics = map { Tickit::Widget::Static->new( text => "Widget $_" ) } 0 .. 2; my $widget = Tickit::Widget::Tabbed->new( tab_position => "left" ); ok( defined $widget, 'defined $widget' ); $widget->add_tab( $statics[$_], label => "tab$_" ) for 0 .. $#statics; $widget->set_window( $win ); ok( defined $statics[0]->window, '$static has window after ->set_window $win' ); flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN(fg => 14,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT(" >") ], 6 => [ SETPEN, PRINT("Widget 0"), SETBG(undef), ERASECH(66) ], ), TERMLINE( 1, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 6 => [ SETBG(undef), ERASECH(74) ], ), TERMLINE( 2, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 6 => [ SETBG(undef), ERASECH(74) ], ), ( map { TERMLINE( $_, 0 => [ SETBG(4), ERASECH(6) ], 6 => [ SETBG(undef), ERASECH(74) ], ) } 3 .. 24 ), }, 'Termlog initially' ); is_display( [ [TEXT("tab0",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget 0")], [TEXT("tab1 ",fg=>7,bg=>4), TEXT("")], [TEXT("tab2 ",fg=>7,bg=>4), TEXT("")] ], 'Display initially' ); $widget->next_tab; flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 6 => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(66) ], ), TERMLINE( 1, 0 => [ SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT(" >") ], 6 => [ SETBG(undef), ERASECH(74) ], ), TERMLINE( 2, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 6 => [ SETBG(undef), ERASECH(74) ], ), ( map { TERMLINE( $_, 0 => [ SETBG(4), ERASECH(6) ], 6 => [ SETBG(undef), ERASECH(74) ], ) } 3 .. 24 ), }, 'Termlog after ->next_tab' ); is_display( [ [TEXT("tab0 ",fg=>7,bg=>4), TEXT("Widget 1")], [TEXT("tab1",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("")], [TEXT("tab2 ",fg=>7,bg=>4), TEXT("")] ], 'Display after ->next_tab' ); $widget->add_tab( Tickit::Widget::Static->new( text => "Another static" ), label => "newtab" ); flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 8 => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(64) ], ), TERMLINE( 1, 0 => [ SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT(" >>>") ], 8 => [ SETBG(undef), ERASECH(72) ], ), TERMLINE( 2, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 8 => [ SETBG(undef), ERASECH(72) ], ), TERMLINE( 3, 0 => [ SETPEN(fg => 7,bg => 4), PRINT("newtab"), SETPEN(fg => 7,bg => 4), PRINT(" ") ], 8 => [ SETBG(undef), ERASECH(72) ], ), ( map { TERMLINE( $_, 0 => [ SETBG(4), ERASECH(8) ], 8 => [ SETBG(undef), ERASECH(72) ], ) } 4 .. 24 ), }, 'Termlog after ->add_tab' ); is_display( [ [TEXT("tab0 ",fg=>7,bg=>4), TEXT("Widget 1")], [TEXT("tab1",fg=>14,bg=>4), TEXT(" >>>",fg=>7,bg=>4), TEXT("")], [TEXT("tab2 ",fg=>7,bg=>4), TEXT("")], [TEXT("newtab ",fg=>7,bg=>4), TEXT("")] ], 'Display after ->add_tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/11-labels-vertical.t0000644000175000017500000000320414200221670017401 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "left" ); my $tab = $widget->add_tab( Tickit::Widget::Static->new( text => "Widget" ), label => "tab" ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget")] ], 'Display initially' ); $tab->set_label( "newlabel" ); flush_tickit; is_display( [ [TEXT("newlabel",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget")] ], 'Display after ->set_label' ); # Narrow rendering $widget->set_window( undef ); my $subwin = $win->make_sub( 0, 0, 5, 80 ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) for 1..10; # Should be too narrow now $widget->set_window( $subwin ); flush_tickit; is_display( [ [TEXT("newlabel",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget")], [TEXT("tab1 ",fg=>7,bg=>4)], [TEXT("tab2 ",fg=>7,bg=>4)], [TEXT("tab3 ",fg=>7,bg=>4)], [TEXT("tab4 ",fg=>7,bg=>4)] ], 'Display with narrow truncation' ); $widget->activate_tab( 7 ); flush_tickit; is_display( [ [TEXT("tab4 ",fg=>7,bg=>4), TEXT("Widget 7")], [TEXT("tab5 ",fg=>7,bg=>4)], [TEXT("tab6 ",fg=>7,bg=>4)], [TEXT("tab7",fg=>14,bg=>4), TEXT(" >>>>>",fg=>7,bg=>4)], [TEXT("tab8 ",fg=>7,bg=>4)] ], 'Display scrolls ribbon to active tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/14-input-horizontal.t0000644000175000017500000000360714200221670017670 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) for 1 .. 3; $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 tab3 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1")] ], 'Display initially' ); is( $widget->active_tab_index, 0, '->active_tab_index initially' ); presskey( key => "Right" ); flush_tickit; is_display( [ [TEXT(" tab1[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]tab3 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after Right key' ); is( $widget->active_tab_index, 1, '->active_tab_index after Right key' ); presskey( key => "C-PageDown" ); flush_tickit; is_display( [ [TEXT(" tab1 tab2[",fg=>7,bg=>4), TEXT("tab3",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 3")] ], 'Display after C-PageDown key' ); is( $widget->active_tab_index, 2, '->active_tab_index after C-PageDown key' ); presskey( key => "M-1" ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 tab3 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1")] ], 'Display after M-1 key' ); is( $widget->active_tab_index, 0, '->active_tab_index after M-1 key' ); pressmouse( press => 1, 0, 7 ); flush_tickit; is_display( [ [TEXT(" tab1[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]tab3 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after press mouse 1 @(0,7)' ); is( $widget->active_tab_index, 1, '->active_tab_index after press mouse 1 @(0,7)' ); done_testing; Tickit-Widget-Tabbed-0.026/t/23-tab-subclass.t0000644000175000017500000000154614200221670016725 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top", tab_class => "TestWidget::Tab", ); my $tab = $widget->add_tab( Tickit::Widget::Static->new( text => "" ), label => "newtab", custom_attr => 123, ); isa_ok( $tab, "TestWidget::Tab", '$tab from custom tab_class' ); is( $tab->custom_attr, 123, '$tab->custom_attr' ); done_testing; package TestWidget::Tab; use base qw( Tickit::Widget::Tabbed::Tab ); sub new { my $class = shift; ( undef, my %args ) = @_; my $self = $class->SUPER::new( @_ ); $self->{custom_attr} = $args{custom_attr}; return $self; } sub custom_attr { my $self = shift; return $self->{custom_attr}; } Tickit-Widget-Tabbed-0.026/t/14-input-vertical.t0000644000175000017500000000377514200221670017316 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "left" ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) for 1 .. 3; $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("tab1",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget 1")], [TEXT("tab2 ",fg=>7,bg=>4)], [TEXT("tab3 ",fg=>7,bg=>4)] ], 'Display initially' ); is( $widget->active_tab_index, 0, '->active_tab_index initially' ); presskey( key => "Down" ); flush_tickit; is_display( [ [TEXT("tab1 ",fg=>7,bg=>4), TEXT("Widget 2")], [TEXT("tab2",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4)], [TEXT("tab3 ",fg=>7,bg=>4)] ], 'Display after Down key' ); is( $widget->active_tab_index, 1, '->active_tab_index after Down key' ); presskey( key => "C-PageDown" ); flush_tickit; is_display( [ [TEXT("tab1 ",fg=>7,bg=>4), TEXT("Widget 3")], [TEXT("tab2 ",fg=>7,bg=>4)], [TEXT("tab3",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4)] ], 'Display after C-PageDown key' ); is( $widget->active_tab_index, 2, '->active_tab_index after C-PageDown key' ); presskey( key => "M-1" ); flush_tickit; is_display( [ [TEXT("tab1",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget 1")], [TEXT("tab2 ",fg=>7,bg=>4)], [TEXT("tab3 ",fg=>7,bg=>4)] ], 'Display after M-1 key' ); is( $widget->active_tab_index, 0, '->active_tab_index after M-1 key' ); pressmouse( press => 1, 1, 3 ); flush_tickit; is_display( [ [TEXT("tab1 ",fg=>7,bg=>4), TEXT("Widget 2")], [TEXT("tab2",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4)], [TEXT("tab3 ",fg=>7,bg=>4)] ], 'Display after mouse press 1 @(1,3)' ); is( $widget->active_tab_index, 1, '->active_tab_index after mouse press 1 @(1,3)' ); done_testing; Tickit-Widget-Tabbed-0.026/t/10-render-right.t0000644000175000017500000001207014200221670016722 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; # Account for Tickit 0.44's whole-tree RB rendering sub TERMLINE { my $line = shift; my @ret; while(@_) { my $col = shift; my $exp = shift; if( $Tickit::Window::VERSION >= '0.44' ) { push( @ret, "$line,$col" => [ @$exp ] ), next if !@ret; # If the previous code ends in an erasech, it must be moveend=1 $ret[-1][-1][2] = 1 if $ret[-1][-1][0] eq "erasech"; push @{ $ret[-1] }, @$exp; } else { push @ret, "$line,$col" => $exp; } } return @ret; } my $win = mk_window; my @statics = map { Tickit::Widget::Static->new( text => "Widget $_" ) } 0 .. 2; my $widget = Tickit::Widget::Tabbed->new( tab_position => "right" ); ok( defined $widget, 'defined $widget' ); $widget->add_tab( $statics[$_], label => "tab$_" ) for 0 .. $#statics; $widget->set_window( $win ); ok( defined $statics[0]->window, '$static has window after ->set_window $win' ); flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN, PRINT("Widget 0"), SETBG(undef), ERASECH(66) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT("< "), SETPEN(fg => 14,bg => 4), PRINT("tab0") ], ), TERMLINE( 1, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab1") ], ), TERMLINE( 2, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab2") ], ), ( map { TERMLINE( $_, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETBG(4), ERASECH(6) ], ) } 3 .. 24 ), }, 'Termlog initially' ); is_display( [ [TEXT("Widget 0"), BLANK(66), TEXT("< ",fg=>7,bg=>4), TEXT("tab0",fg=>14,bg=>4)], [BLANK(74), TEXT(" tab1",fg=>7,bg=>4)], [BLANK(74), TEXT(" tab2",fg=>7,bg=>4)] ], 'Display initially' ); $widget->next_tab; flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(66) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0") ], ), TERMLINE( 1, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT("< "), SETPEN(fg => 14,bg => 4), PRINT("tab1") ], ), TERMLINE( 2, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab2") ], ), ( map { TERMLINE( $_, 0 => [ SETBG(undef), ERASECH(74) ], 74 => [ SETBG(4), ERASECH(6) ] ) } 3 .. 24 ), }, 'Termlog after ->next_tab' ); is_display( [ [TEXT("Widget 1"), BLANK(66), TEXT(" tab0",fg=>7,bg=>4)], [BLANK(74), TEXT("< ",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4)], [BLANK(74), TEXT(" tab2",fg=>7,bg=>4)] ], 'Display after ->next_tab' ); $widget->add_tab( Tickit::Widget::Static->new( text => "Another static" ), label => "newtab" ); flush_tickit; is_termlog( { TERMLINE( 0, 0 => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(64) ], 72 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0") ], ), TERMLINE( 1, 0 => [ SETBG(undef), ERASECH(72) ], 72 => [ SETPEN(fg => 7,bg => 4), PRINT("<<< "), SETPEN(fg => 14,bg => 4), PRINT("tab1") ], ), TERMLINE( 2, 0 => [ SETBG(undef), ERASECH(72) ], 72 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab2") ], ), TERMLINE( 3, 0 => [ SETBG(undef), ERASECH(72) ], 72 => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("newtab") ], ), ( map { TERMLINE( $_, 0 => [ SETBG(undef), ERASECH(72) ], 72 => [ SETBG(4), ERASECH(8) ], ) } 4 .. 24 ), }, 'Termlog after ->add_tab' ); is_display( [ [TEXT("Widget 1"), BLANK(64), TEXT(" tab0",fg=>7,bg=>4)], [BLANK(72), TEXT("<<< ",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4)], [BLANK(72), TEXT(" tab2",fg=>7,bg=>4)], [BLANK(72), TEXT(" newtab",fg=>7,bg=>4)] ], 'Display after ->add_tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/10-render-top.t0000644000175000017500000001002514200221670016405 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my @statics = map { Tickit::Widget::Static->new( text => "Widget $_" ) } 0 .. 2; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); ok( defined $widget, 'defined $widget' ); $widget->add_tab( $statics[$_], label => "tab$_" ) for 0 .. $#statics; $widget->set_window( $win ); ok( defined $statics[0]->window, '$static has window after ->set_window $win' ); flush_tickit; is_termlog( { "0,0" => [ SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), ERASECH(65) ], "1,0" => [ SETPEN, PRINT("Widget 0"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 2 .. 24 ), }, 'Termlog initially' ); is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab0",fg=>14,bg=>4), TEXT("]tab1 tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 0")] ], 'Display initially' ); $widget->next_tab; flush_tickit; is_termlog( { "0,0" => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETBG(4), ERASECH(65) ], "1,0" => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 2 .. 24 ), }, 'Termlog after ->next_tab' ); is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1")] ], 'Display after ->next_tab' ); $widget->add_tab( Tickit::Widget::Static->new( text => "Another static" ), label => "newtab" ); flush_tickit; is_termlog( { "0,0" => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("newtab"), SETBG(4), ERASECH(58) ], # Tickit::Window 0.45 optimised away ->expose on invisible windows ( $Tickit::Window::VERSION >= '0.45' ? () : ( "1,0" => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 2 .. 24 ) ) ), }, 'Termlog after ->add_tab' ); is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 newtab ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1")] ], 'Display after ->add_tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/20-tabs.t0000644000175000017500000001175714200221670015275 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Test::Identity; use Test::Refcount; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); my @tabs = map { $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) } 0 .. 2; is_oneref( $widget, '$widget still has refcount 1 after constructing tabs' ); is( $tabs[$_]->index, $_, "\$tabs[$_]->index" ) for 0 .. 2; is( $widget->active_tab_index, 0, '$widget->active_tab_index initially' ); ok( $tabs[0]->is_active, '$tabs[0] is active initially' ); ok( !$tabs[1]->is_active, '$tabs[1] is not active initially' ); ok( !$tabs[2]->is_active, '$tabs[2] is not active initially' ); identical( $widget->active_tab, $tabs[0], '$widget->active_tab is $tabs[0] initially' ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab0",fg=>14,bg=>4), TEXT("]tab1 tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 0")] ], 'Display initially' ); $widget->activate_tab( 1 ); is( $widget->active_tab_index, 1, '$widget->active_tab_index after ->activate_tab' ); ok( !$tabs[0]->is_active, '$tabs[0] is not active after ->activate_tab' ); ok( $tabs[1]->is_active, '$tabs[1] is active after ->activate_tab' ); ok( !$tabs[2]->is_active, '$tabs[2] is not active after ->activate_tab' ); identical( $widget->active_tab, $tabs[1], '$widget->active_tab is $tabs[1] after ->activate_tab' ); flush_tickit; is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1")] ], 'Display after ->activate_tab index' ); $widget->activate_tab( $tabs[2] ); flush_tickit; is_display( [ [TEXT(" tab0 tab1[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after ->activate_tab $tab' ); $widget->move_tab( 1, +1 ); is( $tabs[0]->index, 0, '$tabs[0]->index after ->move_tab +1' ); is( $tabs[1]->index, 2, '$tabs[1]->index after ->move_tab +1' ); is( $tabs[2]->index, 1, '$tabs[2]->index after ->move_tab +1' ); is( $widget->active_tab_index, 1, '$widget->active_tab_index after ->move_tab +1' ); ok( !$tabs[0]->is_active, '$tabs[0] is not active after ->move_tab +1' ); ok( !$tabs[1]->is_active, '$tabs[1] is not active after ->move_tab +1' ); ok( $tabs[2]->is_active, '$tabs[2] is active after ->move_tab +1' ); flush_tickit; is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]tab1 ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after ->move_tab +1' ); $widget->move_tab( 2, -1 ); is( $tabs[0]->index, 0, '$tabs[0]->index after ->move_tab -1' ); is( $tabs[1]->index, 1, '$tabs[1]->index after ->move_tab -1' ); is( $tabs[2]->index, 2, '$tabs[2]->index after ->move_tab -1' ); is( $widget->active_tab_index, 2, '$widget->active_tab_index after ->move_tab -1' ); ok( !$tabs[0]->is_active, '$tabs[0] is not active after ->move_tab -1' ); ok( !$tabs[1]->is_active, '$tabs[1] is not active after ->move_tab -1' ); ok( $tabs[2]->is_active, '$tabs[2] is active after ->move_tab -1' ); flush_tickit; is_display( [ [TEXT(" tab0 tab1[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after ->move_tab -1' ); $widget->remove_tab( 1 ); splice @tabs, 1, 1, (); is( $widget->active_tab_index, 1, '$widget->active_tab_index after ->remove' ); ok( !$tabs[0]->is_active, '$tabs[0] is not active after ->remove_tab' ); ok( $tabs[1]->is_active, '$tabs[1] is active after ->remove_tab' ); identical( $widget->active_tab, $tabs[1], '$widget->active_tab is $tabs[1] after ->remove_tab' ); flush_tickit; is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab2",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 2")] ], 'Display after ->remove_tab index' ); # Removing active tab { push @tabs, $widget->add_tab( Tickit::Widget::Static->new( text => "Widget 3" ), label => "tab3", ); flush_tickit; $widget->remove_tab( 1 ); splice @tabs, 1, 1, (); is( $widget->active_tab_index, 1, '$widget->active_tab_index after ->remove active' ); ok( !$tabs[0]->is_active, '$tabs[0] is not active after ->remove_tab active' ); ok( $tabs[1]->is_active, '$tabs[1] is active after ->remove_tab active' ); identical( $widget->active_tab, $tabs[1], '$widget->active_tab is $tabs[1] after ->remove_tab active' ); flush_tickit; is_display( [ [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab3",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 3")] ], 'Display after ->remove_tab active' ); } $widget->set_window( undef ); is_oneref( $widget, '$widget still has refcount 1 before EOF' ); done_testing; Tickit-Widget-Tabbed-0.026/t/31-change-orientation.t0000644000175000017500000000160514200221670020113 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); $widget->set_window( $win ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_ content" ), label => "label$_" ) for 1 .. 3; flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("label1",fg=>14,bg=>4), TEXT("]label2 label3",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 1 content")] ], 'Display initially' ); $widget->tab_position( "left" ); flush_tickit; is_display( [ [TEXT("label1",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Widget 1 content")], [TEXT("label2 ",fg=>7,bg=>4)], [TEXT("label3 ",fg=>7,bg=>4)] ], 'Display after ->tab_position change orientation' ); done_testing; Tickit-Widget-Tabbed-0.026/t/11-labels-horizontal.t0000644000175000017500000000331714200221670017766 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); my $tab = $widget->add_tab( Tickit::Widget::Static->new( text => "Widget" ), label => "tab" ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget")] ], 'Display initially' ); $tab->set_label( "newlabel" ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("newlabel",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget")] ], 'Display after ->set_label' ); # Narrow rendering $widget->set_window( undef ); my $subwin = $win->make_sub( 0, 0, 10, 30 ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget $_" ), label => "tab$_" ) for 1..10; # Should be too narrow now $widget->set_window( $subwin ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("newlabel",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("tab1 tab2 tab3 ta",fg=>7,bg=>4), TEXT("..>",fg=>6,bg=>4), TEXT("",bg=>4)], [TEXT("Widget")] ], 'Display with narrow truncation' ); $widget->activate_tab( 7 ); flush_tickit; is_display( [ [TEXT("<..",fg=>6,bg=>4), TEXT("5 tab6[",fg=>7,bg=>4), TEXT("tab7",fg=>14,bg=>4), TEXT("]tab8 tab9 tab10",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget 7")] ], 'Display scrolls ribbon to active tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/13-children-horizontal.t0000644000175000017500000000215514200221670020315 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::VBox; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); my $tab = $widget->add_tab( my $vbox = Tickit::Widget::VBox->new, label => "tab" ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("")] ], 'Display initially' ); $vbox->add( Tickit::Widget::Static->new( text => "Static" ) ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Static")] ], 'Display after $vbox->add' ); $vbox->add( Tickit::Widget::Static->new( text => "More static" ) ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Static")], [TEXT("More static")] ], 'Display after $vbox->add again' ); done_testing; Tickit-Widget-Tabbed-0.026/t/00-pod.t0000755000175000017500000000025714200221670015120 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Tickit-Widget-Tabbed-0.026/t/12-pens-vertical.t0000644000175000017500000000275014200221670017112 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "left" ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget" ), label => "tab" ); my $tab = $widget->add_tab( Tickit::Widget::Static->new( text => "Widget 2" ), label => "othertab" ); is( $widget->lines, 2, '$widget->lines' ); # 2 tabs is( $widget->cols, 18, '$widget->cols' ); # 8 + 2 + 8 $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>4), TEXT(" >>>>>>",fg=>7,bg=>4), TEXT("Widget")], [TEXT("othertab ",fg=>7,bg=>4)] ], 'Display initially' ); $widget->set_style(ribbon_bg => 2); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>2), TEXT(" >>>>>>",fg=>7,bg=>2), TEXT("Widget")], [TEXT("othertab ",fg=>7,bg=>2)] ], 'Display after pen_tabs ->chattr' ); $widget->set_style(active_b => 1); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>2,b=>1), TEXT(" >>>>>>",fg=>7,bg=>2), TEXT("Widget")], [TEXT("othertab ",fg=>7,bg=>2)] ], 'Display after pen_active ->chattr' ); $tab->set_pen( Tickit::Pen->new( fg => 1 ) ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>2,b=>1), TEXT(" >>>>>>",fg=>7,bg=>2), TEXT("Widget")], [TEXT("othertab",fg=>1,bg=>2), TEXT(" ",fg=>7,bg=>2)] ], 'Display after tab set_pen' ); done_testing; Tickit-Widget-Tabbed-0.026/t/10-render-bottom.t0000644000175000017500000001021314200221670017106 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my @statics = map { Tickit::Widget::Static->new( text => "Widget $_" ) } 0 .. 2; my $widget = Tickit::Widget::Tabbed->new( tab_position => "bottom" ); ok( defined $widget, 'defined $widget' ); $widget->add_tab( $statics[$_], label => "tab$_" ) for 0 .. $#statics; $widget->set_window( $win ); ok( defined $statics[0]->window, '$static has window after ->set_window $win' ); flush_tickit; is_termlog( { "0,0" => [ SETPEN, PRINT("Widget 0"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 1 .. 23 ), "24,0" => [ SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETBG(4), ERASECH(65) ], }, 'Termlog initially' ); is_display( [ [TEXT("Widget 0")], BLANKLINES(23), [TEXT("[",fg=>7,bg=>4), TEXT("tab0",fg=>14,bg=>4), TEXT("]tab1 tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)] ], 'Display initially' ); $widget->next_tab; flush_tickit; is_termlog( { "0,0" => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 1 .. 23 ), "24,0" => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETBG(4), ERASECH(65) ], }, 'Termlog after ->next_tab' ); is_display( [ [TEXT("Widget 1")], BLANKLINES(23), [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 ",fg=>7,bg=>4), TEXT("",bg=>4)] ], 'Display after ->next_tab' ); $widget->add_tab( Tickit::Widget::Static->new( text => "Another static" ), label => "newtab" ); flush_tickit; is_termlog( { # Tickit::Window 0.45 optimised away ->expose on invisible windows ( $Tickit::Window::VERSION >= '0.45' ? () : ( "0,0" => [ SETPEN, PRINT("Widget 1"), SETBG(undef), ERASECH(72) ], ( map { +"$_,0" => [ SETBG(undef), ERASECH(80) ] } 1 .. 23 ) ) ), "24,0" => [ SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("tab0"), SETPEN(fg => 7,bg => 4), PRINT("["), SETPEN(fg => 14,bg => 4), PRINT("tab1"), SETPEN(fg => 7,bg => 4), PRINT("]"), SETPEN(fg => 7,bg => 4), PRINT("tab2"), SETPEN(fg => 7,bg => 4), PRINT(" "), SETPEN(fg => 7,bg => 4), PRINT("newtab"), SETBG(4), ERASECH(58) ], }, 'Termlog after ->add_tab' ); is_display( [ [TEXT("Widget 1")], BLANKLINES(23), [TEXT(" tab0[",fg=>7,bg=>4), TEXT("tab1",fg=>14,bg=>4), TEXT("]tab2 newtab ",fg=>7,bg=>4), TEXT("",bg=>4)] ], 'Display after ->add_tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/12-pens-horizontal.t0000644000175000017500000000310214200221670017462 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); $widget->add_tab( Tickit::Widget::Static->new( text => "Widget" ), label => "tab" ); my $tab = $widget->add_tab( Tickit::Widget::Static->new( text => "Widget 2" ), label => "othertab" ); is( $widget->lines, 2, '$widget->lines' ); # 1 for Widgets, 1 for ribbon is( $widget->cols, 14, '$widget->cols' ); # 1 + 3 + 1 + 8 + 1 $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("tab",fg=>14,bg=>4), TEXT("]othertab ",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Widget")] ], 'Display initially' ); $widget->set_style(ribbon_bg => 2); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>2), TEXT("tab",fg=>14,bg=>2), TEXT("]othertab ",fg=>7,bg=>2), TEXT("",bg=>2)], [TEXT("Widget")] ], 'Display after pen_tabs ->chattr' ); $widget->set_style(active_b => 1); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>2), TEXT("tab",fg=>14,bg=>2,b=>1), TEXT("]othertab ",fg=>7,bg=>2), TEXT("",bg=>2)], [TEXT("Widget")] ], 'Display after pen_active ->chattr' ); $tab->set_pen( Tickit::Pen->new( fg => 1 ) ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>2), TEXT("tab",fg=>14,bg=>2,b=>1), TEXT("]",fg=>7,bg=>2), TEXT("othertab",fg=>1,bg=>2), TEXT(" ",fg=>7,bg=>2), TEXT("",bg=>2)], [TEXT("Widget")] ], 'Display after tab set_pen' ); done_testing; Tickit-Widget-Tabbed-0.026/t/22-tabs-late.t0000644000175000017500000000122714200221670016211 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "top" ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("",bg=>4)] ], 'Display initially blank' ); $widget->add_tab( Tickit::Widget::Static->new( text => "Late widget" ), label => "Late tab" ); flush_tickit; is_display( [ [TEXT("[",fg=>7,bg=>4), TEXT("Late tab",fg=>14,bg=>4), TEXT("]",fg=>7,bg=>4), TEXT("",bg=>4)], [TEXT("Late widget")] ], 'Display after ->add_tab' ); done_testing; Tickit-Widget-Tabbed-0.026/t/13-children-vertical.t0000644000175000017500000000174114200221670017735 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use Tickit::Test; use Tickit::Widget::Static; use Tickit::Widget::VBox; use Tickit::Widget::Tabbed; my $win = mk_window; my $widget = Tickit::Widget::Tabbed->new( tab_position => "left" ); my $tab = $widget->add_tab( my $vbox = Tickit::Widget::VBox->new, label => "tab" ); $widget->set_window( $win ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("")] ], 'Display initially' ); $vbox->add( Tickit::Widget::Static->new( text => "Static" ) ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Static")] ], 'Display after $vbox->add' ); $vbox->add( Tickit::Widget::Static->new( text => "More static" ) ); flush_tickit; is_display( [ [TEXT("tab",fg=>14,bg=>4), TEXT(" >",fg=>7,bg=>4), TEXT("Static")], [TEXT(" ",bg=>4), TEXT("More static")] ], 'Display after $vbox->add again' ); done_testing; Tickit-Widget-Tabbed-0.026/dist.ini0000644000175000017500000000111614200221670015125 0ustar leoleoname = Tickit-Widget-Tabbed author = Tom Molesworth license = Perl_5 copyright_holder = Tom Molesworth copyright_year = 2011 main_module = lib/Tickit/Widget/Tabbed.pm [@Basic] [Prereqs] List::Util = 1.26 Scalar::Util = 0 Tickit::ContainerWidget = 0.44 Tickit::Widget = 0.36 Tickit::Window = 0.57 parent = 0 perl = 5.010 [Prereqs / TestRequires] Test::Identity = 0 Test::More = 0.88 Test::Refcount = 0 Tickit::Test = 0.43 Tickit::Widget::Static = 0 Tickit::Widget::VBox = 0 Tickit::Window = 0.17 [NextRelease] [VersionFromModule] [PodVersion] [PkgVersion]