Skip to content

Instantly share code, notes, and snippets.

@angstyloop
Created May 12, 2023 07:14
Show Gist options
  • Save angstyloop/f55f1c32b2d17492efc32b83c00208a4 to your computer and use it in GitHub Desktop.
Save angstyloop/f55f1c32b2d17492efc32b83c00208a4 to your computer and use it in GitHub Desktop.
GTK4 Example: Popover containing a TextView
/** popover.c
*
* COMPILE
*
* gcc `pkg-config --cflags gtk4` -o popover popover.c `pkg-config --libs gtk4`
*
* RUN
*
* ./popover
*/
//static int app_flags = G_APPLICATION_FLAGS_NONE;
#include <gtk/gtk.h>
static void
activate( GtkApplication *app, gpointer user_data )
{
GtkWidget *window, *box, *popover;
window = gtk_application_window_new( app );
gtk_window_set_title( GTK_WINDOW( window ), "Window" );
gtk_window_set_default_size( GTK_WINDOW( window ), 1000, 1000 );
box = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
gtk_window_set_child( GTK_WINDOW( window ), box );
popover = gtk_popover_new();
gtk_widget_set_parent( popover, box );
gtk_popover_set_has_arrow( GTK_POPOVER( popover ), FALSE );
gtk_popover_set_position( GTK_POPOVER( popover ), GTK_POS_RIGHT );
gtk_popover_set_child( GTK_POPOVER( popover ),
gtk_text_view_new() );
gtk_widget_set_size_request( popover, 1000, 1000 );
gtk_widget_show( window );
gtk_popover_popup( GTK_POPOVER( popover ) );
}
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