Replies: 1 comment
-
Hi!
The usual way to do that is not to remove the menu, but just to show something in front of the menu (possibly covering it entirely); and when you're done with it, remove that new thing, and the menu will still be there. If you don't want the menu to be visible when not active, rather than removing it (and having to create it again later), you could switch to a different "screen". The You would have a menu screen with only the menu, and maybe another screen with the active view. You'd move from the menu screen to the active screen when selecting items, and when closing an active view, you'd come back to the menu screen. If possible, it's best to avoid maintaining your own state machine for what should be displayed: it's exactly what cursive is doing internally.
This only means that the closure you're giving cannot borrow other data, but you can totally move stuff in there - including
You can either:
If you're used to C++, then closures in rust are very similar to C++ lambdas, only with less fine-grained control over ref/move for each parameter (if you need fine-grained control in rust you |
Beta Was this translation helpful? Give feedback.
-
Sorry if this is a dumb question, but I'm relatively new to Rust. (And, TBH, I think I'm finding that I'm not smart enough for this language...)
I'm trying to display an opening screen in my app that offers a few selections, then when you select one, removes the menu and replaces it with a new dialog. When you're done with that dialog, you come back to the menu, and select another item.
So, if I have a SelectView like this:
Ideally when I select "About," it removes my menu and displays the about dialog. When I click ok on the about dialog, it would display my menu again. But this violates all sorts of lifetime/ownership rules in Rust.
I started this by trying to create a proper "Welcome" struct that would act as a state machine, tracking the state of what to display: menu, about, sign in, etc. But I wasn't able to modify my struct from within the event handler closure to change its state without violating all sorts of borrow checker rules.
Then I thought about a "WelcomeView," so from within the
on_event
closure I could get the WelcomeView by name from the Cursive reference passed into the closure and update its state, but it doesn't look like it's easy to create a custom view by just composing it of other views (looks like I need to write a lot of drawing, refresh, and resizing code?). But is this how I'm supposed to do this? Is there an example somewhere of a compositional view?I'd really like to just be able to do something like:
And have my
self.next
method refresh the display, replacing the menu with the about dialog...which is how I'd approach this in something like C++ or Go. But it seems like this won't work in Rust, sinceon_submit
wants'static
?Again, sorry if these are dumb questions. You're welcome to just tell me I don't get it, and I'm too new at this to be trying to use Cursive. At this point I'm ready to give up anyway. (For example, I pretty much find every article I read about Rust closures more confusing than the last.)
Thanks
Beta Was this translation helpful? Give feedback.
All reactions