Re: table layout



Hi,

I think you want the table to be homogeneous :
    my $table = Gtk2::Table->new(4, 6, TRUE);

But to me it's a strange way to do what you want to do.

I would personnaly use the "width-chars" property of the GtkEntry in a 2
columns table.
(And then I would have to use a GtkAdjustment to put the GtkEntry on the
left)

Of course, as it was once said (and twice, and more,...) "There Is More
Than One Way To Do It"

To see what can be done, and how, I use to play with Glade gui-builder
before starting coding.
(Actually, now I'm using GladeXML and I forgot about all this :-p)
 
hope it will help !

Pik

Scott Lanning wrote:

I'm having some trouble using a Gtk2::Table layout.
I'd like to make just a simple grid. No matter what
widgets I put in the grid, the grid has the same shape.
Every combination of arguments I try, it seems that
the grid in fact expands or contracts. Basically I want
a simple form and to be able to control the width of
the text entries according to how many columns they
occupy.

|        |        |        |        |        |
  Name:  [_________________]
  Year:  [________]
  Addr:  [__________________________]

But what I get is either this if I don't use 'expand'

  Name: [_______]
  Year: [_______]
  Addr: [_______]

or this if I use 'expand':

  Name: [______________________________________________]
  Year: [______________________________________________]
  Addr: [______________________________________________]

What am I doing wrong?
Here's what I have for the "content creating" subroutine.

sub create_content {
    my $notebook = Gtk2::Notebook->new();

    # Page 1
    # rows: number of rows
    # cols: number of columns
    # homogeneous: TRUE -> boxes are size of largest widget,
    #              FALSE -> boxes are size of tallest/widest in each
row/column
    my $table = Gtk2::Table->new(4, 6, FALSE);
    my $vbox = Gtk2::VBox->new(TRUE);
    my $label = Gtk2::Label->new('Name: ');
    my $entry = Gtk2::Entry->new();
    # left_attach, right_attach, top_attach, bottom_attach:
    # where to attach the four corners of the widget,
    # numbers starting from 0 in the top-left corner
    # xoptions, yoptions: GTK_FILL -> widget expands to use all
available room,
    #   GTK_SHRINK -> widgets shrink with the table, GTK_EXPAND ->
table itself
    #   expands to fill up available room
    # xpadding, ypadding: space in pixels on each side of widget
    # There's also an `attach_defaults' method without the last 4
arguments.
    $table->attach($label, 0, 1, 1, 2, [], [], 3, 2);
    $table->attach($entry, 1, 3, 1, 2, ['fill','expand'], 'expand', 3,
2);

    $label = Gtk2::Label->new('Year: ');
    $entry = Gtk2::Entry->new();
    $table->attach($label, 0, 1, 2, 3, [], [], 3, 2);
    $table->attach($entry, 1, 2, 2, 3, ['fill','expand'], 'expand', 3,
2);

    $label = Gtk2::Label->new('Addr: ');
    $entry = Gtk2::Entry->new();
    $table->attach($label, 0, 1, 3, 4, [], [], 3, 2);
    $table->attach($entry, 1, 4, 3, 4, ['fill','expand'], 'expand', 3,
2);

    $vbox->pack_start($table, TRUE, TRUE, 3);
    $notebook->append_page($vbox, 'Story');

    return $notebook;
}
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list




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