// gtk.wren (GTK3 bindings)
foreign class Gtk {
foreign static init_()
foreign static run_()
foreign static quit_()
static init() { init_() }
static run() { run_() }
static quit() { quit_() }
}
foreign class Window {
// Allocated on the C side; init_ configures the GtkWindow
construct new(title, width, height) {
init_(title, width, height)
}
// --- foreigns ---
foreign init_(title, width, height)
foreign setTitle(title)
foreign setDefaultSize(width, height)
foreign add(child)
foreign showAll()
// DO NOT declare "foreign onDestroy(_)" here; that would collide with the wrapper below.
foreign onDestroy_(fn)
// --- wrappers with validation ---
onDestroy(fn) {
if (!(fn is Fn) || fn.arity != 0) Fiber.abort("onDestroy expects Fn with arity 0")
onDestroy_(fn)
}
}
foreign class Box {
// Two convenience constructors mapping to distinct foreign inits
construct vbox(spacing) { vbox_(spacing) }
construct hbox(spacing) { hbox_(spacing) }
// --- foreigns ---
foreign vbox_(spacing)
foreign hbox_(spacing)
foreign packStart(child, expand, fill, padding)
}
foreign class Button {
construct new(label) { init_(label) }
// --- foreigns ---
foreign init_(label)
foreign setLabel(label)
// Distinct foreign name to avoid colliding with the wrapper
foreign onClicked_(fn)
// --- wrapper ---
onClicked(fn) {
if (!(fn is Fn) || fn.arity != 0) Fiber.abort("onClicked expects Fn with arity 0")
onClicked_(fn)
}
}
foreign class Entry {
construct new() { init_() }
// --- foreigns ---
foreign init_()
foreign setText(text)
foreign text
foreign onActivate_(fn)
foreign onChanged_(fn)
// --- wrappers ---
onActivate(fn) {
if (!(fn is Fn) || fn.arity != 0) Fiber.abort("onActivate expects Fn with arity 0")
onActivate_(fn)
}
onChanged(fn) {
if (!(fn is Fn) || fn.arity != 0) Fiber.abort("onChanged expects Fn with arity 0")
onChanged_(fn)
}
}
foreign class Label {
construct new(text) { init_(text) }
// --- foreigns ---
foreign init_(text)
foreign setText(text)
}