feat: add gtk3 examples
This commit is contained in:
parent
f08e851a61
commit
aeda1c7589
|
@ -0,0 +1 @@
|
|||
*~
|
|
@ -0,0 +1,41 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,35 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue