GtkButton – Part III

#include <gtk/gtk.h>

static void clicked_clbk ( GtkButton *button )
{
    g_return_if_fail ( GTK_IS_BUTTON ( button ) );

    g_print ( "You clicked the Button\n" );
}

static void create_button ( GtkWidget *window )
{
    GtkWidget *button;

    /// ***
    button = gtk_button_new_from_icon_name ( "computer"  );
    g_signal_connect_swapped ( button, "clicked", G_CALLBACK ( clicked_clbk ), button );

    /// ***
    gtk_button_set_icon_name ( GTK_BUTTON ( button ), "camera-web" );

    /// ***
    gtk_button_set_has_frame ( GTK_BUTTON ( button ), FALSE );

    /// ***
    g_object_set ( button, "margin-bottom", 50, NULL );
    g_object_set ( button, "margin-end", 50, NULL );
    g_object_set ( button, "margin-start", 50, NULL );
    g_object_set ( button, "margin-top", 50, NULL );

    /// ***
    gtk_window_set_child ( GTK_WINDOW ( window ), button );
}

static void activate ( GtkApplication *application, G_GNUC_UNUSED gpointer data )
{
    GtkWidget *window;

    /// ***
    window = gtk_application_window_new   ( application );

    /// ***
    gtk_window_set_default_size ( GTK_WINDOW ( window ), 200, 200 );

    /// ***
    create_button ( window );

    /// ***
    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 ), 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. Required fields are marked *