noob
noob

Reputation: 95

A question about a gtk's function —gtk_vbox_new()

I am a beginner in gtk, there are some codes to constuct a simple Simple menu:

#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *vbox;

GtkWidget *menubar;
GtkWidget *fileMenu;
GtkWidget *fileMi;
GtkWidget *quitMi;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_title(GTK_WINDOW(window), "Simple menu");

vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);

menubar = gtk_menu_bar_new();
fileMenu = gtk_menu_new();

fileMi = gtk_menu_item_new_with_label("File");

quitMi = gtk_menu_item_new_with_label("Quit");

gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMi), fileMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), quitMi);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMi);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);

g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

g_signal_connect(G_OBJECT(quitMi), "activate",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);
gtk_main();
return 0;
}

What does the "vbox = gtk_vbox_new(FALSE, 0);" mean? I look gtk_vbox_new() function in gtk Devhelp", it tells me that this function returns a GtkVBox — A vertical container box, who can tell me what this is? I have no idea about "vertical container box".

Upvotes: 0

Views: 697

Answers (1)

David Ranieri
David Ranieri

Reputation: 41017

What does the "vbox = gtk_vbox_new(FALSE, 0);" mean?


Packing boxes are invisible widget containers that we can pack our widgets into and come in two forms, a horizontal box, and a vertical box. When packing widgets into a horizontal box, the objects are inserted horizontally from left to right or right to left depending on the call used. In a vertical box, widgets are packed from top to bottom or vice versa. You may use any combination of boxes inside or beside other boxes to create the desired effect.

hbox:

+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 |
+---+---+---+---+---+

vbox:

+---+
| 1 |
+---+
| 2 |
+---+
| 3 |
+---+
| 4 |
+---+
| 5 |
+---+

gtk_vbox_new is deprecated in the current version (GTK3), now we should use:

gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); /* where 10 is an arbitrary padding */

or

gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); 

Upvotes: 3

Related Questions