WIP: WIP: How to associate an action to this button ?

This commit is contained in:
Jean Sirmai 2023-11-29 17:11:02 +01:00
parent ef0519440e
commit 55e35a6859
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 77 additions and 0 deletions

View File

@ -148,3 +148,49 @@ GemGraphClientApplication *gem_graph_client_application_new(
"flags", flags,
NULL);
}
/* button-event.c
*
* Compile: cc -ggdb button-event.c -o button-event $(pkg-config --cflags --libs gtk4)
* Run: ./button-event
*
* Author: Mohammed Sadiq <www.sadiqpk.org>
*
* SPDX-License-Identifier: LGPL-2.1-or-later OR CC0-1.0
*/
#include <gtk/gtk.h>
static gboolean
gesture_released_cb (GtkWidget *widget)
{
g_warning ("do something");
return GDK_EVENT_STOP;
}
static void
app_activated_cb (GtkApplication *app)
{
GtkGesture *gesture;
GtkWindow *window;
GtkWidget *box, *label;
window = GTK_WINDOW (gtk_application_window_new (app));
gtk_window_set_default_size (window, 400, 300);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
label = gtk_label_new ("Hello");
gtk_box_append (GTK_BOX (box), label);
gtk_window_set_child (window, box);
gesture = gtk_gesture_click_new ();
g_signal_connect_object (gesture, "released",
G_CALLBACK (gesture_released_cb),
box, G_CONNECT_SWAPPED);
gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (gesture));
gtk_window_present (window);
}

View File

@ -184,6 +184,11 @@ A button is now in the GtkBox *runlib_objects of windows.c (line 61)\n\
}
/*
https://docs.gtk.org/gtk4/input-handling.html
https://stackoverflow.com/questions/76583553/how-to-use-eventcontroller-in-gtk4
https://docs.gtk.org/gobject/func.signal_connect_object.html
https://docs.gtk.org/gobject/#functions
https://docs.gtk.org/gtk4/class.Label.html?q=
https://docs.gtk.org/gtk4/ctor.Button.new_with_label.html

View File

@ -243,8 +243,21 @@ GtkWidget *create_tree_label(void)
return label;
}
#include <gtk/gtk.h>
static gboolean
gesture_released_cb (GtkWidget *widget)
{
g_warning ("do something");
printf("Hello ! I'm the button <> I've been clicked !!!\n");
return GDK_EVENT_STOP;
}
GtkWidget *create_tree_button(void)
{
GtkGesture *gesture;
GtkWidget *button;
const char *text = "Hello ! I'm the button";
@ -252,6 +265,19 @@ GtkWidget *create_tree_button(void)
gtk_box_append(GTK_BOX(window->runlib_objects), button);
gtk_widget_show(button);
gesture = gtk_gesture_click_new ();
GdkDevice *xxx = gtk_gesture_get_device (gesture); // printf("%s\n", xxx.class.name);
if (gesture) printf("Hello ! I'm the button <> I'm being clicked !!! \n");
//GtkGestureClick::pressed
g_signal_connect_object (gesture, "released",
G_CALLBACK (gesture_released_cb),
GTK_BOX(window->runlib_objects), G_CONNECT_SWAPPED);
//Use G_CALLBACK() to cast the callback function to a GCallback.
gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (gesture));
tree_c_test();
return button;