mod views; pub struct Error(eframe::Error); pub fn gui(message: &mut crate::Message, circle_length: &mut usize, inputs: bool) -> anyhow::Result<()> { let options = eframe::NativeOptions::default(); eframe::run_native( "Encoded Message", options, Box::new(|_cc| Ok(Box::::new( Gui::new(message, circle_length, inputs) ))) ).map_err(crate::Error::from)?; Ok(()) } struct Gui<'a> { display: views::Display<'a>, } impl<'a> Gui<'a> { fn new(message: &'a mut crate::Message, circle_length: &'a mut usize, inputs: bool) -> Self { let circles = crate::encrypt_message(message, circle_length); let line_colors: Vec = (0..circles.len()) .map(|_|views::random_color()).collect(); Self { display: match inputs { true => views::display_gui(), false => views::display_plot(circles, circle_length, line_colors), }, } } } impl eframe::App for Gui<'_> { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx,|ui| { (self.display)(ui) }); } } impl From for Error { fn from(err: eframe::Error) -> Self { Error(err) } } impl From for anyhow::Error { fn from(err: Error) -> Self { anyhow::anyhow!(err.0.to_string()) } }