Subject: | Support multi-line ribbon |
Doesn't look like 0.010 has this yet, so here's a minor patch to allow ribbon with multiple lines like ingy's screenshot in the github repo. Includes a modified version of the custom ribbon demo as an example of how it might look.
cheers,
Tom
Subject: | demo-custom-ribbon.pl |
#!/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",
);
# $tabbed->pen_active->chattrs( { b => 1, 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 IndexCard;
use base qw( Tickit::Widget::Tabbed::Ribbon );
sub lines { 3 }
package IndexCard::horizontal;
use base qw( IndexCard );
use Tickit::RenderBuffer qw(LINE_SINGLE);
use Tickit::Utils qw( textwidth );
sub lines { 3 }
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 = Tickit::Pen->new(fg => 'grey', bg => 0, b => 0);
my $active_pen = Tickit::Pen->new(fg => 'hi-green', bg => 'black');
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 ? $active_pen : $pen);
$x += $len + 4;
}
}
sub scroll_to_visible { }
Subject: | multi-line-ribbon.patch |
=== modified file 'lib/Tickit/Widget/Tabbed.pm'
--- lib/Tickit/Widget/Tabbed.pm 2013-07-15 02:13:02 +0000
+++ lib/Tickit/Widget/Tabbed.pm 2013-08-24 22:22:10 +0000
@@ -154,14 +154,20 @@
sub _window_position_top {
my $self = shift;
- return 0, 0, 1, $self->window->cols,
- 1, 0, $self->window->lines - 1, $self->window->cols;
+ 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;
- return $self->window->lines - 1, 0, 1, $self->window->cols,
- 0, 0, $self->window->lines - 1, $self->window->cols;
+ 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 {