Hey thanos1983, thanks for your suggestion!
It suddenly occured to me, while fiddling with ->set_tab_border(), that it might be the stock icon that was preventing the label from becoming smaller.
Sure enough, removing the stock icon altogether reduces the tab's size dramatically. Using a smaller stock icon is also effective:
$noteBook->set_tab_border(0);
$button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'menu'));
Here's the corrected script:
#!/usr/bin/perl
package biglabel;
use strict;
use diagnostics;
use warnings;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
# Create the window
my $window = Gtk2::Window->new();
$window->set_title('Notebook');
$window->set_position('center');
$window->set_default_size(800, 500);
$window->set_border_width(5);
$window->signal_connect (destroy => sub { Gtk2->main_quit; });
# Add a VBox with a VPaned, containing a notebook at the top and an en
+try at the bottom
my $vBox = Gtk2::VBox->new(FALSE, 0);
my $vPaned = Gtk2::VPaned->new();
$vPaned->set_position(400);
$vBox->pack_start($vPaned, TRUE, TRUE, 0);
my $noteBook = Gtk2::Notebook->new();
$noteBook->set_scrollable(TRUE);
$noteBook->can_focus(FALSE);
$noteBook->set_tab_border(0);
$vPaned->add($noteBook);
my $entry = Gtk2::Entry->new();
$entry->can_focus(TRUE);
$vPaned->add2($entry);
# Add three tabs to the notebook
for (my $num = 0; $num < 3; $num++) {
my ($buffer, $tabNum) = openTab($noteBook);
}
# Open the window
$window->add($vBox);
$window->show_all();
Gtk2->main();
####################
sub openTab {
# Create a tab in the notebook, containing a textview
my ($noteBook) = @_;
# The vertical packing box contains only a textview
my $vBox = Gtk2::VBox->new(FALSE, 0);
# The horizontal packing box is used as the tab's label (in pl
+ace of a Gtk2::Label)
my $hBox = Gtk2::HBox->new(FALSE, 0);
my $label = Gtk2::Label->new('Hello world');
$hBox->pack_start($label, FALSE, FALSE, 0);
my $button = Gtk2::Button->new();
$button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'm
+enu'));
$button->set_relief('none');
$button->signal_connect (clicked => sub {
# (Do nothing special)
});
$hBox->pack_start($button, FALSE, FALSE, 0);
$label->show();
$button->show();
my $tabNum = $noteBook->append_page($vBox, $hBox);
# Add a textview to the tab
my $frame = Gtk2::Frame->new(undef);
$frame->set_border_width(0);
my $scroll = Gtk2::ScrolledWindow->new(undef, undef);
$scroll->set_shadow_type('etched-out');
$scroll->set_policy('automatic', 'automatic');
$scroll->set_border_width(0);
my $textView = Gtk2::TextView->new();
my $buffer = Gtk2::TextBuffer->new();
$textView->set_buffer($buffer);
$textView->set_editable(FALSE);
$textView->set_cursor_visible(FALSE); # Invisible cursor
$textView->can_focus(FALSE);
$textView->set_wrap_mode('word-char'); # Wrap words if possib
+le, characters if not
$textView->set_justification('left');
$scroll->add($textView);
$frame->add($scroll);
$vBox->pack_start($frame, TRUE, TRUE, 0);
$window->show_all();
# The new tab should be the visible (current) one
$noteBook->set_current_page($tabNum);
return ($buffer, $tabNum);
}
|