antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

Setting WindowType with the view macro #128

Closed he-la closed 6 years ago

he-la commented 6 years ago

In GTK+, the window type must be set in the window constructor and cannot be changed thereafter (there is no set_type method). While I am new to relm, I understand that this makes it impossible to use the view macro when creating a window that is not a toplevel window, such as a popup.

A possible solution would be to perhaps introduce a syntax for passing constructor paramters with the view macro. I think something like the following would make sense:

view! {
    gtk::Window(gtk::WindowType::Popup) {
        // ...
    }
}

i.e. adding constructor parameters for GTK+ widgets within parentheses. Such a feature addition would be compatible with the current version of relm, as the parentheses may be omitted when no constructor parameters are passed.

antoyo commented 6 years ago

That is already implemented and with exactly the same syntax you thought :) . Here's an example. There's also this syntax for when calling the constructor is not enough and you want to set construct-only properties by name, but it's not safe, unfortunately.