Aligning in a Table

View: New views
3 Messages — Rating Filter:   Alert me  

Aligning in a Table

by Dominik-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I'm sure this is easy to answer, but I'm trying to get back into coding, and specifically GTK2-Perl.

I have a table setup with various widgets in each.  What I would like to do is align, say the menubar, to the top of the cell, without having all the gaps in between.  Attached is a screenshot of what I mean.  I think I would have to use Alignment, but I'm not sure, looking through some other people's code I wasn't able to find anything.  Ideally, I would like the center table to take up all the space that the Menubar and Statusbar widgets do not use.  And having those two widgets aligned at the top (Menubar) and bottom (Statusbar).

Any help would be greatly appreciated.

Best,

Dominik


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

ferret-alignment.jpg (27K) Download Attachment

Re: Aligning in a Table

by muppet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 18, 2008, at 5:40 PM, Dominik wrote:

> Hi all,
>
> I'm sure this is easy to answer, but I'm trying to get back into  
> coding, and specifically GTK2-Perl.
>
> I have a table setup with various widgets in each.  What I would  
> like to do is align, say the menubar, to the top of the cell,  
> without having all the gaps in between.  Attached is a screenshot of  
> what I mean.  I think I would have to use Alignment, but I'm not  
> sure, looking through some other people's code I wasn't able to find  
> anything.  Ideally, I would like the center table to take up all the  
> space that the Menubar and Statusbar widgets do not use.  And having  
> those two widgets aligned at the top (Menubar) and bottom (Statusbar).
>
> Any help would be greatly appreciated.

I think what you're looking for are "packing properties", like  
"expand" and "fill".

http://library.gnome.org/devel/gtk/stable/gtk-Standard-Enumerations.html#GtkAttachOptions

GTK_EXPAND   the widget should expand to take up any extra space in  
its container that has been allocated.

GTK_SHRINK   the widget should shrink as and when possible.

GTK_FILL    the widget should fill the space allocated to it.



For the basic layout you created in the screenshot, menubar, content  
area, and statusbar, you really only want the content area to have the  
"expand" and "fill" properties.

     my $table = Gtk2::Table->new (3, 1);

     $table->pack_start ($menubar, 0, 1, 0, 1, [], [], 0, 0);
     $table->pack_start ($contents, 0, 1, 1, 2, [qw(expand fill)],  
[qw(expand fill)], 0, 0);
     $table->pack_start ($statusbar, 0, 1, 2, 3, [], [], 0, 0);



One-column tables are a bit silly, though.  You also can create that  
layout a bit more easily with a vertical box, like this:

     my $vbox = Gtk2::VBox->new ();

     # pack menu bar first, with "expand" and "fill" set to false.
     $vbox->pack_start ($menubar, FALSE, FALSE, 0);

     # next, the content area expands to take all remaining vertical  
space.
     $vbox->pack_start ($contents, TRUE, TRUE, 0);

     # finally, the status bar, packed just like the menu bar.
     $vbox->pack_start ($statusbar, FALSE, FALSE, 0);


This stuff is described in the gtk+ tutorial, but i find it's best to  
play around with these options in the glade UI designer to get a feel  
for what they do.

Here's the "Packing Widgets" section of the gtk2-perl tutorial:
http://gtk2-perl.sourceforge.net/doc/gtk2-perl-tut/ch-PackingWidgets.html

and the original C version for comparison.
http://library.gnome.org/devel/gtk-tutorial/stable/c355.html


--
If the monkey could type one keystroke every nanosecond, the expected  
waiting time until the monkey types out Hamlet is so long that the  
estimated age of the universe is insignificant by comparison ... this  
is not a practical method for writing plays.
   -- Gian-Carlo Rota


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Aligning in a Table

by Dominik-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, that put me on the right track.  The reason I'm using tables is to save space for a progressbar or other widgets to the left or right.

This is what ended up working for me:

my $table = Gtk2::Table->new(3, 2);

$table->attach($menubar, 0, 2, 0, 1, [ 'fill' ], [ 'fill' ], 0, 0);
$table->attach($notebook,0, 2, 1, 2, [qw(expand fill)], [qw(expand fill)], 0, 0);
$table->attach($statusbar, 0, 2, 2, 3, [ 'fill' ], [ 'fill' ], 0, 0);

Thanks again,
Dominik

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
LightInTheBox - Buy quality products at wholesale price!