Adsense code (2021-10-05)

Thursday, December 26, 2013

GTK+3 example of Grid

GTK+3 example of Grid
GTK+3 example of Grid

#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myGrid;
    GtkWidget *button1, *button2, *button3, *button4, 
        *button5, *button6, *button7;


    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

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

    myGrid = gtk_grid_new();

    button1 = gtk_button_new_with_label("Button 1");
    button2 = gtk_button_new_with_label("Button 2");
    button3 = gtk_button_new_with_label("Button 3");
    button4 = gtk_button_new_with_label("Button 4");
    button5 = gtk_button_new_with_label("Button 5");
    button6 = gtk_button_new_with_label("Button 6");
    button7 = gtk_button_new_with_label("Button 7");
    
    gtk_grid_attach(GTK_GRID(myGrid), button1, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button2, 1, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button3, 2, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button4, 3, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button5, 0, 1, 3, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button6, 3, 1, 1, 2);
    gtk_grid_attach(GTK_GRID(myGrid), button7, 0, 2, 1, 1);

    gtk_container_add(GTK_CONTAINER (window), myGrid);
    gtk_widget_show_all (window);

    gtk_main();
    return(0);
}