WIP: OK > the button responds when clicked

This commit is contained in:
Jean Sirmai 2023-11-29 17:56:00 +01:00
parent 55e35a6859
commit 7683d71d5e
Signed by: jean
GPG Key ID: FB3115C340E057E3
2 changed files with 9 additions and 65 deletions

View File

@ -149,48 +149,5 @@ GemGraphClientApplication *gem_graph_client_application_new(
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);
}
/* https://docs.gtk.org/gtk4/input-handling.html */

View File

@ -245,38 +245,25 @@ GtkWidget *create_tree_label(void)
#include <gtk/gtk.h>
static gboolean
gesture_released_cb (GtkWidget *widget)
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_warning ("do something");
printf("Hello ! I'm the button <> I've been clicked !!!\n");
return GDK_EVENT_STOP;
printf("Yes. I'm the new 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";
const char *text = "Hello ! I'm the new button. Click me !";
button = gtk_button_new_with_label(text);
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));
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
//g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);
tree_c_test();