Upload files to "/"

This commit is contained in:
Kevin Kandlbinder 2025-03-26 12:37:55 +01:00
commit db97b26566
3 changed files with 144 additions and 0 deletions

45
advanced.c Normal file
View file

@ -0,0 +1,45 @@
#include <gtk/gtk.h>
#include <glib/gstdio.h>
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkBuilder *builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "builder.ui", NULL);
GObject *window = gtk_builder_get_object (builder, "window");
gtk_window_set_application (GTK_WINDOW (window), app);
GObject *button = gtk_builder_get_object (builder, "button1");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
button = gtk_builder_get_object (builder, "button2");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
gtk_window_present (GTK_WINDOW (window));
g_object_unref (builder);
}
int
main (int argc,
char *argv[])
{
GtkApplication *app = gtk_application_new ("dev.kevink.example2", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
// gcc $(pkg-config --cflags libadwaita-1) -o advanced-gtk advanced.c $(pkg-config --libs libadwaita-1) && ./advanced-gtk

53
builder.ui Normal file
View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object id="window" class="GtkWindow">
<property name="title">Advanced Example</property>
<property name="default-width">300</property>
<property name="default-height">200</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="title-widget">
<object class="GtkLabel">
<property name="label" translatable="yes">Advanced ✨</property>
<property name="single-line-mode">True</property>
<property name="ellipsize">end</property>
<property name="width-chars">5</property>
<style>
<class name="title"/>
</style>
</object>
</property>
</object>
</child>
<child>
<object id="grid" class="GtkGrid">
<property name="hexpand">TRUE</property>
<property name="vexpand">TRUE</property>
<child>
<object id="button1" class="GtkButton">
<property name="label">First Button</property>
<property name="hexpand">TRUE</property>
<property name="vexpand">TRUE</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object id="button2" class="GtkButton">
<property name="label">Second Button</property>
<property name="hexpand">TRUE</property>
<property name="vexpand">TRUE</property>
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</interface>

46
hello-world.c Normal file
View file

@ -0,0 +1,46 @@
#include <gtk/gtk.h>
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
gtk_application_set
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello World");
gtk_window_set_default_size (GTK_WINDOW (window), 250, 200);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("dev.kevink.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
// gcc $(pkg-config --cflags gtk4) -o hello-world-gtk hello-world.c $(pkg-config --libs gtk4) && ./hello-world-gtk