GithubHelp home page GithubHelp logo

jeremyletang / rgtk Goto Github PK

View Code? Open in Web Editor NEW
121.0 14.0 22.0 5.16 MB

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

License: GNU Lesser General Public License v3.0

Rust 98.95% C 1.05%

rgtk's Introduction

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).

rgtk's People

Contributors

blei avatar bpbp-boop avatar briankropf avatar buster avatar dndanik avatar frewsxcv avatar gekola avatar gkoz avatar gsingh93 avatar guillaumegomez avatar jeremyletang avatar jgillich avatar kennytm avatar mathijshenquet avatar oakes avatar osa1 avatar ptersilie avatar simonsapin avatar steveklabnik avatar zploskey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgtk's Issues

How to access Key value?

Hi,

i'm trying to get some very basic app running, consisting of only an Entry.
I'd like to make the app quite when pressing Escape.
According to the docs the EventKey should have some items like "keyval", which i can't access.
How would i read the value of the key press event?

#![feature(globs)]
#![crate_type = "bin"]

extern crate rgtk;

use rgtk::*;
use rgtk::gtk::signals;
use rgtk::gtk::traits::*;
use rgtk::gdk::*;

fn main() {
    gtk::init();
    println!("Major: {}, Minor: {}", gtk::get_major_version(), gtk::get_minor_version());
    let mut window = gtk::Window::new(gtk::window_type::TopLevel).unwrap();
    let entry = gtk::SearchEntry::new().unwrap();
    //let search_entry = gtk::SearchEntry::new().unwrap();
    window.set_title("Yeah a beautiful window with rgtk !");
    window.set_window_position(gtk::window_position::Center);

    window.connect(signals::KeyPressEvent::new(|key|{
        //println!("key pressed: {}", key.keyval);
        println!("text: {}", entry.get_text().unwrap());
        false
    }));

    window.connect(signals::DeleteEvent::new(|_|{
        gtk::main_quit();
        true
    }));

    window.add(&entry);
    window.set_border_width(0);
    window.show_all();
    gtk::main();
}

Thanks!

build rgtk with cargo on travis

@TobiasRaeder and @buster recently work on porting rgtk to the new cargo's feature system.

Right now we can add rgtk to a rust project using cargo. It will be great to build rgtk on travis using cargo build.

undefined reference in building examples on windows

I checked out rgtk and the main library appears to build OK after I changed treepath.rs to use u32 instead of u64 on line 56. but when I try to build the examples, I get an undefined reference to 'cast_GtkTextTagTable'. Any advice on fixing this? I'm new to rust and not sure what exactly it is telling me.

rustc -g -L target/ examples/cairotest.rs -o target/example/cairotest
error: linking with gcc failed: exit code: 1
note: gcc '-m64' '-L' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib' '-o' 'target\example\cairotest' 'target\example\cairotest.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-fno-lto' '-fno-use-linker-plugin' '-Wl,--gc-sections' '-shared-libgcc' '-Wl,--enable-long-section-names' '-Wl,--nxcompat' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libdebug-4e7c5e5c.rlib' 'C:\development\libraries\rust\rgtk\target\librgtk.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liblog-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libregex-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libstd-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librand-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libsync-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\librustrt-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcollections-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liballoc-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libunicode-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\liblibc-4e7c5e5c.rlib' 'C:\development\compilers\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libcore-4e7c5e5c.rlib' '-L' 'target' '-L' 'C:\development\libraries\rust\rgtk.rust' '-L' 'C:\development\libraries\rust\rgtk' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lglib-2.0' '-lgtk-3' '-lgio-2.0' '-lgobject-2.0' '-lgdk-3' '-lcairo' '-lws2_32' '-lgcc_s' '-lcompiler-rt'
note: C:\development\libraries\rust\rgtk\target\librgtk.rlib(rgtk.o):(.text+0x1936): undefined reference to `cast_GtkTextTagTable'
collect2.exe: error: ld returned 1 exit status

error: aborting due to previous error
Makefile:74: recipe for target 'target/example/cairotest' failed
make: *** [target/example/cairotest] Error 101

Add tests

Right now, the travis build only builds the library, but it should have some tests to run through.

column title button signals not working

I made this change in treeview example in the repo:

diff --git a/examples/treeview/src/treeview.rs b/examples/treeview/src/treeview.rs
index 39bd14f..3be128a 100644
--- a/examples/treeview/src/treeview.rs
+++ b/examples/treeview/src/treeview.rs
@@ -11,7 +11,11 @@ use rgtk::*;
 use rgtk::gtk::signals;

 fn append_text_column(tree: &mut gtk::TreeView) {
-    let column = gtk::TreeViewColumn::new().unwrap();
+    let mut column = gtk::TreeViewColumn::new().unwrap();
+    column.set_title("title");
+    column.set_clickable(true);
+    let column_btn: gtk::Button = column.get_button();
+    column_btn.connect(signals::Clicked::new(|| { println!("clicked"); }));
     let cell = gtk::CellRendererText::new().unwrap();
     column.pack_start(&cell, true);
     column.add_attribute(&cell, "text", 0);
@@ -37,7 +41,6 @@ fn main() {
     let left_store = gtk::ListStore::new(column_types).unwrap();
     let left_model = left_store.get_model().unwrap();
     left_tree.set_model(&left_model);
-    left_tree.set_headers_visible(false);
     append_text_column(&mut left_tree);

     for _ in range(0i, 10i) {
@@ -53,7 +56,6 @@ fn main() {
     let right_store = gtk::TreeStore::new(column_types).unwrap();
     let right_model = right_store.get_model().unwrap();
     right_tree.set_model(&right_model);
-    right_tree.set_headers_visible(false);
     append_text_column(&mut right_tree);

     for _ in range(0i, 10i) {

This puts headers to lists and makes them clickable. The problem is handlers are not working. It's not printing anything when I click to headers.

I'm not sure if relevant but GTK/GLib prints those to stdout when I run this program:

➜  treeview git:(master) ✗ cargo run
   Compiling rgtk-examples v0.0.1 (file:///home/omer/rust/rgtk/examples/treeview)
     Running `target/treeview`

(treeview:23066): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed

(treeview:23066): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(treeview:23066): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(treeview:23066): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

(treeview:23066): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed

(treeview:23066): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(treeview:23066): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(treeview:23066): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

Mac doesn't compile on master

Hello,

When I try to compile on 10.8 I get

 Building rgtk.rlib
rustc -g --cfg GTK_3_12 -L target/ src/rgtk.rs --out-dir target/
src/rgtk.rs:108:1: 108:22 warning: the #[crate_id] attribute is deprecated for the #[crate_name] attribute
src/rgtk.rs:108 #![crate_id = "rgtk"]
                ^~~~~~~~~~~~~~~~~~~~~
src/gtk/traits/entry.rs:141:13: 141:78 error: cannot cast from pointer to float directly: `*const f32` as `f32`; cast through an integer first
src/gtk/traits/entry.rs:141             ffi::gtk_entry_get_alignment(GTK_ENTRY(self.get_widget())) as f32
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/glib/list.rs:127:9: 127:31 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
src/glib/list.rs:127         self.nth(*_rhs as u32)
                             ^~~~~~~~~~~~~~~~~~~~~~
src/glib/list.rs:126:5: 128:6 note: consider using an explicit lifetime parameter as shown: fn index(&'a self, _rhs: &uint) -> &'a T
src/glib/list.rs:126     fn index(&self, _rhs: &uint) -> &'a T {
src/glib/list.rs:127         self.nth(*_rhs as u32)
src/glib/list.rs:128     }
src/glib/list.rs:126:5: 128:6 error: method `index` has an incompatible type for trait: expected &-ptr but found type parameter [E0053]
src/glib/list.rs:126     fn index(&self, _rhs: &uint) -> &'a T {
src/glib/list.rs:127         self.nth(*_rhs as u32)
src/glib/list.rs:128     }
src/glib/slist.rs:106:9: 106:31 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
src/glib/slist.rs:106         self.nth(*_rhs as u32)
                              ^~~~~~~~~~~~~~~~~~~~~~
src/glib/slist.rs:105:5: 107:6 note: consider using an explicit lifetime parameter as shown: fn index(&'a self, _rhs: &uint) -> &'a T
src/glib/slist.rs:105     fn index(&self, _rhs: &uint) -> &'a T {
src/glib/slist.rs:106         self.nth(*_rhs as u32)
src/glib/slist.rs:107     }
src/glib/slist.rs:105:5: 107:6 error: method `index` has an incompatible type for trait: expected &-ptr but found type parameter [E0053]
src/glib/slist.rs:105     fn index(&self, _rhs: &uint) -> &'a T {
src/glib/slist.rs:106         self.nth(*_rhs as u32)
src/glib/slist.rs:107     }
error: aborting due to 5 previous errors
make: *** [rgtk-build] Error 101

Gtk - 3.12.3 from brew install gtk+3

Not sure what I am missing, also the README says apt-get install gtk+3 rather then brew for Mac.

Using rgtk in other projects - Consider expanding "Use rgtk" section in readme?

I made some attempt to use rgtk for a test application. Here's what's in my Cargo.toml

[package]
name = "rgtk-test"
version = "0.0.1"
authors = []

[dependencies.rgtk]
path = "../tools/rgtk"

[[bin]]
name = "gtktest"

Here's a simple program involving an Entry and a ListBox

#![feature(globs)]
#![crate_type = "bin"]

extern crate rgtk;

use rgtk::*;
use rgtk::gtk::signals;

fn main() {
    gtk::init();
    println!("Major: {}, Minor: {}", gtk::get_major_version(), gtk::get_minor_version());
    let mut window = gtk::Window::new(gtk::window_type::TopLevel).unwrap();
    let mut frame = gtk::Frame::new(Some("")).unwrap();
    let mut _box = gtk::Box::new(gtk::orientation::Horizontal, 10).unwrap();
    let mut entry = gtk::Entry::new().unwrap();
    let mut list_box = gtk::ListBox::new().unwrap();
    let mut lb = gtk::Label::new("Hello World").unwrap();

    println!("test");


    frame.set_border_width(10);
    _box.set_border_width(5);
    entry.set_placeholder("An Entry with a placeholder !");
    list_box.add(&lb);
    window.set_title("Yeah a beautiful window with rgtk !");
    window.add(&frame);
    window.add(&list_box);

    window.connect(signals::DeleteEvent::new(|_|{
        gtk::main_quit();
        true
    }));

    frame.add(&_box);
    _box.add(&entry);
    _box.set_orientation(gtk::orientation::Vertical);

    window.show_all();
    gtk::main();
}

The build fails with the following message:

[jtcwang@localhost fruzzy-test]$ cargo build --verbose
     Running `rustc src/rgtk.rs --crate-name rgtk --crate-type rlib -g -C metadata=6be5e259f9f3b082 -C extra-filename=-6be5e259f9f3b082 --out-dir /home/jtcwang/proj/fruzzy-test/target/deps --dep-info /home/jtcwang/proj/fruzzy-test/target/.fingerprint/rgtk-6be5e259f9f3b082/dep-lib-rgtk -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/native/rgtk-6be5e259f9f3b082`
     Running `rustc src/gtktest.rs --crate-name gtktest --crate-type bin -g --out-dir /home/jtcwang/proj/fruzzy-test/target --dep-info /home/jtcwang/proj/fruzzy-test/target/.fingerprint/rgtk-test-704d8a0eee6b3521/dep-bin-gtktest -L /home/jtcwang/proj/fruzzy-test/target -L /home/jtcwang/proj/fruzzy-test/target/deps -L /home/jtcwang/proj/fruzzy-test/target/native/rgtk-6be5e259f9f3b082 --extern rgtk=/home/jtcwang/proj/fruzzy-test/target/deps/librgtk-6be5e259f9f3b082.rlib`
       Fresh rgtk v0.0.1 (file:///home/jtcwang/proj/fruzzy-test)
   Compiling rgtk-test v0.0.1 (file:///home/jtcwang/proj/fruzzy-test)
src/gtktest.rs:16:24: 16:41 error: failed to resolve. Could not find `ListBox` in `rgtk::gtk`.
src/gtktest.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                         ^~~~~~~~~~~~~~~~~
src/gtktest.rs:16:24: 16:41 error: unresolved name `gtk::ListBox::new`.
src/gtktest.rs:16     let mut list_box = gtk::ListBox::new().unwrap();
                                         ^~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `rgtk-test`.

Environment

Fedora 20, GTK 3.10, rustc 0.12.0-pre-nightly (09cebc25a 2014-09-07 00:31:28 +0000)

So it looks like ListBox is not present. However, if I put the same code into rgtktest.rs (which is inside rgtk/examples directory) and use make rgtktest, it compiles and runs fine. Seems like the make file is linking some additional dependencies which I suspect is librgtk_glue.o inside target/deps/.

So here's what I'm asking:

  1. Am I doing it right? How can I use rgtk in another project? Do I need to use a makefile?
  2. Should "Use rgtk" be expanded to include more information on this?

I'm more than happy to help expand the readme, but I'll need some guidance here to get things started.

Thanks!

IconSize Enums?

Hello,

I am trying to create a button with a edit-clear icon and I can't seem to figure out what the size enum is? I went through all the code and tried every single variation that I could think of and it still doesn't work. Any ideas?

use rgtk::gtk::enums::{IconSize};
let button = gtk::Button::new_from_icon_name("edit-clear", gtk::IconSize::Button).unwrap();
                                                         // ↑ this part

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

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.

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.

Examples don't build

For the moment, the cargo build command nor the cargo run command can build examples.

undefined reference to `cast_GtkListBox'

I tried using list boxes by adding some code to the example executable and using make gtktest to build it. However I get this error:

note: /home/jtcwang/proj/tools/rgtk/target/librgtk.rlib(rgtk.o): In function `rgtk::gtk::cast::GTK_LIST_BOX':
/home/jtcwang/proj/tools/rgtk/src/gtk/cast.rs:254: undefined reference to `cast_GtkListBox'

Is ListBox ported yet? I see it in the docs so I thought I could use it.
(This is also my first time working with GTK+, so please forgive me if I missed something)

Fedora 20, gtk 3.10, Rust 0.12.0

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.

Building fails (Linux x32)

It's kinda obvious what to do with the first error, but I haven't got a clue about the others.

$ cargo run
    Updating git repository `https://github.com/jeremyletang/rgtk.git`
   Compiling rgtk v0.0.1 (https://github.com/jeremyletang/rgtk.git#855af3f4)
src/gtk/widgets/treepath.rs:54:87: 54:107 error: mismatched types: expected `u32`, found `u64` (expected u32, found u64)
src/gtk/widgets/treepath.rs:54         let tmp = unsafe { ffi::gtk_tree_path_new_from_indicesv(indices.as_mut_ptr(), indices.len() as u64) };
                                                                                                                     ^~~~~~~~~~~~~~~~~~~~
src/gtk/widgets/popover.rs:55:75: 55:98 error: mismatched types: expected `gtk::enums::position_type::PositionType`, found `i32` (expected enum gtk::enums::position_type::PositionType, found i32)
src/gtk/widgets/popover.rs:55         unsafe { ffi::gtk_popover_set_position(GTK_POPOVER(self.pointer), ffi::to_gboolean(modal)) }
                                                                                                        ^~~~~~~~~~~~~~~~~~~~~~~
src/gtk/widgets/popover.rs:59:31: 59:87 error: mismatched types: expected `i32`, found `gtk::enums::position_type::PositionType` (expected i32, found enum gtk::enums::position_type::PositionType)
src/gtk/widgets/popover.rs:59         unsafe { ffi::to_bool(ffi::gtk_popover_get_position(GTK_POPOVER(self.pointer))) }
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Could not compile `rgtk`.

To learn more, run the command again with --verbose.
$ rustc -v
rustc 0.13.0-nightly (aff4f11cd 2014-10-19 23:32:07 +0000)

Split out glib and cairo

glib and cairo are useful (and used) on their own, and it would be really nice to have access to high-level bindings for them without depending on gtk+

Support Windows

http://win32builder.gnome.org/ has unoffical builds for 3.10 for Windows. Also this is another reason to have #1 to allow Windows people to use 3.6.4 (the last "official" release).

Either way it would be nice to redo the Makefile (or switch to something slightly more cross platform like cmake) to allow for Windows support.

Use GTK osx

On osx, a special version of GTK+ exist which use the cocoa api instead of X11 to render the widgets.

We should try to use it on OS X.

use cargo as first party build system for rgtk

Now that we can use cargo to build rgtk it will be great to not duplicate build system in the repository.

For the moment we can build rgtk using a Makefile or using cargo.

We should change this to use only cargo to build rgtk and keep the makefile to build only libgtk_glue.

We may move the examples in different folders and add Cargo.toml file for each example.

Signal new_with_data

Hello,

I am trying to use a Signal with user_data but I can't seem to figure out how, and then I noticed that new_with_data is commented out.

Any idea how I could pass user_data to the callback?

Closures fundamentally broken

Closures right now are fundamentally broken:

fn main(){
    make_window();
    gtk::main();
}

fn make_window(){

    let mut window = gtk::Window::new(gtk::window_type::TopLevel).unwrap();
    let drawing_area = DrawingArea::new().unwrap();

    drawing_area.connect(signals::Draw::new(|cr| 
        drawing_area.get_allocated_area() //`drawing_area` is garbage
    ));

    window.add(drawing_area);
    window.show_all();
}

This is because rust only has stack closures for now. When make_window is finished and it's stack goes out of scope all referenced variables inside the callback become garbage.

I'll be able to fix this when rust-lang/rfcs#114 gets merged.

Custom signals

I'm not experienced in native GTK library, so sorry if that question doesn't make sense.

I'm trying to run some GUI actions based on events emitted in different threads. None of the signals in rgtk::gtk::signals::Signal work for me because there are no guarantees that those signals won't be fired by some other GUI widget. There are no UserSignal or something like that for this purpose. I can't implement Signal trait for my stucts either, because of fn get_trampoline(&self) -> extern "C" fn(); item.

So I'm stuck here, can't use any of built-in signals, and can't implement my signals either. Any ideas on how to handle this? It could be nice if we had an example for this. (maybe with a timer thread that signals an event in ever 3 seconds etc. and a GUI that increments a counter or something like that)

GTK version not being detected correctly

I use Ubuntu, and I have features = ["GTK_3_10"] in my Cargo.toml. When I attempt to use gtk::Stack, which requires 3.10, I get a linker error undefined reference to cast_GtkStack. I knew this was one of the functions defined in gtk_glue.c, so I manually commented out the if defined directive that surrounds it, and it worked. It seems that the features specified in the Cargo.toml aren't making it to gtk_glue.c.

Cairo

Is adding Cairo bindings in the scope of this project?

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)

TreeStore::set_string should be more general

Original version of this function is more general: https://developer.gnome.org/gtk3/stable/GtkTreeStore.html#gtk-tree-store-set-value

I'm currently having trouble with this. As far as I can understand this is only way to put booleans or other values in a TreeStore/TreeModel but current wrapped version is not allowing this.

Note that current version is not safe either, because I can set a column type as boolean but I can't put anything other than string.

EDIT: ListStore also has the same problem.

#cfg not working

Hello,

I am using Rust nightly on Linux and I have GTK 3.12. I compiled with GTK_VERSION ?= GTK_3_12 in my Makefile and when I tried to create a gtk::Button::new_from_icon_name I got an error it did not exist. When I commented out the

#[cfg(GTK_3_10)]
#[cfg(GTK_3_12)]

It worked fine.

I'm not sure if the #cfg is working correctly?

Casting using `as` syntax is wrong(buggy)

I just found a bug in my app caused by casting GLib/GTK pointer types using as. GTK has macros/functions like G_OBJECT, GTK_WIDGET, GTK_BOX etc. for casting and we need to use those. (also see the warning messages printed to console, those indicates errors in the wrappers)

I think we need to change traits to something like this:

(not tested)

pub trait FFIWidget<Ctype> {
    fn get_widget(&self) -> *mut Ctype;
    fn wrap(widget: *mut Ctype) -> Self;
}

We also need to remove as syntax used in macros like impl_TraitWidget! and use proper casting instead. Unfortunately this means adding whole lot of wrappers(like the ones in gtk_glue.c) from every widget type to GObject etc. I'm wondering if there's a better way to do this without using as at all.

Specify Required Rust Version

Rust is a constantly moving target, it would be nice to say what is required to build rgtk. Do we need nightly, master, servo.

Build instructions are out of date

The readme tells me to use ./configure, but there's neither a configure file nor a file for autoconf to generate one from.

Using cargo build seems to work (though I get a probably unrelated build error about core::marker::Sized not being implemented for str, most likely because I'm using the newest nightly).

set_size_request

i cant set size an button or entry etc.
how i can use set_size_request() function.
i cant see set_size_request() function or comment in ffi file of gtk.

thank u very much for this binding.

Support different version of GTK+

For the moment, rgtk target GTK+ version 3.10.
We should find a wind to build GTK+ with an older version. Maybe with some attribut to conditionally compile class that doesn't exist on the anterior version of GTK+.

Find a good way to handle signals

We should provide a way to connect widgets to GTK+ signal, using closures or functions, actual signal handling is just for testing.

Splitting rgtk compilation into different parts

Just an idea i had:

Right now compilation takes quite some time allready, probably because of all the structs and ffi functions everywhere, and this will probably only get worse. Perhaps we can look into the possibility of splitting the compilation into different steps: first compiling gtk -> gtk.rlib, glib -> glib.rlib, cairo -> cairo.rlib and then statically liking them together into rgtk.rlib. This would have the advantage of only having to rebuild the subsection you are working on (and the rgtk.rlib).

Don't know if it is possible or even beneficial though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.