Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
Created March 2, 2022 18:28
Embed
What would you like to do?
module gtk;
macro import neat.macros.cimport;
import std.stdio;
import c_header("glib.h");
import c_header("gtk/gtk.h");
void print_hello(void* widget, void* data) {
print("Hello World");
}
void main() {
gtk_init(null, null);
auto window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
window.gtk_window_set_title("Window");
window.gtk_window_set_default_size(200, 200);
g_signal_connect(window, "destroy", cast(void*) &gtk_main_quit, null);
auto button = gtk_button_new_with_label("Hello World");
g_signal_connect(button, "clicked", cast(void*) &print_hello, null);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main;
}
void gtk_main_quit() { import c_header("gtk/gtk.h") : gtk_main_quit; gtk_main_quit; }
extern(C) void* g_type_check_instance_cast(void*, size_t);
alias GtkWindow = void;
GtkWindow* GTK_WINDOW(void* p) {
return cast(GtkWindow*) g_type_check_instance_cast(p, gtk_window_get_type());
}
alias GtkContainer = void;
GtkContainer* GTK_CONTAINER(void* p) {
return cast(GtkContainer*) g_type_check_instance_cast(p, gtk_container_get_type());
}
void g_signal_connect(void* instance, char* detailed_signal, void* handler, void* data) {
g_signal_connect_data(
instance,
detailed_signal,
cast(void function(void)) handler,
data,
cast(void function(void*, GClosure*)) null,
0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment