Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

GtkBox

A GtkBox manages a row (GtkHBox) or column (GtkVBox) of widgets. For GtkHBox, all the widgets are assigned the same height; the box's job is to distribute the available width between them. GtkHBox optionally uses some of the available width to leave gaps (called "spacing") between widgets. GtkVBox is identical, but in the opposite direction (i.e., it distributes available height rather than width). GtkBox is an abstract base class; GtkVBox and GtkHBox can be used almost entirely via its interface. Boxes are the most useful container widget.

To create a GtkBox, you use one of the constructors shown in Figure 2 and Figure 3. The box constructor functions take two parameters. If TRUE, homogeneous means that all children of the box will be allocated the same amount of space. spacing specifies the amount of space between each child. There are functions to change spacing and toggle homogeneity after the box is created.

#include <gtk/gtkhbox.h>

GtkWidget* gtk_hbox_new(gboolean homogeneous, gint spacing);

Figure 2. GtkHBox Constructor

#include <gtk/gtkvbox.h>

GtkWidget* gtk_vbox_new(gboolean homogeneous, gint spacing);

Figure 3. GtkVBox Constructor

There are two basic functions to add a child to a GtkBox; they are shown in Figure 4.

#include <gtk/gtkbox.h>

void gtk_box_pack_start(GtkBox* box, GtkWidget* child, gboolean expand, gboolean fill, gint padding);

void gtk_box_pack_end(GtkBox* box, GtkWidget* child, gboolean expand, gboolean fill, gint padding);

Figure 4. Packing GtkBox

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. Figure 5 shows this for GtkVBox. 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.

Figure 5. Buttons packed into a GtkVBox

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire