1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
>Packing Using Tables</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
TITLE="GTK+ 2.0 Tutorial"
11
HREF="book1.html"><LINK
13
TITLE="Packing Widgets"
14
HREF="c355.html"><LINK
16
TITLE="Packing Demonstration Program"
17
HREF="x387.html"><LINK
19
TITLE="Table Packing Example"
20
HREF="x442.html"></HEAD
31
SUMMARY="Header navigation table"
40
>GTK+ 2.0 Tutorial</TH
50
><<< Previous</A
64
>Next >>></A
76
NAME="SEC-PACKINGUSINGTABLES"
77
>Packing Using Tables</A
80
>Let's take a look at another way of packing - Tables. These can be
81
extremely useful in certain situations.</P
83
>Using tables, we create a grid that we can place widgets in. The
84
widgets may take up as many spaces as we specify.</P
86
>The first thing to look at, of course, is the gtk_table_new() function:</P
94
CLASS="PROGRAMLISTING"
95
>GtkWidget *gtk_table_new( guint rows,
97
gboolean homogeneous );</PRE
102
>The first argument is the number of rows to make in the table, while
103
the second, obviously, is the number of columns.</P
105
>The homogeneous argument has to do with how the table's boxes are
106
sized. If homogeneous is TRUE, the table boxes are resized to the size
107
of the largest widget in the table. If homogeneous is FALSE, the size
108
of a table boxes is dictated by the tallest widget in its same row,
109
and the widest widget in its column.</P
111
>The rows and columns are laid out from 0 to n, where n was the number
112
specified in the call to gtk_table_new. So, if you specify rows = 2
113
and columns = 2, the layout would look something like this:</P
121
CLASS="PROGRAMLISTING"
123
0+----------+----------+
125
1+----------+----------+
127
2+----------+----------+</PRE
132
>Note that the coordinate system starts in the upper left hand corner.
133
To place a widget into a box, use the following function:</P
141
CLASS="PROGRAMLISTING"
142
>void gtk_table_attach( GtkTable *table,
148
GtkAttachOptions xoptions,
149
GtkAttachOptions yoptions,
151
guint ypadding );</PRE
156
>The first argument ("table") is the table you've created and the
157
second ("child") the widget you wish to place in the table.</P
159
>The left and right attach arguments specify where to place the widget,
160
and how many boxes to use. If you want a button in the lower right
161
table entry of our 2x2 table, and want it to fill that entry <I
165
left_attach would be = 1, right_attach = 2, top_attach = 1,
166
bottom_attach = 2.</P
168
>Now, if you wanted a widget to take up the whole top row of our 2x2
169
table, you'd use left_attach = 0, right_attach = 2, top_attach = 0,
170
bottom_attach = 1.</P
172
>The xoptions and yoptions are used to specify packing options and may
173
be bitwise OR'ed together to allow multiple options.</P
175
>These options are:</P
188
>If the table box is larger than the widget, and
192
> is specified, the widget will expand to use all the room
202
>If the table widget was allocated less space
203
then was requested (usually by the user resizing the window), then the
204
widgets would normally just be pushed off the bottom of the window and
208
> is specified, the widgets will shrink
218
>This will cause the table to expand to use up
219
any remaining space in the window.</P
224
>Padding is just like in boxes, creating a clear area around the widget
225
specified in pixels.</P
227
>gtk_table_attach() has a <I
231
So, there's a shortcut:</P
239
CLASS="PROGRAMLISTING"
240
>void gtk_table_attach_defaults( GtkTable *table,
245
guint bottom_attach );</PRE
250
>The X and Y options default to <TT
252
>GTK_FILL | GTK_EXPAND</TT
254
and X and Y padding are set to 0. The rest of the arguments are identical to the
255
previous function.</P
257
>We also have gtk_table_set_row_spacing() and
258
gtk_table_set_col_spacing(). These places spacing between the rows at
259
the specified row or column.</P
267
CLASS="PROGRAMLISTING"
268
>void gtk_table_set_row_spacing( GtkTable *table,
270
guint spacing );</PRE
283
CLASS="PROGRAMLISTING"
284
>void gtk_table_set_col_spacing ( GtkTable *table,
286
guint spacing );</PRE
291
>Note that for columns, the space goes to the right of the column, and
292
for rows, the space goes below the row.</P
294
>You can also set a consistent spacing of all rows and/or columns with:</P
302
CLASS="PROGRAMLISTING"
303
>void gtk_table_set_row_spacings( GtkTable *table,
304
guint spacing );</PRE
317
CLASS="PROGRAMLISTING"
318
>void gtk_table_set_col_spacings( GtkTable *table,
319
guint spacing );</PRE
324
>Note that with these calls, the last row and last column do not get
332
SUMMARY="Footer navigation table"
345
><<< Previous</A
363
>Next >>></A
371
>Packing Demonstration Program</TD
385
>Table Packing Example</TD
b'\\ No newline at end of file'