📄 ch-packingwidgets.html
字号:
<HTML><HEAD><TITLE>Packing Widgets</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="PREVIOUS"TITLE="An Upgraded Hello World"HREF="sec-anupgradedhelloworld.html"><LINKREL="NEXT"TITLE="Details of Boxes"HREF="sec-detailsofboxes.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="CHAPTER"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="sec-anupgradedhelloworld.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-detailsofboxes.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="CH-PACKINGWIDGETS">Chapter 4. Packing Widgets</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT>4.1. <AHREF="ch-packingwidgets.html#SEC-THEORYOFPACKINGBOXES">Theory of Packing Boxes</A></DT><DT>4.2. <AHREF="sec-detailsofboxes.html">Details of Boxes</A></DT><DT>4.3. <AHREF="sec-packingdemonstrationprogram.html">Packing Demonstration Program</A></DT><DT>4.4. <AHREF="sec-packingusingtables.html">Packing Using Tables</A></DT><DT>4.5. <AHREF="sec-tablepackingexamples.html">Table Packing Example</A></DT></DL></DIV><P>When creating an application, you'll want to put more than one widgetinside a window. Our first <ICLASS="EMPHASIS">helloworld</I> example only used onewidget so we could simply use a gtk_container_add call to "pack" thewidget into the window. But when you want to put more than one widgetinto a window, how do you control where that widget is positioned?This is where packing comes in.</P><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-THEORYOFPACKINGBOXES">4.1. Theory of Packing Boxes</A></H1><P>Most packing is done by creating boxes. Theseare invisible widget containers that we can pack our widgets intowhich come in two forms, a horizontal box, and a vertical box. Whenpacking widgets into a horizontal box, the objects are insertedhorizontally from left to right or right to left depending on the callused. In a vertical box, widgets are packed from top to bottom or viceversa. You may use any combination of boxes inside or beside otherboxes to create the desired effect.</P><P>To create a new horizontal box, we use a call to gtk_hbox_new(), andfor vertical boxes, gtk_vbox_new(). The gtk_box_pack_start() andgtk_box_pack_end() functions are used to place objects inside of thesecontainers. The gtk_box_pack_start() function will start at the topand work its way down in a vbox, and pack left to right in an hbox.gtk_box_pack_end() will do the opposite, packing from bottom to top ina vbox, and right to left in an hbox. Using these functions allows usto right justify or left justify our widgets and may be mixed in anyway to achieve the desired effect. We will use gtk_box_pack_start() inmost of our examples. An object may be another container or awidget. In fact, many widgets are actually containers themselves,including the button, but we usually only use a label inside a button.</P><P>By using these calls, GTK knows where you want to place your widgetsso it can do automatic resizing and other nifty things. There are alsoa number of options as to how your widgets should be packed. As youcan imagine, this method gives us a quite a bit of flexibility whenplacing and creating widgets.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-anupgradedhelloworld.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-detailsofboxes.html">Next >>></A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">An Upgraded Hello World</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"> </TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Details of Boxes</TD></TR></TABLE></DIV> </td> </tr></table> </td> </tr></table></body></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -