table layout



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;
}



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