Reputation: 63636
It seems to me that both functions can be used to add some widget to the container.
What's the difference?
Upvotes: 3
Views: 3030
Reputation: 591
gtk_container adds widgets to the container(by the way many widgets can be containers) and gtk_box_pack_start is used for packing of widgets in some virtual entities called boxes which are also widgets. Adding just puts them into a container according to some predefined rules where as in packing you tell how to add widgets and then add this arranged widgets tothe container.
Upvotes: 3
Reputation: 137
On a GtkBox, the following pseudo-code is equivalent:
gtk_container_add(box, widget)
gtk_box_pack_start(box, widget, default_expand, default_expand, 0)
http://git.gnome.org/browse/gtk+/tree/gtk/gtkbox.c#n1665
Upvotes: 3
Reputation: 19214
gtk_pack_start
gives you more control over how child widgets are allocated space. You can control whether child widgets will "expand" (allocate any extra space), "fill" (use all allocated space or only minimum space requested by them), and amount of padding given to child. So, if your container id a GtkBox, gtk_box_pack_start
/gtk_box_pack_end
is preferred, as gtk_container_add will work, but use default values, which are not optimal most of the time.
Upvotes: 4
Reputation: 4935
GtkBox is further down the object hierarchy than GtkContainer, that is GtkBox adds the notion of packing to GtkContainer, with GtkContainer adding the ability for GtkWidgets to contain other GtkWidgets.
In short, GtkBox gives you more control over the layout of the contained widgets.
So if you need more control use gtk_box_pack_start to pack widgets, for example adding a number of aligned combo boxes within a hbox, otherwise use gtk_container_add, for example adding a frame to a window.
http://library.gnome.org/devel/gtk/stable/GtkContainer.html#GtkContainer.description
http://library.gnome.org/devel/gtk/stable/GtkBox.html#GtkBox.description
Upvotes: 3