The Delight standard library includes support for creating graphical applications using GTK.
A simple Hello World program:
import dlt.gtk: *
in Gtk gtk
void main(string args):
args = gtk.init_check(args)
auto window = gtk.gtkWindow()
auto label = gtk.gtkLabel("Hello world")
Note that you must link GTK programs with the -ldltgtk option.
D provides two libraries for GTK. BCD provides low-level C-style
bindings, which GtkD wraps GTK objects in D objects to provide a
Delight, instead, adds a new external linkage type for GObject. For
interface GtkWindow extends GtkWidget:
void set_title(const(char) *title)
GtkWindow gtk_window_new(int type)
void gtk_init(int*? argc, char**? argv)
GtkWindow window = gtk_window_new(0)
No wrapping is done here. When you call window.show, Delight searches the
GtkWindow and GtkWidget interfaces (at compile time) to find the show
method. Due to the GObject linkage, this turns into a call to the C symbol
- No unnecessary casts or verbose function names (as with BCD).
- No extra objects created (as with GtkD).
- No automatic memory management. You must ref and unref these objects just
as in a C program. Also, if GTK holds a pointer to a Delight object, the
garbage collector won't see it and may collect the object anyway.
- Strings must be C-style null-terminated arrays. D constant strings are OK,
but you need to call toStringz(s) to add the null for other strings.
So, it may be worth wrapping the objects anyway. However, GtkD doesn't work
with GDC currently.