Re: Alignment of labels in table
- From: muppet <scott asofyet org>
- To: Peter Daum <gator_ml yahoo de>
- Cc: gtk-perl-list gnome org
- Subject: Re: Alignment of labels in table
- Date: Sun, 13 Nov 2005 15:33:05 -0500
On Nov 13, 2005, at 2:43 PM, Peter Daum wrote:
muppet wrote:
[...]
So, the trick is to make sure that the label, which is set to
align to the left, is allocated all the space of the place where
you want it to go. In Gtk2::Table's packing terms, that means
the x options must contain "fill", which means "the child should
be allocated all the space of the cell, or, should fill the
cell". You specified "shrink", which allocates the child exactly
as much space as it asked for, and therefore your alignment
settings are ignored.
Thanks a lot - now it works as intended!
Still, I am a little confused. Does this mean, that packed with
'shrink',
the label does not even get a whole table cell, but only the center
portion, with space to the left and to the right within the cell left
unallocated?
Expand and shrink have to do with the behavior of the cell. Fill has
to do with the behavior of the child within the cell.
Play with this script for a while and perhaps you'll get the feel for
it. Hint: resize the window and stretch the haned's gutter.
For those just playing along, this program illustrates using
container child properties, making a haned's second child sticky,
using named colors, vectorization of operations, and using multiple
columns in a combo box model but not in the view.
-=-=-=- table_packing.pl -=-=-=-=-=-
#!/usr/bin/perl -w
use strict;
use Glib qw(:constants);
use Gtk2 -init;
my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit});
my $hpaned = Gtk2::HPaned->new;
$window->add ($hpaned);
my $table = Gtk2::Table->new (2, 2);
$hpaned->add1 ($table);
my $vbox = Gtk2::VBox->new;
$hpaned->add2 ($vbox);
$hpaned->child1_resize (TRUE);
$hpaned->child2_resize (FALSE);
my $combo_model = Gtk2::ListStore->new ('Gtk2::AttachOptions',
'Glib::String');
foreach ({name => 'expand', value => ['expand'] },
{name => 'fill', value => ['fill'] },
{name => 'shrink', value => ['shrink'] },
{name => 'expand+fill', value => ['expand', 'fill']}) {
$combo_model->set ($combo_model->append,
0, $_->{value},
1, $_->{name});
}
foreach ([0, 1, 0, 1, "red"],
[0, 1, 1, 2, "green"],
[1, 2, 0, 1, "blue"],
[1, 2, 1, 2, "orange"]) {
my ($left, $right, $top, $bottom, $color_name) = @$_;
my $color = Gtk2::Gdk::Color->parse ($color_name);
my $event_box = Gtk2::EventBox->new;
my $label = Gtk2::Label->new ("$left $right $top $bottom");
$event_box->modify_bg (normal => $color);
$event_box->add ($label);
$label->show;
$table->attach_defaults ($event_box, $left, $right, $top, $bottom);
$label = Gtk2::Label->new ("$left $right $top $bottom");
$label->modify_fg (normal => $color);
$vbox->pack_start ($label, FALSE, FALSE, 0);
my $combo_box = Gtk2::ComboBox->new ($combo_model);
my $cell = Gtk2::CellRendererText->new;
$combo_box->pack_start ($cell, TRUE);
$combo_box->add_attribute ($cell, text => 1);
$combo_box->signal_connect (changed => sub {
my ($combo_box, $child) = @_;
my $new_x_options =
$combo_box->get_model->get
($combo_box->get_active_iter, 0);
$table->child_set ($child, x_options => $new_x_options);
}, $event_box);
$combo_box->set_active (0);
$vbox->pack_start ($combo_box, FALSE, FALSE, 0);
}
$window->show_all;
Gtk2->main;
-=-=-=-=-=-=-
--
"it's hard to be eventful when you have this much style."
- me, rationalizing yet another night of sitting at home.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]