GtkBox – Part IV

#include <gtk/gtk.h>

static void activate_clbk ( GtkApplication *application )
{
    GtkWidget *window;
    GtkWidget *grid;
    GtkWidget *label;
    GtkWidget *button;

    /// ***
    window = gtk_application_window_new   ( application );
    gtk_window_set_default_size ( GTK_WINDOW ( window ), 300, 400 );

    /// ***
    grid = gtk_grid_new ();

    /// ***
    gtk_grid_set_column_spacing ( GTK_GRID ( grid ), 8 );
    gtk_grid_set_row_spacing ( GTK_GRID ( grid ), 8 );

    for ( int j = 0; j < 3; j++ )
    {
        const char *baseline_label[] = { "  Set to TOP", "  Set to CENTER", "  Set to BOTTOM"};
        const int b_lines[]          = { GTK_BASELINE_POSITION_TOP, GTK_BASELINE_POSITION_CENTER, GTK_BASELINE_POSITION_BOTTOM };

        /// ***
        label = gtk_label_new ( "     Baseline     " );

        /// ***
        gtk_widget_set_vexpand ( label, TRUE );

        /// ***
        gtk_grid_attach ( GTK_GRID ( grid ), label, 0, j, 1, 1 );

        /// ***
        button = gtk_button_new_with_label ( baseline_label[j] );

        /// ***
        gtk_widget_set_valign ( button, GTK_ALIGN_BASELINE );

        /// ***
        gtk_grid_set_row_baseline_position ( GTK_GRID ( grid ), j, b_lines[j] );

        /// ***
        gtk_grid_attach ( GTK_GRID ( grid ), button, 1, j, 1, 1 );
    }

    /// ***
    gtk_window_set_child ( GTK_WINDOW ( window ), grid );

    /// ***
    gtk_window_present ( GTK_WINDOW ( window ) );
}

int main ( void )
{
    GtkApplication *application;
    gint status;

    /// ***
    application = gtk_application_new ( "this.is.my-nice.app", G_APPLICATION_FLAGS_NONE );

    /// ***
    g_signal_connect ( application, "activate", G_CALLBACK ( activate_clbk ), NULL );

    /// ***
    status = g_application_run ( G_APPLICATION ( application ), FALSE, NULL );

    /// ***
    g_object_unref ( application );
    return status;
}
Author: MichaelB

Leave a Reply

Your email address will not be published.