?? sec-containers.html
字號:
</p> <p> <b>Figure 14. <span class="STRUCTNAME"> GtkTable</span> after expanding the window vertically</b> </p> </div> <p> Next, imagine the user expanding the window horizontally; only child widget number three can expand horizontally. <a href= "sec-containers.html#FIG-TABLEHORIZRESIZE">Figure 15</a> shows this. </p> <div class="FIGURE"> <a name="FIG-TABLEHORIZRESIZE"></a> <p> <img src="figures/tablehorizresize.png"> </p> <p> <b>Figure 15. <span class="STRUCTNAME"> GtkTable</span> after expanding the window horizontally</b> </p> </div> <p> <a href="sec-containers.html#FIG-TABLEVERTSHRINK"> Figure 16</a> shows the result if the user shrinks the table vertically, so that there isn't enough vertical space to give all the widgets their size requests. Child number two gets shortchanged, while child number one gets all the vertical space it needs. </p> <div class="FIGURE"> <a name="FIG-TABLEVERTSHRINK"></a> <p> <img src="figures/tablevertshrink.png"> </p> <p> <b>Figure 16. <span class="STRUCTNAME"> GtkTable</span> after shrinking the window vertically</b> </p> </div> <p> Finally, <a href= "sec-containers.html#FIG-TABLEHORIZSHRINK">Figure 17</a> shows the result if the user shrinks the table horizontally. Child number three gets the short end of the stick in this situation. </p> <div class="FIGURE"> <a name="FIG-TABLEHORIZSHRINK"></a> <p> <img src="figures/tablehorizshrink.png"> </p> <p> <b>Figure 17. <span class="STRUCTNAME"> GtkTable</span> after shrinking the window horizontally</b> </p> </div> <p> It's not a bad idea to try resizing your window like this whenever you're designing a layout, just to be sure something sane happens. The definition of "sane" varies with the exact widgets you've placed in the layout. </p> </div> <div class="SECT3"> <h3 class="SECT3"> <a name="Z54">Using <tt class="FUNCTION"> gtk_table_attach_defaults()</tt></a> </h3> <p> Since <tt class="FUNCTION">gtk_table_attach()</tt> is somewhat cumbersome, there's a simpler version called <tt class="FUNCTION">gtk_table_attach_defaults()</tt>, shown in <a href= "sec-containers.html#FL-ATTACHDEFAULTS">Figure 18</a>. This version attaches the child with the options <span class="STRUCTNAME">GTK_EXPAND</span> and <span class= "STRUCTNAME">GTK_FILL</span>, and no padding. </p> <p> It's tempting to use <tt class="FUNCTION"> gtk_table_attach_defaults()</tt> all the time to save typing, but really you shouldn't; in fact, it's probably fair to say that it's rarely used. The function is only useful if the defaults happen to be exactly the settings you want. Most of the time, you need to carefully tweak your table attachment parameters to get really nice behavior when your window is resized. Always try resizing your window to be sure you've designed your layout well. </p> <div class="FIGURE"> <a name="FL-ATTACHDEFAULTS"></a> <div class="FUNCSYNOPSIS"> <a name="FL-ATTACHDEFAULTS.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_attach_defaults</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>);</code> </p> </div> <p> <b>Figure 18. Attaching with Defaults</b> </p> </div> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z55">Other Layout Widgets</a> </h2> <p> Boxes and tables are the most commonly-used layout widgets by far. However, there are a few others for special situations. </p> <ul> <li> <p> <tt class="CLASSNAME">GtkButtonBox</tt> is a special kind of box appropriate for the "action area" of a dialog. </p> </li> <li> <p> <tt class="CLASSNAME">GtkPacker</tt> supports <tt class="APPLICATION">Tk</tt>-style packing, useful if you're familiar with <tt class="APPLICATION"> Tk</tt>. </p> </li> <li> <p> <tt class="CLASSNAME">GtkLayout</tt> provides an infinite scrolling area. In general, scrolling areas in GTK+ are limited to just over 30,000 pixels, because that is the maximum size of an X window. </p> </li> <li> <p> <tt class="CLASSNAME">GtkFixed</tt> allows you to manually position widgets at fixed coordinates. </p> </li> </ul> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z56">Manually Affecting Layout</a> </h2> <p> It's possible to manually override GTK+'s geometry management. This is a bad idea 95% of the time, because GTK+'s geometry is essentially the user's preferred geometry, determined by the theme, and resizing toplevel windows. If you find yourself wanting to do things manually, it's probably because you're using the wrong layout container, or you really should be writing a custom container widget. </p> <p> You can force a size or position on a widget with the functions shown in <a href="sec-containers.html#FL-SETU"> Figure 19</a>. However, it is rarely a good idea to use them. In particular, <tt class="FUNCTION"> gtk_widget_set_usize()</tt> should not be used to set a toplevel window's default size. Usually you want to set window size because you've saved the application's state and you're restoring it, or because the user specified a window geometry on the command line. Unfortunately, if you use <tt class="FUNCTION">gtk_widget_set_usize()</tt> the user will be unable to shrink the window, and you'll get hate mail. Rather than force a size, you want to specify an initial size with <tt class="FUNCTION"> gtk_window_set_default_size()</tt>, shown in <a href= "sec-containers.html#FL-DEFAULTSIZE">Figure 20</a>. <tt class="FUNCTION">gtk_widget_set_usize()</tt> is almost never a good idea for non-toplevel widgets either; most of the time, you can get better results using the proper layout widget. </p> <p> <tt class="FUNCTION">gtk_widget_set_uposition()</tt> is only useful for toplevel windows; it borders on nonsensical for other widgets, and will most likely cause bad things to happen. It's primarily used to honor a <tt class="APPLICATION">--geometry</tt> command line argument. </p> <p> All three of these functions can accept <span class= "STRUCTNAME">-1</span> for the <span class="STRUCTNAME"> x</span>, <span class="STRUCTNAME">y</span>, <span class= "STRUCTNAME">width</span>, or <span class="STRUCTNAME"> height</span> argument. The functions ignore any <span class="STRUCTNAME">-1</span> argument; this allows you to set only one of the two arguments, leaving the default value for the other. </p> <div class="FIGURE"> <a name="FL-SETU"></a> <div class="FUNCSYNOPSIS"> <a name="FL-SETU.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gtk/gtkwidget.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gtk_widget_set_uposition</tt></code>(GtkWidget* <tt class="PARAMETER"><i>widget</i></tt>, gint <tt class= "PARAMETER"><i>x</i></tt>, gint <tt class= "PARAMETER"><i>y</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gtk_widget_set_usize</tt></code>(GtkWidget* <tt class="PARAMETER"><i>widget</i></tt>, gint <tt class= "PARAMETER"><i>width</i></tt>, gint <tt class= "PARAMETER"><i>height</i></tt>);</code> </p> </div> <p> <b>Figure 19. Forcing Allocations</b> </p> </div> <div class="FIGURE"> <a name="FL-DEFAULTSIZE"></a> <div class="FUNCSYNOPSIS"> <a name="FL-DEFAULTSIZE.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gtk/gtkwindow.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gtk_window_set_default_size</tt></code>(GtkWindow* <tt class="PARAMETER"><i>window</i></tt>, gint <tt class="PARAMETER"><i>width</i></tt>, gint <tt class= "PARAMETER"><i>height</i></tt>);</code> </p> </div> <p> <b>Figure 20. Default Window Size</b> </p> </div> </div> </div> <div class="NAVFOOTER"> <br> <br> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="cha-gtk.html"><font color="#0000ff" size="2"> <b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="z57.html"><font color="#0000ff" size="2"><b> Next >>></b></font></a> </td> </tr> <tr> <td colspan="2" align="left"> <font color="#000000" size="2"><b>GTK+ Basics</b></font> </td> <td colspan="2" align="right"> <font color="#000000" size="2"><b>Widget Concepts</b></font> </td> </tr> </table> </div> </body></html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -