Skip to content

Latest commit

 

History

History
171 lines (143 loc) · 6.54 KB

index.md

File metadata and controls

171 lines (143 loc) · 6.54 KB
layout
wide

Rust bindings for GTK+ 3, Cairo, GtkSourceView and other GLib-compatible libraries

GTK screenshot

Crates

{% include badges.html %}

Announcements

{% for post in site.categories.front limit:3 %} {{ post.date | date: "%-d %b %Y" }}

{{ post.title }}

{% endfor %}
Crate Minimum supported version
atk 2.30
cairo 1.14
gdk 3.16
gdk-pixbuf 2.32
gdk-x11 3.14
gio 2.44
glib 2.44
gtk 3.16
pango 1.38
pangocairo 1.0
sourceview 3.0

Using

First, prepare your system by taking a look at the GTK installation page.

Then include gtk and gio in your Cargo.toml and set the minimal GTK version required by your project: {% assign gtk = site.data.crates | where: "name", "gtk" %}

[dependencies.gtk]
version = "{{ gtk[0].max_version }}"
features = ["v3_16"]

[dependencies.gio]
version = "{{ gio[0].max_version }}"
features = ["v2_44"]

The code is stable and feature complete, but the APIs might change in the future.

Import the gtk and gio crates and their traits:

extern crate gtk;
extern crate gio;

use gtk::prelude::*;
use gio::prelude::*;

Create an application, etc.

use gtk::{Application, ApplicationWindow, Button};

fn main() {
    let application = Application::new(
        Some("com.github.gtk-rs.examples.basic"),
        Default::default(),
    ).expect("failed to initialize GTK application");

    application.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title("First GTK+ Program");
        window.set_default_size(350, 70);

        let button = Button::with_label("Click me!");
        button.connect_clicked(|_| {
            println!("Clicked!");
        });
        window.add(&button);

        window.show_all();
    });

    application.run(&[]);
}

Using latest, not published version

Include gtk in your Cargo.toml not as crate but from git:

[dependencies.gtk]
git = "https://github.com/gtk-rs/gtk"
features = ["v3_16"]

Projects using gtk-rs

If you want yours to be added to this list, please create a Pull Request for it!