bodil / vgtk

A declarative desktop UI framework for Rust built on GTK and Gtk-rs
http://bodil.lol/vgtk/
Other
1.05k stars 36 forks source link

Support for TreeModel/ListStore? #59

Open piegamesde opened 4 years ago

piegamesde commented 4 years ago

I'd like to use a gtk::IconView but I somehow can't set the model. I tried inputting a dummy ListStore, Option::None and others but I always get a recursion limit reached error. Is this even supported or is it a bug in the macro?

zzeroo commented 4 years ago

@piegamesde Did you notice the Tutorial? Please read the #getting-started paragraph at least.

... Whenever this happens, it tells you to add an attribute to your crate, that looks like #![recursion_limit = "some number"] ...

piegamesde commented 4 years ago

I read the tutorial, but several weeks before actually trying it out myself. The error message makes more sense now:

error[E0277]: the trait bound `std::option::Option<gtk::auto::list_store::ListStore>: vgtk::properties::PropertyValueCompare<'_, std::option::Option<gtk::auto::tree_model::TreeModel>>` is not satisfied
  --> src/main.rs:28:9
   |
28 | /         gtk! {
29 | |             <Application::new_unwrap(Some("com.example.{{project-name}}"), ApplicationFlags::empty())>
30 | |                 <Window border_width=20 on destroy=|_| Message::Exit>
31 | |                     <IconView
...  |
34 | |             </Application>
35 | |         }
   | |_________^ the trait `vgtk::properties::PropertyValueCompare<'_, std::option::Option<gtk::auto::tree_model::TreeModel>>` is not implemented for `std::option::Option<gtk::auto::list_store::ListStore>`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `std::option::Option<gtk::auto::list_store::ListStore>: vgtk::properties::PropertyValueCompare<'_, std::option::Option<gtk::auto::tree_model::TreeModel>>` is not satisfied
  --> src/main.rs:32:13
   |
32 |                         model={Some(ListStore::new(&[]))} />
   |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `vgtk::properties::PropertyValueCompare<'_, std::option::Option<gtk::auto::tree_model::TreeModel>>` is not implemented for `std::option::Option<gtk::auto::list_store::ListStore>`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
zzeroo commented 4 years ago

@piegamesde Could you create a very minimal example which shows what you are trying. A gist or a git repo would helpful. I know the gtk liststore/ treestores and I'm willing to help you here if I could.

piegamesde commented 4 years ago

I sadly don't have the original code for my bug report anymore, but cloning the cargo-template-vgtk and changing the view function like below should give similar results:

    fn view(&self) -> VNode<Model> {
        gtk! {
            <Application::new_unwrap(Some("com.example.{{project-name}}"), ApplicationFlags::empty())>
                <Window border_width=20 on destroy=|_| Message::Exit>
                    <IconView
                        model={Some(ListStore::new(&[]))} />
                </Window>
            </Application>
        }
    }

In the end I want the icon view's content to be somehow synchronized with the internal state of the widget: when I add elements to it this should be reflected in the GUI, when I reorder them within the widget, this should trigger an update to the model

nt8r commented 3 years ago

It looks like there's a functional workaround for this, using a TreeStore--the GTK docs suggest this works for an IconView.