Last active
December 25, 2015 08:01
-
-
Save gbluma/2d9e06511d6583821a0a to your computer and use it in GitHub Desktop.
Felix using and being called from GTK+3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export requires header """ #include <gtk/gtk.h> """, package "gtk"; | |
type GtkApplication_ptr = "GtkApplication*"; | |
type GtkWidget_ptr = "GtkWidget*"; | |
type gpointer = "gpointer"; | |
cproc hello (widget:GtkWidget_ptr, data:gpointer) = { [21/1899] | |
var text = cexpr [+char] """ | |
(char*) gtk_entry_buffer_get_text( | |
gtk_entry_get_buffer( (GtkEntry*) $1 ) | |
) | |
""" (data) endcexpr; | |
println$ "hello from felix: " + text; | |
} | |
cproc destroy () = { | |
cstmt """ gtk_main_quit (); """; | |
} | |
cproc activate (app:GtkApplication_ptr, user_data:gpointer) = { | |
cstmt """ | |
auto window = | |
gtk_application_window_new ($1); | |
auto button_box = | |
gtk_button_box_new (GTK_ORIENTATION_VERTICAL); | |
gtk_container_add (GTK_CONTAINER (window), button_box); | |
auto button = | |
gtk_button_new_with_label ("Hello Felix"); | |
auto tf = | |
gtk_entry_new (); | |
g_signal_connect (button, "clicked", G_CALLBACK ($2), tf); | |
gtk_container_add (GTK_CONTAINER (button_box), button); | |
gtk_container_add (GTK_CONTAINER (button_box), tf); | |
gtk_window_set_title (GTK_WINDOW (window), "Felix Window"); | |
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200); | |
gtk_widget_show_all (window); | |
""" | |
(app, hello) | |
; | |
} | |
proc init_app() = { | |
cstmt """ | |
auto app = | |
gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE); | |
g_signal_connect (app, "activate", G_CALLBACK ($3), NULL); | |
int status = | |
g_application_run (G_APPLICATION (app), $1, $2); | |
g_object_unref (app); | |
""" | |
(System::argc, System::_argv, activate) | |
; | |
} | |
init_app(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: test | |
test: gtk.fpc | |
flx --pkgconfig-path+=. --static -o app gtk.flx | |
gtk.fpc: | |
echo "cflags: `pkg-config --cflags gtk+-3.0`" > gtk.fpc | |
echo "requires_slibs: `pkg-config --libs gtk+-3.0`" >> gtk.fpc |
Author
gbluma
commented
Dec 25, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment