use egui::{Color32, Label, RichText}; use super::{State, Window}; #[allow(clippy::pedantic)] #[derive(Debug, Default)] pub struct ConfirmW { id: String, text: String, response: Option, data: Vec } impl Window for ConfirmW { fn ui(&mut self, _: &mut State, ctx: &egui::Context, open: &mut bool) -> anyhow::Result<()> { let mut should_close = false; egui::Window::new("Are you sure?").open(open).show(ctx, |ui| { ui.vertical(|ui| { ui.label(RichText::new("Are you sure you want to do this?").size(15.0).color(Color32::BLUE)); ui.horizontal(|ui| { ui.add(Label::new(self.text.clone()).wrap(true)); }); ui.horizontal(|ui| { if ui.button("Cancel").clicked() { self.response = Some(false); should_close = true; } else if ui.button("Continue").clicked() { self.response = Some(true); should_close = true; } }) }) }); if should_close { *open = false; } Ok(()) } } impl ConfirmW { pub fn set_message(&mut self, new_id: S, text: S, data: &[String]) { self.text = text.to_string(); self.id = new_id.to_string(); self.data = data.to_vec(); } pub fn get_response(&self) -> (&String, &Option, &Vec) { (&self.id, &self.response, &self.data) } pub fn reset(&mut self) { self.id.clear(); self.text.clear(); self.response = None; } }