Skip to content

Instantly share code, notes, and snippets.

@gbluma
Last active December 25, 2015 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbluma/2d9e06511d6583821a0a to your computer and use it in GitHub Desktop.
Save gbluma/2d9e06511d6583821a0a to your computer and use it in GitHub Desktop.
Felix using and being called from GTK+3
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();
.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
@gbluma
Copy link
Author

gbluma commented Dec 25, 2015

screenshot - 12252015 - 02 01 01 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment