-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve view macro syntax for 0.5 #162
Comments
Great suggestions! By the way, the window = gtk::Window {
...
present: (),
} I've got a few suggestions, too: Unify clone syntaxTo clone a variable into closure you just write it in parentheses: connect_name(cloned_var1, cloned_var2, ...) => move |arg1, arg2, ...| { ... } To clone a field or a method, you write it inside square brackets: connect_name[sender1 = components.name1.sender(),
sender2 = components.name2.sender(), ...] => move |arg1, arg2, ...| But I think the syntax could be unified. connect_name(cloned_var1, sender1 = components.name1.sender(),
sender2 = components.name2.sender(), cloned_var2, ...) => move |arg1, arg2, ...| Allow property / method chains in widget initappend = app.components.my_component.widget() {
...
} |
Everything looks really useful to me. I'd be a little concerned with the new multiple arguments parsing being a little easy to miss. The new way looks like a single item tuple of tuples. But it might be better when you get more familiar with it. |
Now after pondering about the "multiple root" idea for a while, I realised it might also be useful to allow arbitrary ordering of the "roots", instead of hard-coding the first one as the root widget. Perhaps for example some fields must be initialised before the main widget tree (previously covered by |
For conditional rendering, maybe something like this would be sufficient: set_child: some_child = || {
match model.mode {
AppMode::SingleUser => view! {
gtk::Label::new("hi")
}
AppMode::Batch => view! {
gtk::Label::new("ho")
}
}
} The closure can be used for anything and will run each time the UI gets updated. The type of the return value can be inferred via the |
For a more pragmatic approach that extends the set_child ?= (model.mode == AppMode::SingleUser) = {
}
set_child: a_child ?= (model.mode == AppMode::SingleUser) = {
} |
The PR is merged 🎉 Thanks for your feedback, I think most of it should have been implemented by the PR. Let me know if there's something broken or missing. |
This is a list of suggestion for improving the macro syntax. Comments and suggestions are highly appreciated.
Multiple "roots"
Motivation and source
Attributes
Allow using local variables
[local_ref]
could be used for variables passed by reference.Make
watch!
andtrack!
attributesBlock signals
Multiple arguments
Remove
args!
Other
send!
The text was updated successfully, but these errors were encountered: