bodil / vgtk

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

allow child properties on components #46

Open nt8r opened 4 years ago

nt8r commented 4 years ago

See PR #44: the following gtk markup works:

<Notebook show_tabs=true show_border=false>
    <Entry Notebook::tab_label="filename" />
</Notebook>

but this markup fails:

<Notebook show_tabs=true show_border=false>
    <@CustomComponent Notebook::tab_label="filename" />
</Notebook>

with the error:

error[E0277]: the trait bound `glib::object::Object: glib::object::IsA<gtk::auto::widget::Widget>` is not satisfied
   --> src/main.rs:100:22
    |
100 |                                             Notebook::tab_label="foo"
    |                                                       ^^^^^^^^^ the trait `glib::object::IsA<gtk::auto::widget::Widget>` is not implemented for `glib::object::Object`
    |
    = help: the following implementations were found:
              <glib::object::Object as glib::object::IsA<glib::object::Object>>
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

It seems that one can only set child properties on widgets, not components. It seems like it would be possible to set the child property on the component's top-level widget in its view function, but this is presently silently ignored, and would breaks modularity even if it worked: component implementations would need to know what their containers would be.

Can vgtk allow child properties on component instantiations (and perhaps explicitly disallow child properties from top-level widgets returned by view functions, since they have no effect there)?