?? sec-containers.html
字號:
</p> </div> <p> <b>Figure 4. Packing <tt class="CLASSNAME"> GtkBox</tt></b> </p> </div> <p> A box can contain two sets of widgets. The first set is packed at the "start" (top or left) of the box; the second at the "end" (bottom or right). If you pack three widgets into the start of a box, the first widget you pack appears topmost or leftmost; the second follows the first; and the third appears closest to the center of the box. If you then pack three widgets into the end of the same box, the first appears bottommost or rightmost; the second follows it; and the third appears closest to the center. With all six widgets packed, the order from top/left to bottom/right is: 1, 2, 3, 3, 2, 1. <a href= "sec-containers.html#FIG-PACKSTARTEND">Figure 5</a> shows this for <tt class="CLASSNAME">GtkVBox</tt>. Order of packing is only important within each end of the box; i.e., we could have alternated packing start and packing end, with the same results. </p> <div class="FIGURE"> <a name="FIG-PACKSTARTEND"></a> <p> <img src="figures/packstartend.png"> </p> <p> <b>Figure 5. Buttons packed into a <tt class= "CLASSNAME">GtkVBox</tt></b> </p> </div> <div class="SECT3"> <h3 class="SECT3"> <a name="Z49"><tt class="CLASSNAME">GtkBox</tt> Layout Details</a> </h3> <p> Packing is affected by three parameters, which are the same for both start and end packing; the meaning of these parameters is somewhat complicated, because they interact with the <span class="STRUCTNAME"> homogeneous</span> setting of the box and with each other. </p> <p> Here's how a <tt class="CLASSNAME">GtkBox</tt> computes its size request for the "interesting" direction (width for <tt class="CLASSNAME">GtkHBox</tt>, height for <tt class="CLASSNAME">GtkVBox</tt>): </p> <ol type="1"> <li> <p> The total requested size of each child is considered to be the child's size request, plus two times the <span class="STRUCTNAME">padding</span> value used to pack the child. A child's <span class="STRUCTNAME">padding</span> is the amount of blank space on either side of it. In short, Child Size = (Child Widget's Size Request) + 2*(Child Padding). </p> </li> <li> <p> If the box is homogeneous, the base size request for the entire box is equal to the size (request + padding) of the largest child, times the number of children. In a homogeneous box, all children are as large as the largest child. </p> </li> <li> <p> If the box is not homogeneous, the base size request for the entire box is the sum of the size (request + padding) of each child. </p> </li> <li> <p> The box-wide <span class="STRUCTNAME"> spacing</span> setting determines how much blank space to leave between children; so this value is multiplied by the number of chilren minus one, and added to the base size request. Note that <i class= "FIRSTTERM">spacing</i> does not belong to a child; it is blank space between children and is unaffected by the <span class="STRUCTNAME"> expand</span> and <span class="STRUCTNAME"> fill</span> parameters. <i class="FIRSTTERM"> Padding</i>, on the other hand, is the space around each child and <i class="EMPHASIS">is</i> affected by the child's packing parameters. </p> </li> <li> <p> All containers have a "border width" setting; two times the border width is added to the request, representing a border on either side. Thus, the total size requested by a <tt class="CLASSNAME"> GtkBox</tt> is: (Sum of Child Sizes) + Spacing*(Number of Children - 1) + 2*(Border Width). </p> </li> </ol> <p> After computing its size request and delivering it to its parent container, <tt class="CLASSNAME">GtkBox</tt> will receive its size allocation and distribute it among its children as follows: </p> <ol type="1"> <li> <p> Enough space for the border width and inter-child spacing is subtracted from the allocation; the remainder is the available space for children themselves. This space is divided into two chunks: the amount actually requested by the children (child requisitions and padding), and the "extra." Extra = (Allocation Size) - (Sum of Child Sizes). </p> </li> <li> <p> If the box is not homogeneous, the "extra" space is divided among those children with the <span class= "STRUCTNAME">expand</span> parameter set to <span class="STRUCTNAME">TRUE</span>. These children can expand to fit available space. If no child can expand, the extra is used to add more space in the center of the box, between the start-packed widgets and the end-packed widgets. </p> </li> <li> <p> If the box is homogeneous, the extra is distributed according to need; those children who requested more space get less extra, so that everyone ends up with the same amount of space. The <span class= "STRUCTNAME">expand</span> parameter is ignored for homogeneous boxes---extra is distributed to all children, not just the expandable ones. </p> </li> <li> <p> When a child gets some extra space, there are two possibilities. More padding can be added around the child, or the child widget itself can be expanded. The <span class="STRUCTNAME">fill</span> parameter determines which will happen. If <span class= "STRUCTNAME">TRUE</span>, the child widget expands to fill the space---that is, the entire space becomes the child's allocation; if <span class= "STRUCTNAME">fill</span> is <span class= "STRUCTNAME">FALSE</span>, the child's padding is increased to fill the space, and the child is allocated only the space it requested. Note that <span class="STRUCTNAME">fill</span> has no effect if <span class="STRUCTNAME">expand</span> is set to <span class="STRUCTNAME">FALSE</span> and the box is not homogeneous, because the child will never receive any extra space to fill. </p> </li> </ol> <p> Whew! Who wants to think about all that? Fortunately, there are some common patterns of usage, so you don't need to solve a multivariate equation to figure out how to use the widget. The authors of the GTK+ Tutorial boil things down nicely to five cases that occur in practice; we'll follow in their footsteps here. </p> </div> <div class="SECT3"> <h3 class="SECT3"> <a name="Z50">Non-Homogeneous Box Packing Patterns</a> </h3> <p> There are three interesting ways to pack a non-homogeneous box. First, you can pack all the widgets into the end of the box, with their natural size. This means setting the <span class="STRUCTNAME"> expand</span> parameter to <span class="STRUCTNAME"> FALSE</span>: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> gtk_box_pack_start(GTK_BOX(box), child, FALSE, FALSE, 0); </pre> </td> </tr> </table> <p> The result is shown in <a href= "sec-containers.html#FIG-PACKNONHOMONOEXPANDNOFILL"> Figure 6</a>. The <span class="STRUCTNAME"> expand</span> parameter is the only one that matters in this case; no children are receiving extra space, so they wouldn't be able to fill it even if <span class= "STRUCTNAME">fill</span> were <span class="STRUCTNAME"> TRUE</span>. </p> <div class="FIGURE"> <a name="FIG-PACKNONHOMONOEXPANDNOFILL"></a> <p> <img src="figures/packnonhomonoexpandnofill.png"> </p> <p> <b>Figure 6. Non-homogeneous, with <span class= "STRUCTNAME">expand = FALSE</span></b> </p> </div> <p> Second, you can spread widgets throughout the box, letting them keep their natural size as in <a href= "sec-containers.html#FIG-PACKNONHOMOEXPANDNOFILL"> Figure 7</a>; this means setting the <span class= "STRUCTNAME">expand</span> parameter to <span class= "STRUCTNAME">TRUE</span>: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> gtk_box_pack_start(GTK_BOX(box), child, TRUE, FALSE, 0); </pre> </td> </tr> </table> <div class="FIGURE"> <a name="FIG-PACKNONHOMOEXPANDNOFILL"></a> <p> <img src="figures/packnonhomoexpandnofill.png"> </p> <p> <b>Figure 7. Non-homogeneous, with <span class= "STRUCTNAME">expand = TRUE</span> and <span class= "STRUCTNAME">fill = FALSE</span></b> </p> </div> <p> Finally, you can fill the box with widgets (letting larger children have more space) by setting the <span class="STRUCTNAME">fill</span> parameter to <span class="STRUCTNAME">TRUE</span> as well: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> gtk_box_pack_start(GTK_BOX(box), child, TRUE, TRUE, 0); </pre> </td> </tr> </table> <p> This configuration is shown in <a href= "sec-containers.html#FIG-PACKNONHOMOEXPANDFILL">Figure 8</a> </p> <div class="FIGURE"> <a name="FIG-PACKNONHOMOEXPANDFILL"></a> <p> <img src="figures/packnonhomoexpandfill.png"> </p> <p> <b>Figure 8. Non-homogeneous, with <span class= "STRUCTNAME">expand = TRUE</span> and <span class= "STRUCTNAME">fill = TRUE</span></b> </p> </div> </div> <div class="SECT3"> <h3 class="SECT3"> <a name="Z51">Homogeneous Box Packing Patterns</a> </h3> <p> There are only two interesting ways to pack a homogeneous box. Recall that the <span class= "STRUCTNAME">expand</span> parameter is irrelevant for homogeneous boxes; so the two cases correspond to the <span class="STRUCTNAME">fill</span> parameter's setting. </p> <p> If <span class="STRUCTNAME">fill</span> is <span class= "STRUCTNAME">FALSE</span>, you get <a href= "sec-containers.html#FIG-PACKHOMONOFILL">Figure 9</a>. Notice that the box is logically divided into three equal parts, but only the largest child widget occupies its entire space. The others are padded to fill their third of the area. If <span class="STRUCTNAME"> fill</span> is <span class="STRUCTNAME">TRUE</span>, you get <a href="sec-containers.html#FIG-PACKHOMOFILL"> Figure 10</a>; all the widgets are the same size. </p> <div class="FIGURE"> <a name="FIG-PACKHOMONOFILL"></a> <p> <img src="figures/packhomonofill.png"> </p>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -