Replies: 1 comment
-
When I first designed egui this was something I did consider, but it has drawback on its own:
Ideally I'd like to have something similar to the Python construct with ui = ui.horizontal() {
//lots of ui code
} …but I doubt Rust will be getting that anytime soon. The multiple-borrows of a struct member can be worked around by doing a deconstruct: fn ui(&mut self, ui: &mut Ui) {
let Self { foo, bar, baz } = self:
…
} This works for most cases I've encountered. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
currently closures are used everywhere in egui, but they have a few limitations: https://stackoverflow.com/questions/36379242/mutably-borrow-one-struct-field-while-borrowing-another-in-a-closure
Most of egui closures are used to do some startup operations, and then execute the closure, and finally some closing operations.
This seems like a good usecase for the rust Drop trait: https://doc.rust-lang.org/std/ops/trait.Drop.html
(for example you could do:
Do you think it would be worthwhile to switch to this more elegant method?
Can this even be considered a more elegant method in the first place?
Beta Was this translation helpful? Give feedback.
All reactions