Rust bindings and wrappers for GLib, GDK 3, GTK+ 3 and Cairo.

Related tags

GUI rgtk
Overview

THIS REPOSITORY IS DEPRECATED SEE: https://github.com/rust-gnome rgtk Build Status Gitter chat

Rust bindings and wrappers for GLib, GDK 3, GTK+ 3 and Cairo.

Building

rgtk expects GTK+, GLib and Cairo development files to be installed on your system. Optionally, it is recommended to install the debug packages containing helpful debug symbols.

Debian and Ubuntu

> sudo apt-get install libgtk-3-dev
> sudo apt-get install libgtk-3-0-dbg libglib2.0-0-dbg libcairo2-dbg

Fedora

> sudo yum install gtk3-devel glib2-devel

OS X

Install XQuartz, then:

> brew install gtk+3 --without-x11
> export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig

Windows

Install mingw-w64 (select the win32 threading model) and download a GTK+ SDK:

Make sure both mingw's and the sdk's bin directories are in your PATH e.g. (assuming mingw is installed in C:\mingw-w64 and the SDK unpacked into C:\gtk)

C:\> set PATH="C:\mingw-w64\bin;C:\gtk\bin;%PATH%"

It's crucial that GCC from mingw is used by Rust so either make sure that mingw is earlier in the PATH or delete gcc.exe and ld.exe from the Rust installation.

Versions and features

rgtk targets GTK+ 3.6 and Cairo 1.10 by default, other versions support is enabled by requesting a corresponding feature e.g.

> cargo build --features "GTK_3_10 CAIRO_1_12"

Currently supported versions are GTK+ 3.4 to 3.14 and Cairo 1.10 to 1.12.

We are currently targetting rust master compiler to build rgtk, make sure you have the latest version before submitting any bugs.

In examples you can find some tests showing off the functionality, these can be built and run as follows:

> cd examples
> cargo build --release
# Or, if your system has GTK 3.10 or later
> cargo build --features GTK_3_10 --release
> ./target/release/gtktest
> ./target/release/cairotest

When building documentation don't forget to specify the feature set you're using:

> cargo doc --feature GTK_3_12

Your local copy can be accessed using your browser at

file:///{rgtk_location}/target/doc/rgtk/index.html

You can also access a daily build of the docs via the internet:

http://rust-ci.org/jeremyletang/rgtk/doc/rgtk/

Including rgtk as a cargo dependency

To include rgtk as a cargo dependency you have to add it to your Cargo.toml and specify the GTK version you want using Cargo features

[dependencies.rgtk]
git = "https://github.com/jeremyletang/rgtk.git"
features = ["GTK_3_12"]

Use rgtk

To implement GTK+ inheritance in rust, we implemented gtk superclasses as traits located in rgtk::gtk::traits::*. The various widgets implement these traits and live in rgtk::gtk::*.

For your convenience the various traits are reexported in the rgtk::* namespace as Gtk{trait_name}Trait so you can just use...

extern mod rgtk;
use rgtk::*;

...to easily access all the gtk widgets and all traits methods:

let button = gtk::Button:new(); // You have access to the struct methods of gtk::Button aswell
                                // as the trait methods from gtk::traits::Button as GtkButtonTrait.

Projects using rgtk

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

Contribute

Contributor you're welcome!

You probably know but Gtk+ uses its own GObject system: inherited class and interface.

To respect this design, I follow a special design on rgtk:

  • Interface -> Implement them on a trait with only default methods.
  • Class -> Implement the construct on the class impl and other methods on a traits.
  • Sub-class -> Implement all the methods on the class.

Example for GtkOrientable, GtkBox, GtkButtonBox:

GtkOrientable is an interface with all methods implemented as default method of the trait gtk::traits::Orientable.

GtkBox is a class with constructors implemented on the struct gtk::Box, and the other method as default methods of the trait gtk::traits::Box. So gtk::Box implements gtk::traits::Orientable and gtk::traits::Box.

GtkButtonBox is a sub-class of GtkBox, the struct gtk::ButtonBox implements all the methods of GtkButtonBox and the traits gtk::traits::Orientable and gtk::traits::Box.

Finally, all the gtk widgets implement the trait gtk::traits::Widget.

License

rgtk is available under the same license term as GTK+: the LGPL (Lesser General Public license).

Comments
  • Add TreeStore and ListStore

    Add TreeStore and ListStore

    This fixes #60 by wrapping TreeStore and ListStore, so TreeViews can display content. The idea is that it should work like this:

    let mut project_tree = gtk::TreeView::new().unwrap();
    let column_types = vec![glib::ffi::g_type_string];
    let tree_store = gtk::TreeStore::new(column_types).unwrap();
    let model = tree_store.get_model().unwrap();
    project_tree.set_model(&model);
    

    Here's what I think still needs to be done:

    • ~~Complete all the TreeStore/ListStore functions~~
    • ~~Create an enum that maps to the various GType constants~~
    • ~~TreeView's getter functions seem to have the "get_" omitted, which seems inconsistent with other widgets like IconView, so that should probably be fixed~~
    opened by oakes 35
  • Missing GtkBuilder methods

    Missing GtkBuilder methods

    Why are methods like these commented out in the source:

    pub fn gtk_builder_add_from_file(builder: *mut C_GtkBuilder, file_name: *const c_char, error: *mut *mut C_GError) -> c_uint;
    

    This particular method is a very useful one, as it's used to instantiate the view from a Glade file.

    opened by gsingh93 23
  • Added gdk_keyval_name function

    Added gdk_keyval_name function

    I implemented the keyval_name function, solving issue #203. I tested it and it works. But could someone have a look and see if the fix looks okay.

    For instance I am unsure about line 32 in keys.rs. I had to comment that out since my program would crash otherwise. Similar gdk functions that return the same type (like gdk_screen_get_monitor_plug_name) however suggest that it should be there.

    The other thing I'm uncertain about is whether the return type of this

    pub fn gdk_keyval_name (keyval:c_uint) -> *mut c_char;
    

    should be immutable as this says "The [returned] String should not be modified".

    opened by ptersilie 18
  • Support the Quartz backend on OS X

    Support the Quartz backend on OS X

    Fix #2 by mentioning the custom homebrew formula pointed out by @dubcanada. The only fix needed is that GtkSocket needs to be stubbed out because it doesn't look like the Quartz backend supports it. Compiling with this is much better than with X11.

    opened by oakes 17
  • Trying to run examples/gtktest on OS X using homebrew libraries: `cargo build` fails

    Trying to run examples/gtktest on OS X using homebrew libraries: `cargo build` fails

    $ cargo run --verbose
       Compiling rgtk v0.0.1 (file:///rust/rgtk/examples/gtktest)
         Running `rustc src/rgtk.rs --crate-name rgtk --crate-type rlib -g --cfg feature="GTK_3_10" -C metadata=0166c31074c24165 -C extra-filename=-0166c31074c24165 --out-dir /rust/rgtk/examples/gtktest/target/deps --dep-info /rust/rgtk/examples/gtktest/target/.fingerprint/rgtk-0166c31074c24165/dep-lib-rgtk -L /rust/rgtk/examples/gtktest/target/deps -L /rust/rgtk/examples/gtktest/target/deps -L /rust/rgtk/examples/gtktest/target/native/rgtk-0166c31074c24165`
    src/rgtk.rs:1:1: 1:1 error: can't find crate for `std`
    src/rgtk.rs:1 // This file is part of rgtk.
                  ^
    error: aborting due to previous error
    Could not compile `rgtk`.
    
    Caused by:
      Process didn't exit successfully: `rustc src/rgtk.rs --crate-name rgtk --crate-type rlib -g --cfg feature="GTK_3_10" -C metadata=0166c31074c24165 -C extra-filename=-0166c31074c24165 --out-dir /rust/rgtk/examples/gtktest/target/deps --dep-info /rust/rgtk/examples/gtktest/target/.fingerprint/rgtk-0166c31074c24165/dep-lib-rgtk -L /rust/rgtk/examples/gtktest/target/deps -L /rust/rgtk/examples/gtktest/target/deps -L /rust/rgtk/examples/gtktest/target/native/rgtk-0166c31074c24165` (status=101)
    
    opened by nicerobot 17
  • is_modified wrong?

    is_modified wrong?

    While looking at how EventKey works i was comparing https://developer.gnome.org/gdk3/stable/gdk3-Event-Structures.html#GdkEventKey with https://github.com/jeremyletang/rgtk/blob/master/src/gdk/events.rs#L204

    The official doc says that this is called "is_modifier" and it's a flag if the key is a modifier, whereas the rgtk is a u32.

    opened by buster 16
  • Updated documentation

    Updated documentation

    • Updated README.md
    • Shortened and spread out rgtk.rs and gtk/mod.rs documentation
    • Add documentation stubs for gdk/mod.rs, glib/mod.rs and cairo/mod.rs
    opened by mathijshenquet 13
  • Windows support

    Windows support

    Several fixes to support windows build.

    1. C function gtk_recent_info_get_applications accepts a pointer to 'gulong' as a second argument. Unsigned long is 64bit on linux but 32 bit on windows.
    2. Now examples don't link - undefined references to gtk_glue cast_Gtk* symbols. It seems that functions in #ifdef GTK_ conditionals are not included, because GTK_VERSION define is not passed to the gcc.
    3. More undefined references to gtk_glue. #ifdef GTK_* conditionals are wrong. 3_6 symbols exist in 3_10 and 3_12, 3_10 in 3_12. Uncommented GApp* stuff in gtk_glue.
    4. Linking errors on g_app* symbols. Passing gio to link flags fixes this.

    Tested on windows using msys2_64, linux64. Gtk version 3.13. Rgtk built for GTK_3_12.

    opened by dndanik 12
  • Add glib refcounting to gtk widgets, fixes #35

    Add glib refcounting to gtk widgets, fixes #35

    Needs some discussion regarding impl Clone. I know Jeremy dislikes this approach but I think it can make sense.

    Conceptually a gtk widget (Button, Window etc...) in rust can be thought of as a reference to the concrete widget on the screen. In that sense a clone makes sense and just gives you another reference to the concrete widget.

    On the other hand this may be confusing to users, where they expect an whole new Button or Window in case of a clone, in this case we should implement something like widget.reference() to do the same. This has the disadvantage of being non obvious in the sense the Clone is pretty populair trait.

    Let me know what you think,

    opened by mathijshenquet 12
  • Suggestion: Favour `fail!` over `Option<T>` for error states

    Suggestion: Favour `fail!` over `Option` for error states

    When foreign functions are nearly sure to return proper values dont wrap in an Option monad for invalid data but just fail!.

    I think it is OK to fail! instead of Option when there is really an error state. The resulting api is also a lot cleaner.

    opened by mathijshenquet 12
  • make failed

    make failed

    $ make

    cc -DGTK_3_12 -g -c gtk_glue/gtk_glue.c -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12   -o target/deps/librgtk_glue.o -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0   -fPIC
    gtk_glue/gtk_glue.c:455:1: error: unknown type name ‘GtkFlowBox’
     GtkFlowBox* cast_GtkFlowBox(GtkWidget* widget) {
     ^
    gtk_glue/gtk_glue.c: In function ‘cast_GtkFlowBox’:
    gtk_glue/gtk_glue.c:456:5: warning: return makes pointer from integer without a cast [enabled by default]
         return GTK_FLOW_BOX(widget);
         ^
    gtk_glue/gtk_glue.c: At top level:
    gtk_glue/gtk_glue.c:459:1: error: unknown type name ‘GtkFlowBoxChild’
     GtkFlowBoxChild* cast_GtkFlowBoxChild(GtkWidget* widget) {
     ^
    gtk_glue/gtk_glue.c: In function ‘cast_GtkFlowBoxChild’:
    gtk_glue/gtk_glue.c:460:5: warning: return makes pointer from integer without a cast [enabled by default]
         return GTK_FLOW_BOX_CHILD(widget);
         ^
    gtk_glue/gtk_glue.c: At top level:
    gtk_glue/gtk_glue.c:463:1: error: unknown type name ‘GtkActionBar’
     GtkActionBar* cast_GtkActionBar(GtkWidget* widget) {
     ^
    gtk_glue/gtk_glue.c: In function ‘cast_GtkActionBar’:
    gtk_glue/gtk_glue.c:464:5: warning: return makes pointer from integer without a cast [enabled by default]
         return GTK_ACTION_BAR(widget);
         ^
    make: *** [target/deps/librgtk_glue.o] Error 1
    
    opened by electricface 10
  • Deprecation link is broken

    Deprecation link is broken

    The link in the header is broken:

     GTK+ bindings and wrappers for Rust (DEPRECATED SEE https://github.com/rust-gnome ) 
    

    Should it be this one?

    https://github.com/gtk-rs/gtk
    
    opened by chrismiddleton 2
  • 32bit support?

    32bit support?

    Hi,

    i just wanted to compile my program on i386 (Atom based netbook) but the steps show the following errors. I guess this is due to the netbook being 32bit? Or could this be something different?

    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:70:18: 70:87 error: mismatched types:
     expected `i64`,
        found `i32`
    (expected i64,
        found i32) [E0308]
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:70         unsafe { ffi::gtk_recent_info_get_added(GTK_RECENT_INFO(self.unwrap_widget())) }
                                                                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:74:18: 74:90 error: mismatched types:
     expected `i64`,
        found `i32`
    (expected i64,
        found i32) [E0308]
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:74         unsafe { ffi::gtk_recent_info_get_modified(GTK_RECENT_INFO(self.unwrap_widget())) }
                                                                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:78:18: 78:89 error: mismatched types:
     expected `i64`,
        found `i32`
    (expected i64,
        found i32) [E0308]
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:78         unsafe { ffi::gtk_recent_info_get_visited(GTK_RECENT_INFO(self.unwrap_widget())) }
                                                                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:97:21: 97:31 error: mismatched types:
     expected `*mut i32`,
        found `&mut i64`
    (expected i32,
        found i64) [E0308]
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gtk/widgets/recent_info.rs:97                     &mut time_));
                                                                                                                         ^~~~~~~~~~
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gdk/widgets/pixbuf.rs:74:18: 74:90 error: mismatched types:
     expected `u64`,
        found `u32`
    (expected u64,
        found u32) [E0308]
    /home/buster/.cargo/git/checkouts/rgtk-1b1dd31ed25241cd/master/src/gdk/widgets/pixbuf.rs:74         unsafe { ffi::gdk_pixbuf_get_byte_length(self.pointer as *const ffi::C_GdkPixbuf) }
                                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    error: aborting due to 5 previous errors
    Could not compile `rgtk`.
    
    To learn more, run the command again with --verbose.
    
    opened by buster 13
  • Draw/Cairo broken

    Draw/Cairo broken

    It seems like cairo (or at least connecting the draw function to a drawing area) is broken since the last big update. The example cairotest crashes instantly unless

    Connect::connect(&drawing_area, Draw::new(draw_fn));
    

    is commented out.

    opened by ptersilie 26
  • Add new trait : GtkStatusIcon

    Add new trait : GtkStatusIcon

    As discussed I'm adding this issue, but I'd love to contribute and fix it myself.

    Anyways, I'm gonna wait for it build with the alpha version https://github.com/jeremyletang/rgtk/pull/177

    GTK Reference

    enhancement 
    opened by mfaerevaag 4
  • Submit to crates.io

    Submit to crates.io

    This should be submitted to crates.io. As far as I know it is currently the only way to make GUI applications in Rust, and it would be nice to make it more accessible to the rest of the Rust community.

    opened by mitchelldm 5
Owner
Jeremy Letang
Jeremy Letang
Provides Rust bindings for GTK libraries

The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries

null 431 Dec 30, 2022
Provides Rust bindings for GTK libraries

gtk3-rs The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org. This

null 431 Dec 30, 2022
A template to kickstart your Cairo 1.0 development

Cairo 1 template How to use Install Rust Click the "Use this template" button to use this as a basis for your repo or create a codespace on Github. To

Extropy.io 4 Dec 23, 2022
A compiler to convert Cairo's intermediate representation "Sierra" code to MLIR.

Cairo Sierra to MLIR compiler A compiler to convert Cairo's intermediate representation "Sierra" code to MLIR. Documentation There is an mdbook in the

Lambdaclass 5 Mar 16, 2023
Typesafe opinionated abstractions for developing Cairo 1.0 smart contracts

Suna Built with auditless/cairo-template Typesafe opinionated abstractions for developing Cairo 1.0 smart contracts. Originally created to facilitate

Auditless 12 Apr 2, 2023
A powerful color picker and formatter, built with GTK and Rust

Eyedropper A powerful color picker and formatter. More screenshots Features Pick a Color Enter a color in Hex-Format Parse RGBA/ARGB Hex-Colors View c

Jonathan 108 Dec 24, 2022
Highly customizable finder with high performance. Written in Rust and uses GTK

Findex Highly customizable finder with high performance. Written in Rust and uses GTK Installation Automatic Binary Clone from https://aur.archlinux.o

MD Gaziur Rahman Noor 442 Jan 1, 2023
A GUI for NordVPN on Linux that maintains feature parity with the official clients, written with Rust and GTK.

Viking for NordVPN This project aims to provide a fully usable and feature-complete graphical interface for NordVPN on Linux. While it attempts to clo

Jacob Birkett 2 Oct 23, 2022
A Rust library to parse Blueprint files and convert them into GTK UI files

?? gtk-ui-builder A Rust library to parse Blueprint files and convert them into GTK UI files Inspired by the Blueprint project Example 1 - blueprints

Observer KRypt0n_ 5 Oct 22, 2022
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

null 2.2k Dec 31, 2022
Graphical font editor (GTK + Rust)

gerb *gerb ʰ-: reconstructed Proto-Indo-European root, meaning to carve gerb: a WIP font editor in gtk3 and rust Introduction gerb is an experimental,

Manos Pitsidianakis 40 Jan 1, 2023
GTK 4 front-end to ChatGPT completions written in Rust

ChatGPT GUI Building git clone [email protected]:teunissenstefan/chatgpt-gui.git cd chatgpt-gui cargo build --release Todo Connect insert_text to only al

Stefan Teunissen 6 Mar 12, 2023
Reactive components in rust, designed to make GTK more manageable

gflux gflux is a tiny experimental reactive component system for rust, designed to make GTK more manageable. gflux: is about 300 lines of code contain

Brian Vincent 3 Aug 20, 2023
An example of searching iBeacon using gtk-rs and btleplug.

Beacon Searcher Screenshot Compile & Run Install GTK 3 dev packages: macOS: $ brew install gtk+3 $ brew install gnome-icon-theme Debian / Ubuntu: $ s

Ling, Wei-Cheng 0 Dec 21, 2021
Test bed for gtk-rs-core experiments

Rust GObject Experiments class macro #[gobject::class(final)] mod obj { #[derive(Default)] pub struct MyObj { #[property(get, set)]

Jason Francis 2 May 28, 2022
Rust bindings to Core Foundation and other low level libraries on Mac OS X and iOS

core-foundation-rs Compatibility Targets macOS 10.7 by default. To enable features added in macOS 10.8, set Cargo feature mac_os_10_8_features. To hav

Servo 685 Jan 2, 2023
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 1.1k Jan 9, 2023
Rust bindings for Dear ImGui

imgui-rs: Rust bindings for Dear ImGui (Recently under new maintenance, things subject to change) Window::new(im_str!("Hello world")) .size([300.0

null 2k Jan 7, 2023
Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`

Improved User Interface A cross-platform UI toolkit for Rust based on libui iui: ui-sys: iui is a simple (about 4 kLOC of Rust), small (about 800kb, i

Rust Native UI Group 865 Dec 27, 2022