GTK and Vala
About Vala
Vala is a programming language using modern high level abstractions without imposing additional runtime requirements and without using a different ABI compared to applications and libraries written in C. Vala uses the GObject type system and has additional code generation routines that make targeting the GNOME stack simple. Vala has many other uses where native binaries are required..
GTK Documentation for Vala
There is an official GTK API Documentation for using GTK and Vala together, deals with the Vala bindings for GLib, GTK, Cairo, GtkSourceView and other GLib-compatible libraries(more than 256).
There are also a growing number of examples and through tests of language features in the test suite.
You can see many Vala and GTK based projectsGNOME Wiki and Github Repositories.
Tutorials
Vala website lists various tutorials that range from an introduction to the language, to its use with GTK, and much more.
A Hello World app
Below is an Hello World
program that can be used as an example to get started with GTK Vala binding.
// Save this code as "hello_world.vala"
int main (string[] argv) {
// Create a new application
var app = new Gtk.Application ("com.example.GtkApplication",
GLib.ApplicationFlags.DEFAULT_FLAGS);
app.activate.connect (() => {
// Create a new window
var window = new Gtk.ApplicationWindow (app);
// Create a new button
var button = new Gtk.Button.with_label ("Hello, World!");
// When the button is clicked, close the window
button.clicked.connect (() => {
window.close ();
});
window.set_child (button);
window.present ();
});
return app.run (argv);
}
To compile the program, copy it in your favorite text editor, save it as hello_world.vala
, and compile it from the command line using:
valac --pkg gtk4 hello_world.vala
Contribute
If you are interested in contributing to the Vala and GTK binding project, you can get a head start by reading the instructions on how to get started for contributing to Vala here.
If you want to get in touch with the original source files, you can visit the project’s git repository on GNOME.
See More
- Project: https://gitlab.gnome.org/GNOME/vala
- Docs: https://valadoc.org/
- Tutorial: https://wiki.gnome.org/Projects/Vala/Tutorial