From 67a8bb5e4c3d8d09761147c95434007b4ebf95f7 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Sun, 9 Mar 2025 22:20:16 +0100 Subject: [PATCH] show VRU dialog in main window (#311) --- src/ui/gui.rs | 74 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/src/ui/gui.rs b/src/ui/gui.rs index 43d8bf7..5a05e39 100644 --- a/src/ui/gui.rs +++ b/src/ui/gui.rs @@ -222,44 +222,35 @@ fn configure_profile(app: &mut GopherEguiApp, ctx: &egui::Context) { } fn show_vru_dialog(app: &mut GopherEguiApp, ctx: &egui::Context) { - ctx.show_viewport_immediate( - egui::ViewportId::from_hash_of("vru_dialog"), - egui::ViewportBuilder::default() - .with_title("What would you like to say?") - .with_always_on_top(), - |ctx, class| { - assert!( - class == egui::ViewportClass::Immediate, - "This egui backend doesn't support multiple viewports" - ); - egui::CentralPanel::default().show(ctx, |ui| { - egui::Grid::new("vru_words").show(ui, |ui| { - for (i, v) in app.vru_word_list.iter().enumerate() { - if i % 5 == 0 { - ui.end_row(); - } - if ui.button((*v).to_string()).clicked() { - app.vru_word_notifier - .as_ref() - .unwrap() - .try_send(v.clone()) - .unwrap(); - app.show_vru_dialog = false; - } - } - }); - }); - - if ctx.input(|i| i.viewport().close_requested()) { - app.vru_word_notifier - .as_ref() - .unwrap() - .try_send(String::from("")) - .unwrap(); - app.show_vru_dialog = false; + egui::CentralPanel::default().show(ctx, |ui| { + ui.label("What would you like to say?"); + egui::Grid::new("vru_words").show(ui, |ui| { + for (i, v) in app.vru_word_list.iter().enumerate() { + if i % 5 == 0 { + ui.end_row(); + } + if ui.button((*v).to_string()).clicked() { + app.vru_word_notifier + .as_ref() + .unwrap() + .try_send(v.clone()) + .unwrap(); + app.show_vru_dialog = false; + } } - }, - ); + }); + + ui.add_space(32.0); + + if ui.button("Close without saying anything").clicked() { + app.vru_word_notifier + .as_ref() + .unwrap() + .try_send(String::from("")) + .unwrap(); + app.show_vru_dialog = false; + }; + }); } fn get_latest_version(app: &mut GopherEguiApp, ctx: &egui::Context) { @@ -475,6 +466,11 @@ pub fn open_rom(app: &mut GopherEguiApp, ctx: &egui::Context, enable_overclock: impl eframe::App for GopherEguiApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + if self.show_vru_dialog { + show_vru_dialog(self, ctx); + return; + } + if self.netplay.create { gui_netplay::netplay_create(self, ctx); } @@ -654,10 +650,6 @@ impl eframe::App for GopherEguiApp { } } - if self.show_vru_dialog { - show_vru_dialog(self, ctx); - } - get_latest_version(self, ctx); } }