From aeda1c75899df84ba00b3e033ea02faf4a99f8ea Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Wed, 21 Dec 2022 13:41:38 +0100 Subject: [PATCH] feat: add gtk3 examples --- .gitignore | 1 + gtk3/mnemonic/exampleapp.c | 41 ++++++++++++++++++++++++++++++++++++++ gtk3/mnemonic/makefile | 23 +++++++++++++++++++++ gtk3/tooltip/exampleapp.c | 35 ++++++++++++++++++++++++++++++++ gtk3/tooltip/makefile | 23 +++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 gtk3/mnemonic/exampleapp.c create mode 100644 gtk3/mnemonic/makefile create mode 100644 gtk3/tooltip/exampleapp.c create mode 100644 gtk3/tooltip/makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4e5f6c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ \ No newline at end of file diff --git a/gtk3/mnemonic/exampleapp.c b/gtk3/mnemonic/exampleapp.c new file mode 100644 index 0000000..123d979 --- /dev/null +++ b/gtk3/mnemonic/exampleapp.c @@ -0,0 +1,41 @@ +#include + +void print_msg(GtkWidget *widget, gpointer window) { + + g_print("Button clicked\n"); +} + +int main(int argc, char *argv[]) { + + GtkWidget *window; + GtkWidget *button; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Mnemonic"); + gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); + gtk_container_set_border_width(GTK_CONTAINER(window), 15); + + /*set mnemonic*/ + button = gtk_button_new_with_mnemonic("_Button"); + + /*connect signal with callback fct print_msg*/ + g_signal_connect(button, "clicked", + G_CALLBACK(print_msg), NULL); + + /*source:https://stackoverflow.com/questions/58746046/alternative-to-deprecated-gtk-alignment-new*/ + gtk_widget_set_halign (button, GTK_ALIGN_START); + gtk_widget_set_valign (button, GTK_ALIGN_START); + + gtk_container_add(GTK_CONTAINER(window), button); + + gtk_widget_show_all(window); + + g_signal_connect(G_OBJECT(window), "destroy", + G_CALLBACK(gtk_main_quit), NULL); + + gtk_main(); + + return 0; +} diff --git a/gtk3/mnemonic/makefile b/gtk3/mnemonic/makefile new file mode 100644 index 0000000..7990516 --- /dev/null +++ b/gtk3/mnemonic/makefile @@ -0,0 +1,23 @@ +CC ?= gcc +PKGCONFIG = $(shell which pkg-config) +CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-3.0) +LIBS = $(shell $(PKGCONFIG) --libs gtk+-3.0) + +SRC = exampleapp.c + +OBJS = $(SRC:.c=.o) + +all: exampleapp + +%.o: %.c + + $(CC) -c -o $(@F) $(CFLAGS) $< + +exampleapp: $(OBJS) + + $(CC) -o $(@F) $(OBJS) $(LIBS) + +clean: + + rm -f $(OBJS) + rm -f exampleapp diff --git a/gtk3/tooltip/exampleapp.c b/gtk3/tooltip/exampleapp.c new file mode 100644 index 0000000..2bf21ce --- /dev/null +++ b/gtk3/tooltip/exampleapp.c @@ -0,0 +1,35 @@ +#include + +int main(int argc, char *argv[]) { + + GtkWidget *window; + GtkWidget *button; + GtkWidget *halign; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Tooltip"); + gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); + + /*set border space around the edges of the window*/ + gtk_container_set_border_width(GTK_CONTAINER(window), 15); + + button = gtk_button_new_with_label("Button"); + + /*set tooltop for widget*/ + gtk_widget_set_tooltip_text(button, "Button widget"); + + /*source:https://stackoverflow.com/questions/58746046/alternative-to-deprecated-gtk-alignment-new*/ + gtk_widget_set_halign (button, GTK_ALIGN_START); + gtk_widget_set_valign (button, GTK_ALIGN_START); + + gtk_container_add(GTK_CONTAINER(window), button); + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + + /*flat the container to show all widgets at once*/ + gtk_widget_show_all(window); + gtk_main(); + + return 0; +} diff --git a/gtk3/tooltip/makefile b/gtk3/tooltip/makefile new file mode 100644 index 0000000..7990516 --- /dev/null +++ b/gtk3/tooltip/makefile @@ -0,0 +1,23 @@ +CC ?= gcc +PKGCONFIG = $(shell which pkg-config) +CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-3.0) +LIBS = $(shell $(PKGCONFIG) --libs gtk+-3.0) + +SRC = exampleapp.c + +OBJS = $(SRC:.c=.o) + +all: exampleapp + +%.o: %.c + + $(CC) -c -o $(@F) $(CFLAGS) $< + +exampleapp: $(OBJS) + + $(CC) -o $(@F) $(OBJS) $(LIBS) + +clean: + + rm -f $(OBJS) + rm -f exampleapp