When composing components, you can also discharge components in a table-like manner. In GTK, you can use gtktable, you can use the gtk_table_new () function to create:
Gtkwidget * Table = gtk_table_new (3, 3, true );
The preceding program segment also creates a table with three columns (ROW) and three rows (Column). The third parameter determines whether the space in the table is evenly allocated, therefore, if it is set to true, the space of each grid is determined by the largest element.
To place the component in the table, you can use the gtk_table_attach () function:
Void gtk_table_attach (gtktable * table,
Gtkwidget * child,
Guint
Left_attach,
Guint
Right_attach,
Guint
Top_attach,
Guint
Bottom_attach,
Gtkattacexceptions xoptions,
Gtkattacexceptions yoptions,
Guint
Xpadding,
Guint
Ypadding );
In this function, the left_attach, right_attach, top_attach, and bottom_attach determine the blank space for the component to be added. For example, if the table 3 is used:
0
1 2
3
0 + ---------- +
---------- +
|
|
1 + ---------- +
---------- +
|
|
2 + ---------- +
---------- +
|
|
3 + ---------- +
---------- +
If you want to leave the upper left pane blank
Left_attach 0, right_attach 1, top_attach 0, and bottom_attach 1.
Left_attach is 1, right_attach is 2, top_attach is 1, bottom_attach is 2,
If you want to leave the two cells at the bottom of the component
Left_attach is 0, right_attach is 2, top_attach is 1, bottom_attach is 2, and so on.
Xoptions and yoptions are components that have no space between them. You can specify the following values and use the or combination values:
- Gtk_fill: if the component is less than the available space, the component will fill in the available space.
- Gtk_shrink:
If the size of a component is greater than the available space, the component will be smaller to meet the available space.
- Gtk_expand: The table is scaled to fit the component size.
You can use the gtk_table_attach_defaults () function. When the parameter is set to gtk_fill | gtk_expand, padding is set to 0:
Void gtk_table_attach_defaults (gtktable * table,
Gtkwidget * widget,
Guint left_attach,
Guint right_attach,
Guint top_attach,
Guint bottom_attach );
The following program first shows how to use the gtktable of the upload ticket:
# Include <GTK/GTK. h>
Int main (INT argc, char * argv []) {
Gtkwidget * window;
Gtkwidget * table;
Gtkwidget * label;
Const char * Text [] = {"one", "two", "three ",
"Four", "five", "Six ",
"Seven", "eight", "Nine "};
Int I, J, K;
Gtk_init (& argc, & argv );
Window = gtk_window_new (gtk_window_toplevel );
Gtk_window_set_title (gtk_window (window), "gtktable ");
Gtk_window_set_default_size (gtk_window (window), 250,150 );
Table = gtk_table_new (3, 3, true );
For (I = 0, K = 0; I <3; I ++, K = K + 3 ){
For (j = 0; j <3; j ++ ){
Label = gtk_label_new (Text [K + J]);
Gtk_table_attach_defaults (
Gtk_table (table), label, J, J + 1, I, I + 1 );
}
}
Gtk_container_add (gtk_container (window), table );
G_signal_connect (gtk_object (window), "Destroy ",
G_callback (gtk_main_quit), null );
Gtk_widget_show_all (window );
Gtk_main ();
Return 0;
}
When the program is running, the test details are as follows:
You can specify the left_attach, right_attach, top_attach, and bottom_attach modes of the gtktable to facilitate cross-Data Element conversion. In table Packing example
In this example, you can take another test.
Packing using tables
There is a description about gtktable.