Tickit-Widget-Tabbed-0.021/0002755000175000017500000000000013051070140013454 5ustar leoleoTickit-Widget-Tabbed-0.021/LICENSE0000644000175000017500000004370611654266142014511 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.021/examples/0002755000175000017500000000000013051070140015272 5ustar leoleoTickit-Widget-Tabbed-0.021/examples/demo-logtail.pl0000644000175000017500000000306312504120216020206 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.021/examples/demo-multiline-ribbon.pl0000644000175000017500000000431012504120216022022 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; package IndexCard; use base qw( Tickit::Widget::Tabbed::Ribbon ); sub lines { 3 } use Tickit::Style -copy; BEGIN { style_definition base => tab_fg => "grey", tab_bg => 0, tab_b => 0; } package IndexCard::horizontal; use base qw( IndexCard ); use Tickit::RenderBuffer qw(LINE_SINGLE); use Tickit::Utils qw( textwidth ); sub lines { 2 } sub cols { 1 } sub render_to_rb { my $self = shift; my ($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; } } sub scroll_to_visible { } Tickit-Widget-Tabbed-0.021/examples/demo-tabs.pl0000644000175000017500000000223012504120216017477 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.021/examples/demo-custom-ribbon.pl0000644000175000017500000000346612504120216021345 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; package CustomRibbon; use base qw( Tickit::Widget::Tabbed::Ribbon ); use Tickit::Style -copy; BEGIN { style_definition base => current_fg => 8; } package CustomRibbon::horizontal; use base qw( CustomRibbon ); use Tickit::Utils qw( textwidth ); sub lines { 1 } sub cols { 1 } sub render_to_rb { my $self = shift; my ( $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 ); } sub scroll_to_visible { } Tickit-Widget-Tabbed-0.021/dist.ini0000644000175000017500000000111612752103600015122 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] Tickit-Widget-Tabbed-0.021/lib/0002755000175000017500000000000013051070140014222 5ustar leoleoTickit-Widget-Tabbed-0.021/lib/Tickit/0002755000175000017500000000000013051070140015451 5ustar leoleoTickit-Widget-Tabbed-0.021/lib/Tickit/Widget/0002755000175000017500000000000013051070140016674 5ustar leoleoTickit-Widget-Tabbed-0.021/lib/Tickit/Widget/Tabbed/0002755000175000017500000000000013051070140020055 5ustar leoleoTickit-Widget-Tabbed-0.021/lib/Tickit/Widget/Tabbed/Ribbon.pm0000644000175000017500000004612513051070127021641 0ustar leoleo# You may distribute under the terms of the Artistic License (the same terms # as Perl itself) # # (C) Paul Evans, 2011-2015 -- leonerd@leonerd.org.uk package Tickit::Widget::Tabbed::Ribbon; use strict; use warnings; use base qw( Tickit::Widget ); Tickit::Window->VERSION( '0.57' ); # ->bind_event our $VERSION = '0.021'; use Scalar::Util qw( weaken ); 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; =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 { my $class = shift; my ( $orientation, @args ) = @_; return ${\"${class}::${orientation}"}->new( @args ); } sub new { my $class = shift; my %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?"; } my $self = $class->SUPER::new( %args ); my ( $prev_more, $next_more ) = $args{tabbed}->get_style_values(qw( more_left more_right )); $self->{prev_more} = [ $prev_more, textwidth $prev_more ]; $self->{next_more} = [ $next_more, textwidth $next_more ]; $self->{tabs} = []; push @{$self->{tabs}}, @{$args{tabs}} if $args{tabs}; $self->{scroll_offset} = 0; $self->{active_tab_index} = $args{active_tab_index} || 0; weaken( $self->{tabbed} = $args{tabbed} ); $self->scroll_to_visible( $self->{active_tab_index} ); return $self; } sub active_pen { my $self = shift; return $self->{tabbed}->get_style_pen( "active" ); } =head2 @tabs = $ribbon->tabs =head2 $count = $ribbon->tabs Returns a list of the contained L tab objects in list context, or the count of them in scalar context. =cut sub tabs { my $self = shift; return @{$self->{tabs}}; } sub _tab2index { my $self = shift; my ( $tab_or_index ) = @_; if( !ref $tab_or_index ) { croak "Invalid tab index" if $tab_or_index < 0 or $tab_or_index >= @{ $self->{tabs} }; return $tab_or_index; } return ( grep { $tab_or_index == $self->{tabs}[$_] } 0 .. $#{ $self->{tabs} } )[0]; } sub _pen_for_tab { my $self = shift; my ( $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 $index = $ribbon->active_tab_index Returns the index of the currently-active tab =cut sub active_tab_index { my $self = shift; return $self->{active_tab_index}; } =head2 $tab = $ribbon->active_tab Returns the currently-active tab as a C tab object. =cut sub active_tab { my $self = shift; return $self->{tabs}->[$self->{active_tab_index}]; } sub append_tab { my $self = shift; my ( $tab ) = @_; push @{$self->{tabs}}, $tab; $self->{tabbed}->_tabs_changed; $self->scroll_to_visible( undef ); } sub remove_tab { my $self = shift; my $del_index = $self->_tab2index( shift ); my $tabs = $self->{tabs}; my ( $tab ) = splice @$tabs, $del_index, 1, (); $tab->widget->window->close; if( $self->{active_tab_index} > $del_index ) { $self->{active_tab_index}--; } elsif( $self->{active_tab_index} == $del_index ) { $self->{active_tab_index}-- if $del_index == @$tabs; if( $self->active_tab ) { $self->active_tab->_activate; } else { $self->{tabbed}->window->expose; } } $self->{tabbed}->_tabs_changed; $self->scroll_to_visible( undef ); } sub move_tab { my $self = shift; my $old_index = $self->_tab2index( shift ); my $delta = shift; my $tabs = $self->{tabs}; 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 $self->{active_tab_index} += $delta if $self->{active_tab_index} == $old_index; $self->{active_tab_index}++ if $self->{active_tab_index} < $old_index and $self->{active_tab_index} >= $old_index + $delta; $self->{active_tab_index}-- if $self->{active_tab_index} > $old_index and $self->{active_tab_index} <= $old_index + $delta; $self->redraw; } sub activate_tab { my $self = shift; my $new_index = $self->_tab2index( shift ); return if $new_index == $self->{active_tab_index}; if(my $old_widget = $self->active_tab->widget) { $self->active_tab->_deactivate; } $self->{active_tab_index} = $new_index; $self->scroll_to_visible( $self->{active_tab_index} ); $self->redraw; if(my $tab = $self->active_tab) { $tab->_activate; } else { $self->window->clear; } return $self; } sub next_tab { my $self = shift; $self->activate_tab( ( $self->active_tab_index + 1 ) % $self->tabs ); } sub prev_tab { my $self = shift; $self->activate_tab( ( $self->active_tab_index - 1 ) % $self->tabs ); } sub on_pen_changed { my $self = shift; my ( $pen, $id ) = @_; $self->redraw; return $self->SUPER::on_pen_changed( @_ ); } sub on_key { 0 } sub on_mouse { 0 } package Tickit::Widget::Tabbed::Ribbon::horizontal; use base qw( Tickit::Widget::Tabbed::Ribbon ); use constant orientation => "horizontal"; use List::Util qw( sum0 ); sub new { my $class = shift; my %args = @_; my $self = $class->SUPER::new( %args ); $self->{active_marker} = $args{active_marker} || [ "[", "]" ]; return $self; } sub lines { 1 } sub cols { my $self = shift; return sum0(map { $_->label_width + 1 } $self->tabs) + 1; } sub reshape { my $self = shift; my $win = $self->window or return; $self->scroll_to_visible( undef ); my $prev_more = $self->{prev_more}; if( $prev_more->[2] ) { $prev_more->[2]->change_geometry( 0, 0, 1, $prev_more->[1], ); } my $next_more = $self->{next_more}; if( $next_more->[2] ) { $next_more->[2]->change_geometry( 0, $win->cols - $next_more->[1], 1, $next_more->[1], ); } } sub render_to_rb { my $self = shift; my ( $rb, $rect ) = @_; $rect->top == 0 or return; $rect->bottom == 1 or return; $rb->goto(0, -$self->{scroll_offset}); my $prev_active; foreach my $tab ($self->tabs) { my $active = $tab->is_active; $rb->text($active ? $self->{active_marker}[0] : $prev_active ? $self->{active_marker}[1] : ' '); $rb->text($tab->label, $self->_pen_for_tab($tab)); $prev_active = $active; } if($prev_active) { $rb->text($self->{active_marker}[1]); } $rb->erase_to($self->window->cols); } sub _col2tab { my $self = shift; my ( $col ) = @_; $col += $self->{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; } sub scroll_to_visible { my $self = shift; my ( $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 = $self->{scroll_offset}; my $want_prev_more = defined $prev_more->[2]; my $want_next_more = defined $next_more->[2]; { 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->[1] : 0; my $right_margin = $want_next_more ? $cols - $next_more->[1] : $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; } } $self->{scroll_offset} = $ofs; if( $want_prev_more and !$prev_more->[2] ) { my $w = $win->make_float( 0, 0, 1, $prev_more->[1], ); $prev_more->[2] = $w; $w->set_pen( $self->{tabbed}->get_style_pen( "more" ) ); $w->bind_event( expose => sub { my ( $win, undef, $info ) = @_; $info->rb->text_at( 0, 0, $prev_more->[0] ); }); $w->bind_event( mouse => sub { my ( $win, undef, $info ) = @_; $self->_scroll_left if $info->type eq "press" && $info->button == 1; return 1; } ); } elsif( !$want_prev_more and $prev_more->[2] ) { $prev_more->[2]->hide; undef $prev_more->[2]; } if( $want_next_more and !$next_more->[2] ) { my $w = $win->make_float( 0, $win->cols - $next_more->[1], 1, $next_more->[1], ); $next_more->[2] = $w; $w->set_pen( $self->{tabbed}->get_style_pen( "more" ) ); $w->bind_event( expose => sub { my ( $win, undef, $info ) = @_; $info->rb->text_at( 0, 0, $next_more->[0] ); } ); $w->bind_event( mouse => sub { my ( $win, undef, $info ) = @_; $self->_scroll_right if $info->type eq "press" && $info->button == 1; return 1; } ); } elsif( !$want_next_more and $next_more->[2] ) { $next_more->[2]->hide; undef $next_more->[2]; } } sub _scroll_left { my $self = shift; my $win = $self->window or return; $self->{scroll_offset} -= int( $win->cols / 2 ); $self->{scroll_offset} = 0 if $self->{scroll_offset} < 0; $self->scroll_to_visible( undef ); $self->redraw; } sub _scroll_right { my $self = shift; my $win = $self->window or return; $self->{scroll_offset} += int( $win->cols / 2 ); $self->scroll_to_visible( undef ); $self->redraw; } sub on_key { my $self = shift; my ( $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; } } sub on_mouse { my $self = shift; my ( $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 ); } package Tickit::Widget::Tabbed::Ribbon::vertical; use base qw( Tickit::Widget::Tabbed::Ribbon ); use constant orientation => "vertical"; use List::Util qw( max ); sub new { my $class = shift; my %args = @_; my $self = $class->SUPER::new( %args ); $self->{tab_position} = $args{tab_position}; return $self; } sub lines { my $self = shift; return scalar $self->tabs; } sub cols { my $self = shift; return 2 + max(0, map { $_->label_width } $self->tabs); } sub reshape { my $self = shift; my $win = $self->window or return; $self->scroll_to_visible( undef ); my $prev_more = $self->{prev_more}; if( $prev_more->[2] ) { $prev_more->[2]->change_geometry( 0, 0, 1, $win->cols, ); } my $next_more = $self->{next_more}; if( $next_more->[2] ) { $next_more->[2]->change_geometry( $win->lines - 1, $win->cols, 1, $win->cols, ); } } sub render_to_rb { my $self = shift; my ( $rb, $rect ) = @_; my $lines = $self->window->lines; my $cols = $self->window->cols; my $pos = $self->{tab_position}; my $next_line = -$self->{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($pos eq 'left') { $rb->text($tab->label, $self->_pen_for_tab($tab)); $rb->text($active ? (' ' . ('>' x ($spare - 1))) : (' ' x $spare)); } elsif($pos 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; } } sub scroll_to_visible { my $self = shift; my ( $idx ) = @_; defined $idx or return; my $win = $self->window or return; my $lines = $win->lines; my $halfheight = int( $lines / 2 ); my $ofs = $self->{scroll_offset}; { my $line = -$ofs; $line += $idx; if( $line < 0 ) { $ofs -= $halfheight; $ofs = 0 if $ofs < 0; redo; } if( $line >= $lines ) { $ofs += $halfheight; redo; } } $self->{scroll_offset} = $ofs; } sub _showhide_more_markers { } sub on_key { my $self = shift; my ( $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; } } sub on_mouse { my $self = shift; my ( $ev ) = @_; my $line = $ev->line; $line += $self->{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 $ribbon->render( %args ) =head2 $lines = $ribbon->lines =head2 $cols = $ribbon->cols As per the L methods. =head2 $handled = $ribbon->on_key( $ev ) =head2 $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 $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.021/lib/Tickit/Widget/Tabbed.pm0000644000175000017500000003755013051070127020430 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 package Tickit::Widget::Tabbed; use strict; use warnings; use parent qw(Tickit::ContainerWidget); BEGIN { 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; our $VERSION = '0.021'; =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 sub TAB_CLASS { shift->{tab_class} || "Tickit::Widget::Tabbed::Tab" } sub RIBBON_CLASS { shift->{ribbon_class} || "Tickit::Widget::Tabbed::Ribbon" } =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 sub new { my $class = shift; my %args = @_; my $self = $class->SUPER::new(%args); $self->{tab_class} = delete($args{tab_class}); $self->{ribbon_class} = delete($args{ribbon_class}); $self->tab_position(delete($args{tab_position}) || 'top'); my $ribbon = $self->{ribbon}; $ribbon->set_style( $self->get_style_pen("ribbon")->getattrs ); return $self; } # Positions for the four screen edges - these will return appropriate sizes # for the tab and child subwindows sub _window_position_left { my $self = shift; my $ribbon = $self->{ribbon}; my $label_width = $ribbon->cols; return 0, 0, $self->window->lines, $label_width, 0, $label_width, $self->window->lines, $self->window->cols - $label_width; } sub _window_position_right { my $self = shift; my $ribbon = $self->{ribbon}; 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; } sub _window_position_top { my $self = shift; my $ribbon = $self->{ribbon}; 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; } sub _window_position_bottom { my $self = shift; my $ribbon = $self->{ribbon}; 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; } sub on_style_changed_values { my $self = shift; my %values = @_; if( grep { $_ =~ m/^ribbon_/ } keys %values ) { $self->{ribbon}->set_style( $self->get_style_pen("ribbon")->getattrs ); } } sub reshape { my $self = shift; my $window = $self->window or return; my $tab_position = $self->tab_position; my @positions = $self->${\"_window_position_$tab_position"}(); if( my $ribbon_window = $self->{ribbon}->window ) { $ribbon_window->change_geometry( @positions[0..3] ); } else { my $ribbon_window = $window->make_sub( @positions[0..3] ); $self->{ribbon}->set_window( $ribbon_window ); } $self->{child_window_geometry} = [ @positions[4..7] ]; foreach my $tab ( $self->{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); } } } sub _max_child_lines { my $self = shift; my $ribbon = $self->{ribbon}; return max( 1, map { $_->widget->requested_lines } $ribbon->tabs ); } sub _max_child_cols { my $self = shift; my $ribbon = $self->{ribbon}; return max( 1, map { $_->widget->requested_cols } $ribbon->tabs ); } sub lines { my $self = shift; my $ribbon = $self->{ribbon}; if( $ribbon->orientation eq "horizontal" ) { return $ribbon->lines + $self->_max_child_lines; } else { return max( $ribbon->lines, $self->_max_child_lines ); } } sub cols { my $self = shift; my $ribbon = $self->{ribbon}; 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 sub children { my $self = shift; my $ribbon = $self->{ribbon}; return $ribbon, map { $_->widget } $ribbon->tabs; } # The only focusable child widget is the active one sub children_for_focus { my $self = shift; return $self->active_tab_widget; } sub _new_child_window { my $self = shift; my ( $visible ) = @_; my $window = $self->window or return undef; my $child_window = $window->make_hidden_sub( @{ $self->{child_window_geometry} } ); $child_window->show if $visible; return $child_window; } sub window_lost { my $self = shift; $self->SUPER::window_lost(@_); $_->widget->set_window(undef) for $self->{ribbon}->tabs; undef $self->{child_window_geometry}; $self->{ribbon}->set_window(undef); } =head2 tab_position Accessor for the tab position (top, left, right, bottom). =cut sub tab_position { my $self = shift; if(@_) { my $pos = shift; 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( !$self->{ribbon} or $self->{ribbon}->orientation ne $orientation ) { my %args = ( tabbed => $self, tab_position => $pos, ); if( my $old_ribbon = $self->{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 $self->{ribbon}; } $self->{ribbon} = $self->RIBBON_CLASS->new_for_orientation( $orientation, %args ); $self->{ribbon}->set_style( $args{pen}->getattrs ) if $args{pen}; } $self->{tab_position} = $pos; undef $self->{child_window_geometry}; $self->reshape if $self->window; $self->redraw; } return $self->{tab_position}; } sub _tabs_changed { my $self = shift; $self->reshape if $self->window; $self->{ribbon}->redraw if $self->{ribbon}->window; } =head2 active_tab_index Returns the 0-based index of the currently-active tab. =cut sub active_tab_index { shift->{ribbon}->active_tab_index } =head2 active_tab Returns the currently-active tab as a tab object. See below. =cut sub active_tab { shift->{ribbon}->active_tab } =head2 active_tab_widget Returns the widget in the currently active tab. =cut # Old name *tab = \&active_tab_widget; sub active_tab_widget { my $self = shift; $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 sub add_tab { my $self = shift; my ($child, %opts) = @_; my $ribbon = $self->{ribbon}; 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 sub remove_tab { shift->{ribbon}->remove_tab( @_ ) } =head2 move_tab Move tab given by 0-based index or tab object forward the given number of positions. =cut sub move_tab { shift->{ribbon}->move_tab( @_ ) } =head2 activate_tab Switch to the given tab; by 0-based index, or object. =cut sub activate_tab { shift->{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; sub next_tab { shift->{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; sub prev_tab { shift->{ribbon}->prev_tab } sub child_resized { my $self = shift; $self->reshape; } sub on_key { my $self = shift; my ($ev) = @_; return 1 if $self->{ribbon}->on_key(@_); 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 < $self->{ribbon}->tabs; return 1; } return 0; } sub render_to_rb { my $self = shift; my ( $rb, $rect ) = @_; # Just clear the child area if we have nothing better to do $rb->eraserect( $rect ); } package Tickit::Widget::Tabbed::Tab; use 5.010; # for //= operator use Scalar::Util qw( weaken ); 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 new { my $class = shift; my ( $tabbed, %args ) = @_; my $self = bless { tabbed => $tabbed, widget => $args{widget}, label => $args{label}, active => 0, }, $class; weaken( $self->{tabbed} ); return $self; } =head2 index Returns the 0-based index of this tab =cut sub index { my $self = shift; return $self->{tabbed}->{ribbon}->_tab2index( $self ); } =head2 widget Returns the C contained by this tab =cut sub widget { shift->{widget} } =head2 label Returns the current label text =cut sub label_width { my $self = shift; return $self->{label_width} //= textwidth( $self->{label} ); } sub label { shift->{label} } =head2 set_label Set new label text for the tab =cut sub set_label { my $self = shift; ( $self->{label} ) = @_; undef $self->{label_width}; $self->{tabbed}->_tabs_changed if $self->{tabbed}; } =head2 is_active Returns true if this tab is the currently active one =cut sub is_active { my $self = shift; return $self->{tabbed}->active_tab == $self; } =head2 activate Activate this tab =cut sub activate { my $self = shift; $self->{tabbed}->activate_tab( $self ); } sub _activate { my $self = shift; $self->widget->window->show if $self->widget->window; $self->${\$self->{on_activated}}() if $self->{on_activated}; } sub _deactivate { my $self = shift; $self->${\$self->{on_deactivated}}() if $self->{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 sub set_on_activated { my $self = shift; ( $self->{on_activated} ) = @_; } =head2 set_on_deactivated Set a callback or method name to invoke when the tab is deactivated =cut sub set_on_deactivated { my $self = shift; ( $self->{on_deactivated} ) = @_; } =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 sub _has_pen { defined shift->{pen} } sub pen { my $self = shift; return $self->{pen}; } sub set_pen { my $self = shift; ( $self->{pen} ) = @_; $self->{tabbed}->_tabs_changed if $self->{tabbed}; } sub on_mouse { my $self = shift; my ( $type, $button, $line, $col ) = @_; return 0 unless $type eq "press" && $button == 1; $self->{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 with a constructor having the following behaviour: sub new { my $class = shift; my ( $tabbed, %args ) = @_; ... my $self = $class->SUPER::new( $tabbed, %args ); ... return $self; } 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 => "Tab::Class::Name" ); or use constant TAB_CLASS => "Tab::Class::Name"; =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.021/MANIFEST0000644000175000017500000000135213051070140014604 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 META.yml 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.json Module JSON meta-data (added by MakeMaker) Tickit-Widget-Tabbed-0.021/META.json0000644000175000017500000000257213051070140015101 0ustar leoleo{ "abstract" : "Basic tabbed window support", "author" : [ "Tom Molesworth " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.1002, CPAN::Meta::Converter version 2.150005", "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", "Scalar::Util" : "0", "Tickit::ContainerWidget" : "0.44", "Tickit::Widget" : "0.36", "Tickit::Window" : "0.28", "parent" : "0", "perl" : "5.010" } } }, "release_status" : "stable", "version" : "0.021", "x_serialization_backend" : "JSON::PP version 2.27400" } Tickit-Widget-Tabbed-0.021/t/0002755000175000017500000000000013051070140013717 5ustar leoleoTickit-Widget-Tabbed-0.021/t/10-render-right.t0000644000175000017500000001207012504120216016714 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.021/t/13-children-vertical.t0000644000175000017500000000174112504120216017727 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.021/t/23-tab-subclass.t0000644000175000017500000000154612504120216016717 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.021/t/22-tabs-late.t0000644000175000017500000000122712504120216016203 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.021/t/11-labels-vertical.t0000644000175000017500000000320412504120216017373 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.021/t/10-render-top.t0000644000175000017500000001002512504120216016377 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.021/t/11-labels-horizontal.t0000644000175000017500000000331712504120216017760 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.021/t/00-use.t0000755000175000017500000000015612320565073015134 0ustar leoleo#!/usr/bin/perl use strict; use warnings; use Test::More; use_ok('Tickit::Widget::Tabbed'); done_testing; Tickit-Widget-Tabbed-0.021/t/13-children-horizontal.t0000644000175000017500000000215512504120216020307 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.021/t/31-change-orientation.t0000644000175000017500000000160512504120216020105 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.021/t/14-input-horizontal.t0000644000175000017500000000360712504120216017662 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.021/t/30-remove-last.t0000644000175000017500000000132412504120216016562 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.021/t/12-pens-horizontal.t0000644000175000017500000000310212536405371017471 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.021/t/21-tab-activate.t0000644000175000017500000000170212504120216016670 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.021/t/14-input-vertical.t0000644000175000017500000000377512504120216017310 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.021/t/20-tabs.t0000644000175000017500000001175712504120216015267 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.021/t/10-render-bottom.t0000644000175000017500000001021312504120216017100 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.021/t/00-pod.t0000755000175000017500000000025712320565073015124 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.021/t/12-pens-vertical.t0000644000175000017500000000275012536405371017121 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.021/t/10-render-left.t0000644000175000017500000001175012504120216016535 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.021/Changes0000644000175000017500000001004313051070127014750 0ustar leoleoRevision history for Tickit-Widget-Tabbed 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.021/Makefile.PL0000644000175000017500000000263212752103600015434 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.010", "NAME" => "Tickit::Widget::Tabbed", "PREREQ_PM" => { "List::Util" => "1.26", "Scalar::Util" => 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" } ); 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.021/README0000644000175000017500000000045711654266142014360 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.021/META.yml0000644000175000017500000000152713051070140014730 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.1002, CPAN::Meta::Converter version 2.150005' 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 requires: List::Util: '1.26' Scalar::Util: '0' Tickit::ContainerWidget: '0.44' Tickit::Widget: '0.36' Tickit::Window: '0.28' parent: '0' perl: '5.010' version: '0.021' x_serialization_backend: 'CPAN::Meta::YAML version 0.018'