?? sec-containers.html
字號:
<p> <b>Figure 9. Homogeneous, with <span class= "STRUCTNAME">fill = FALSE</span></b> </p> </div> <div class="FIGURE"> <a name="FIG-PACKHOMOFILL"></a> <p> <img src="figures/packhomofill.png"> </p> <p> <b>Figure 10. Homogeneous, with <span class= "STRUCTNAME">fill = TRUE</span></b> </p> </div> </div> <div class="SECT3"> <h3 class="SECT3"> <a name="Z52">Box Packing Summary</a> </h3> <p> Figure <a href="sec-containers.html#FIG-ALLPACK">Figure 11</a> shows all five box-packing techniques together. (They are packed into a homogeneous <tt class= "CLASSNAME">GtkVBox</tt> with <span class="STRUCTNAME"> fill</span> set to <span class="STRUCTNAME">TRUE</span> and an interchild spacing of two pixels.) This should give you a sense of their relative effects. Keep in mind that you can also tweak the <span class= "STRUCTNAME">padding</span> and <span class= "STRUCTNAME">spacing</span> parameters, to increase or decrease the amount of blank space between widgets. However, you can easily create an ugly layout by using inconsistent spacing---it's a good idea to try to keep widgets "lined up" and consistently spaced. </p> <div class="FIGURE"> <a name="FIG-ALLPACK"></a> <p> <img src="figures/allpack.png"> </p> <p> <b>Figure 11. All Five Ways to Pack a Box</b> </p> </div> <p> A final point: notice that the <span class= "STRUCTNAME">expand</span> and <span class= "STRUCTNAME">fill</span> parameters are only relevant when a box's size allocation is larger than its size request. That is, these parameters determine how <i class="EMPHASIS">extra</i> space is distributed. Typically, extra space appears when a user resizes a window to make it larger than its default size. Thus, you should always try resizing your windows to be sure your boxes are packed correctly. </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="SEC-GTKTABLE"><tt class="CLASSNAME"> GtkTable</tt></a> </h2> <p> The second most common layout container is <tt class= "CLASSNAME">GtkTable</tt>. <tt class="CLASSNAME"> GtkTable</tt> divides a region into cells; you can assign each child widget to a rectangle made up of one or more cells. You can think of <tt class="CLASSNAME"> GtkTable</tt> as a sheet of graph paper (with more flexibility---the grid lines do not have to be equidistant, though they can be). </p> <p> <tt class="CLASSNAME">GtkTable</tt> comes with the usual constructor, and some functions to attach children to it; these are shown in <a href= "sec-containers.html#FL-GTKTABLE">Figure 12</a>. When creating a table, you specify the number of cells you plan to use; this is purely for efficiency. The table will automatically grow if you place children in cells outside its current area. Like boxes, tables can be homogeneous or not. </p> <div class="FIGURE"> <a name="FL-GTKTABLE"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GTKTABLE.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gtk/gtktable.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">GtkWidget* <tt class= "FUNCTION">gtk_table_new</tt></code>(guint <tt class= "PARAMETER"><i>rows</i></tt>, guint <tt class= "PARAMETER"><i>columns</i></tt>, gboolean <tt class= "PARAMETER"><i>homogeneous</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">GtkWidget* <tt class= "FUNCTION">gtk_table_attach</tt></code>(GtkTable* <tt class="PARAMETER"><i>table</i></tt>, GtkWidget* <tt class="PARAMETER"><i>child</i></tt>, guint <tt class= "PARAMETER"><i>left_side</i></tt>, guint <tt class= "PARAMETER"><i>right_side</i></tt>, guint <tt class= "PARAMETER"><i>top_side</i></tt>, guint <tt class= "PARAMETER"><i>bottom_side</i></tt>, GtkAttachOptions <tt class="PARAMETER"><i>xoptions</i></tt>, GtkAttachOptions <tt class="PARAMETER"><i> yoptions</i></tt>, guint <tt class="PARAMETER"><i> xpadding</i></tt>, guint <tt class="PARAMETER"><i> ypadding</i></tt>);</code> </p> </div> <p> <b>Figure 12. <tt class="CLASSNAME">GtkTable</tt></b> </p> </div> <p> The first two arguments to <tt class="FUNCTION"> gtk_table_attach()</tt> are the table and the child to place in the table. The next four specify which grid lines should form the bounding box of the child. Grid lines are numbered from the top left (northwest) corner of the table, starting with 0; so a 2 by 3 table will have vertical lines 0, 1, 2 and horizontal lines 0,1,2,3. The last two arguments are the amount of padding to put on the left-right sides of the child (<span class= "STRUCTNAME">xpadding</span>) and the top-bottom (<span class="STRUCTNAME">ypadding</span>). This is analagous to padding in boxes. </p> <p> The <span class="STRUCTNAME">GtkAttachOptions</span> arguments require some explanation. Here's a summary of possible values. The values are bitmasks, so more than one can be specified by or-ing them together. </p> <ul> <li> <p> <span class="STRUCTNAME">GTK_EXPAND</span> specifies that this section of the table will expand to fit available space, much like the <span class= "STRUCTNAME">expand</span> option when packing boxes. </p> </li> <li> <p> <span class="STRUCTNAME">GTK_FILL</span> specifies that the child widget will expand to fill available space. Important only if <span class="STRUCTNAME"> GTK_EXPAND</span> is set, because <span class= "STRUCTNAME">GTK_EXPAND</span> permits extra space to exist. </p> </li> <li> <p> <span class="STRUCTNAME">GTK_SHRINK</span> determines what will happen if there is insufficient space to meet the child's size request. If <span class= "STRUCTNAME">GTK_SHRINK</span> is set, the child is given a smaller allocation which reflects available space---i.e., the table shrinks the child. If it isn't set, the child is given its requested size; this may result in overlapping children within the table, and children will be "chopped off" at the table edges (because they'll try to draw outside the table's <span class="STRUCTNAME"> GdkWindow</span>). </p> </li> </ul> <p> It's possible to set spacing between rows and columns, in addition to padding around particular children; the terms "spacing" and "padding" mean the same thing with respect to tables and boxes. See <tt class="FILENAME"> gtk/gtktable.h</tt> for a complete list of available <tt class="CLASSNAME">GtkTable</tt> functions. </p> <div class="SECT3"> <h3 class="SECT3"> <a name="Z53"><tt class="CLASSNAME">GtkTable</tt> Example</a> </h3> <p> The following code creates a table with four cells and three children; one child covers two cells. The children are packed using different parameters: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> GtkWidget* window; GtkWidget* button; GtkWidget* container; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); container = gtk_table_new(2, 2, FALSE); gtk_container_add(GTK_CONTAINER(window), container); gtk_window_set_title(GTK_WINDOW(window), "Table Attaching"); gtk_container_set_border_width(GTK_CONTAINER(container), 10); /* This would be a bad idea in real code; but it lets us * experiment with window resizing. */ gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE); gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event_cb), NULL); button = gtk_button_new_with_label("1. Doesn't shrink\nor expand"); gtk_table_attach(GTK_TABLE(container), button, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); button = gtk_button_new_with_label("2. Expands and shrinks\nvertically"); gtk_table_attach(GTK_TABLE(container), button, 0, 1, 1, 2, GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); button = gtk_button_new_with_label("3. Expands and shrinks\nin both directions"); gtk_table_attach(GTK_TABLE(container), button, 1, 2, 0, 2, GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0); </pre> </td> </tr> </table> <p> It's instructive to observe the resulting table as the window is resized. First, a quick summary of how the children are attached: </p> <ol type="1"> <li> <p> The first child will always receive its requested size; it neither expands nor shrinks. </p> </li> <li> <p> The second child can expand and shrink only in the Y direction. </p> </li> <li> <p> The third child can expand and shrink in either direction. </p> </li> </ol> <p> The window's natural size is shown in <a href= "sec-containers.html#FIG-TABLENATURAL">Figure 13</a>; notice that some cells are given more space than the widgets inside them requested because table cells have to remain aligned. (Recall that a button with a label will request only enough space to display the entire label.) The <span class="STRUCTNAME">GTK_FILL</span> flag causes <tt class="CLASSNAME">GtkTable</tt> to allocate extra space to the widgets themselves, instead of leaving blank padding around them. </p> <div class="FIGURE"> <a name="FIG-TABLENATURAL"></a> <p> <img src="figures/tablenatural.png"> </p> <p> <b>Figure 13. <span class="STRUCTNAME"> GtkTable</span> before resizing</b> </p> </div> <p> Now imagine the user expands the window vertically; notice that extra space is given to the widgets with <span class="STRUCTNAME">GTK_EXPAND</span> turned on in the Y direction---namely widgets two and three---while the widget in the top-left corner remains unchanged. <a href="sec-containers.html#FIG-TABLEVERTRESIZE">Figure 14</a> shows this state of affairs. </p> <div class="FIGURE"> <a name="FIG-TABLEVERTRESIZE"></a> <p> <img src="figures/tablevertresize.png">
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -