Last active
May 4, 2023 05:09
-
-
Save angstyloop/cd1ef402238b61605e067fa680cf89a4 to your computer and use it in GitHub Desktop.
Basic usage of ( now deprecated, but still incredibly useful, in GTK 4 ) GtkInfoBar widget as a "toast".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** infobar.c | |
* | |
* COMPILE | |
* | |
* gcc `pkg-config --cflags gtk4` -o infobar infobar.c `pkg-config --libs gtk4` | |
* | |
* RUN | |
* | |
* ./infobar | |
* | |
* SOURCE | |
* | |
* https://docs.gtk.org/gtk4/class.InfoBar.html | |
*/ | |
#include <gtk/gtk.h> | |
#include <libintl.h> | |
static void | |
activate( GtkApplication *app, gpointer user_data ) | |
{ | |
GtkWidget *window, *message_label, *widget, *grid; | |
GtkInfoBar *bar; | |
window = gtk_application_window_new( app ); | |
gtk_window_set_title( GTK_WINDOW( window ), "Window" ); | |
gtk_window_set_default_size( GTK_WINDOW( window ), 200, 200 ); | |
widget = gtk_info_bar_new(); | |
bar = GTK_INFO_BAR( widget ); | |
grid = gtk_grid_new(); | |
gtk_window_set_child( GTK_WINDOW( window ), grid ); | |
message_label = gtk_label_new( "" ); | |
gtk_info_bar_add_child( bar, message_label ); | |
//gtk_info_bar_add_button( bar, gettext("_OK"), GTK_RESPONSE_OK ); | |
gtk_info_bar_set_show_close_button( GTK_INFO_BAR( bar ), | |
TRUE ); | |
g_signal_connect( bar, "response", | |
G_CALLBACK( gtk_widget_hide ), NULL ); | |
gtk_grid_attach( GTK_GRID( grid ), widget, 0, 2, 1, 1 ); | |
gtk_label_set_text( GTK_LABEL( message_label ), | |
"An error occurred!" ); | |
gtk_info_bar_set_message_type( bar, GTK_MESSAGE_ERROR ); | |
gtk_widget_show( GTK_WIDGET( bar ) ); | |
gtk_widget_show( window ); | |
} | |
int | |
main( int argc, char **argv ) | |
{ | |
GtkApplication *app; | |
int status; | |
app = gtk_application_new( "org.gtk.example", | |
G_APPLICATION_FLAGS_NONE ); | |
g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL ); | |
status = g_application_run( G_APPLICATION( app ), argc, argv ); | |
g_object_unref( app ); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment