0

I am brand new to GTK with Rust as well as being new to the Rust language itself and I am putting together a small demo app as practice and at one point I created a content widget which is a Box class I believe.

let content = Box::new(Orientation: Vertical, 0);
content.append(&label);
content.append(&button);

I appended the widgets into my box and then on the child property of the builder I passed in the box widget, in other words content like so:

let window = ApplicationWindow::builder()
     .title("UI Demo")
     .application(_app)
     .child(&content)
     .build();

But with the above code, I am getting an error on append() saying:

GTK: the method append exists for struct gtk::Box, but its trait bounds were not satisfied. The following trait bounds were not satisfied: gtk::Box: IsA which is required by gtk::Box: gtk::prelude::UnixFDListExtManual gtk::Box IsA which is required by gtk::Box...

And it just goes on like this.

Daniel
  • 14,004
  • 16
  • 96
  • 156

1 Answers1

0

The error is due to you using the gtk4 method append on Box while having gtk (the gtk3 bindings) in your dependencies. If you have gtk4 available on your system you can drop in replace your gtk dependency to:

gtk = { version = "0.5.5", package = "gtk4" }

in your Cargo.toml

If you're limited to gtk3 you have to use the gtk3 api of Box.

cafce25
  • 15,907
  • 4
  • 25
  • 31
  • that seemed to work except that when I run `cargo run` in terminal it will not compile and instead just hangs on the message: ` Blocking waiting for file lock on package cache`. – Daniel Jan 13 '23 at 02:10
  • Then either you have a `cargo` updating the package cache somewhere else (maybe by `rust-analyzer` in your IDE) or it crashed and left the lock file behind. See https://stackoverflow.com/questions/72264451/blocking-waiting-for-file-lock-on-package-cache-when-i-added-dependency-to-cargo – cafce25 Jan 13 '23 at 02:13
  • can this be fixed by deleting the lock file and running `cargo run` again? – Daniel Jan 13 '23 at 02:16
  • thanks, but I think in order for me to use the above solution, I need to have `gtk4` and I just remembered, I am on Ubuntu desktop and there is not a stable version of `gtk4` for it right now. – Daniel Jan 13 '23 at 02:24
  • Maybe [`pack_end`](https://gtk-rs.org/gtk3-rs/stable/latest/docs/gtk/prelude/trait.BoxExt.html#tymethod.pack_end) [gtk docs](https://docs.gtk.org/gtk3/method.Box.pack_end.html) is what you're looking for then, but I don't know. – cafce25 Jan 13 '23 at 02:31