📄 sec-detailsofboxes.html
字号:
<HTML><HEAD><TITLE>Details of Boxes</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Packing Widgets"HREF="ch-packingwidgets.html"><LINKREL="PREVIOUS"TITLE="Packing Widgets"HREF="ch-packingwidgets.html"><LINKREL="NEXT"TITLE="Packing Demonstration Program"HREF="sec-packingdemonstrationprogram.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%"> <tr> <td bgcolor="#FFFFFF" valign=top nowrap> <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A> <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR> </td> <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="ch-packingwidgets.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 4. Packing Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-packingdemonstrationprogram.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-DETAILSOFBOXES">4.2. Details of Boxes</A></H1><P>Because of this flexibility, packing boxes in GTK can be confusing atfirst. There are a lot of options, and it's not immediately obvious howthey all fit together. In the end, however, there are basically fivedifferent styles.</P><P><SPANCLASS="INLINEMEDIAOBJECT"><IMGSRC="gtk_tut_packbox1.jpg"></IMG></SPAN></P><P>Each line contains one horizontal box (hbox) with several buttons. Thecall to gtk_box_pack is shorthand for the call to pack each of thebuttons into the hbox. Each of the buttons is packed into the hbox thesame way (i.e., same arguments to the gtk_box_pack_start() function).</P><P>This is the declaration of the gtk_box_pack_start function.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_box_pack_start( GtkBox *box, GtkWidget *child, gint expand, gint fill, gint padding );</PRE></TD></TR></TABLE><P>The first argument is the box you are packing the object into, thesecond is the object. The objects will all be buttons for now, sowe'll be packing buttons into boxes.</P><P>The expand argument to gtk_box_pack_start() and gtk_box_pack_end()controls whether the widgets are laid out in the box to fill in allthe extra space in the box so the box is expanded to fill the areaallotted to it (TRUE); or the box is shrunk to just fit the widgets(FALSE). Setting expand to FALSE will allow you to do right and leftjustification of your widgets. Otherwise, they will all expand to fitinto the box, and the same effect could be achieved by using only oneof gtk_box_pack_start or gtk_box_pack_end.</P><P>The fill argument to the gtk_box_pack functions control whether theextra space is allocated to the objects themselves (TRUE), or as extrapadding in the box around these objects (FALSE). It only has an effectif the expand argument is also TRUE.</P><P>When creating a new box, the function looks like this:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_hbox_new (gint homogeneous, gint spacing);</PRE></TD></TR></TABLE><P>The homogeneous argument to gtk_hbox_new (and the same forgtk_vbox_new) controls whether each object in the box has the samesize (i.e., the same width in an hbox, or the same height in avbox). If it is set, the gtk_box_pack routines function essentiallyas if the <TTCLASS="LITERAL">expand</TT> argument was always turned on.</P><P>What's the difference between spacing (set when the box is created)and padding (set when elements are packed)? Spacing is added betweenobjects, and padding is added on either side of an object. Thefollowing figure should make it clearer:</P><P><SPANCLASS="INLINEMEDIAOBJECT"><IMGSRC="gtk_tut_packbox2.jpg"></IMG></SPAN></P><P>Here is the code used to create the above images. I've commented itfairly heavily so I hope you won't have any problems followingit. Compile it yourself and play with it.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="ch-packingwidgets.html"><<< Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-packingdemonstrationprogram.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Packing Widgets</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-packingwidgets.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Packing Demonstration Program</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -