I'm trying to create a second window using druid. I have a button that's supposed to create a secondary window:
let enter_btn = Button::new("Enter")
.on_click(|_ctx, data: &mut HelloState, _env| {
AppLauncher::with_window(game_window)
.use_simple_logger()
.launch((*data).game_state)
.expect("Failed to launch application");
});
However, I see that this is not possible since I am using AppLauncher to do this. I tried searching through the documentation to no avail since most of the structs with the name Window just pertains to the Window descriptions and ID and I can't find anything about creating new windows. Is this possible using Druid? If so, what's the best way to open a new window while sharing the same state?
You can use EventCtx::new_window for this. druid also has an example for this use case, the relevant part is this:
let new_win = WindowDesc::new(ui_builder())
.menu(make_menu)
.window_size((data.selected as f64 * 100.0 + 300.0, 500.0));
ctx.new_window(new_win);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With