Today i made a step in the rigtht direction:
I used a vertical_box and packed horizontal boxes inside of it.
Also was able to create a separator and a button "quit" which closes the window.
That won't make the wizards scream, but i am ok with it.
All that padding and filling is beyond me (and probably ever will be).
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit();
return FALSE;
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *separator;
gtk_init(&argc, &argv);
/*----------------------------------------*/
/* window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL);
gtk_widget_show(window);
/*----------------------------------------*/
/* vertical box */
vbox = gtk_vbox_new(FALSE, 0);
gtk_widget_show(vbox);
/*----------------------------------------*/
/* first horizontal box */
hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox);
button = gtk_button_new_with_label("mount");
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
button = gtk_button_new_with_label("fdisk");
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
/*----------------------------------------*/
/* separator */
separator = gtk_hseparator_new();
gtk_widget_set_size_request(separator, 400, 5);
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 5);
gtk_widget_show(separator);
/*----------------------------------------*/
/* second horizontal box */
hbox = gtk_hbox_new(TRUE, 50);
gtk_widget_show(hbox);
button = gtk_button_new_with_label("cat");
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
button = gtk_button_new_with_label("less");
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
/*----------------------------------------*/
/* separator */
separator = gtk_hseparator_new();
gtk_widget_set_size_request(separator, 400, 5);
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 5);
gtk_widget_show(separator);
/*----------------------------------------*/
/* quit box */
hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox);
button = gtk_button_new_with_label("quit");
g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_main_quit), window);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 50);
gtk_widget_show(button);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
/*----------------------------------------*/
/* adding vbox to container window */
gtk_container_add(GTK_CONTAINER(window), vbox);
/*----------------------------------------*/
gtk_main();
/*----------------------------------------*/
return EXIT_SUCCESS;
}
* in C is a lot. Here it is a pointer (not multiplicate and not dereferencing).
& is the address of a variable. If a function expects a pointer, and you got a variable, say int i = 42, you can use &i to give the function what it asks for. You could also do: int *j; j = &i; and then offer j to the function. Confusing? Yes.
Both can be ignored to understand what is getting done.
Ups: Just in case,
to compile it you will need "libgtk2.0-dev" and
gcc name_of.c $(pkg-config gtk+-2.0 --cflags) $(pkg-config gtk+-2.0 --libs)
Then click on "quit" and foo, it closes. A miracle.