Re: Alignment of labels in table




On Nov 13, 2005, at 1:31 PM, Peter Daum wrote:

I am trying to create a (table-based) form with left-aligned labels.
In the Example below, the text in the left column is always centered,
no matter what I do with "set_alignment" or "set_justify".
What am I missing?

set_justify only pertains to multiline labels -- it tells pango how to align the lines of the paragraph.

set_alignment tells Gtk2::Misc (Gtk2::Label's parent class) where to place the contents of the widget when it is allocated more space than it requests.

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.


 my $window = new Gtk2::Window( "toplevel" );
 my $t=new Gtk2::Table(2,2,0);
 $window->add($t);
 my $l1=Gtk2::Label->new('a');
 my $l2=Gtk2::Label->new('bla blasdf');
 my $l3=Gtk2::Label->new('Zsdf bla sdflks');
 my $l4=Gtk2::Label->new('bla');

$l1->set_alignment (0.0, 0.5);
$l2->set_alignment (0.0, 0.5);
$l3->set_alignment (0.0, 0.5);
$l4->set_alignment (0.0, 0.5);

 $t->attach($l1,0,1,0,1,'shrink','shrink',10,10);

$t->attach($l1,0,1,0,1,'fill','string',10,10);

 $t->attach($l2,1,2,0,1,['expand','fill'],'expand',10,10);
 $t->attach($l3,0,1,1,2,'shrink','shrink',10,10);

$t->attach($l3,0,1,0,1,'fill','string',10,10);

 $t->attach($l4,1,2,1,2,['expand','fill'],'expand',10,10);




--
That's it! It's one thing for a ghost to scare my children, but it's another to play my theremin!
  - Homer Simpson




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]