2024-11-04 19:54:00 +00:00
|
|
|
mod views;
|
|
|
|
|
|
2024-11-04 02:30:33 +00:00
|
|
|
pub struct Error(eframe::Error);
|
|
|
|
|
|
2024-11-04 19:54:00 +00:00
|
|
|
pub fn gui(message: &mut crate::Message, circle_length: &mut usize, inputs: bool) -> anyhow::Result<()> {
|
2024-11-04 00:14:54 +00:00
|
|
|
let options = eframe::NativeOptions::default();
|
2024-11-04 02:30:33 +00:00
|
|
|
eframe::run_native(
|
|
|
|
|
"Encoded Message",
|
|
|
|
|
options,
|
|
|
|
|
Box::new(|_cc| Ok(Box::<Gui>::new(
|
2024-11-04 19:54:00 +00:00
|
|
|
Gui::new(message, circle_length, inputs)
|
2024-11-04 02:30:33 +00:00
|
|
|
)))
|
|
|
|
|
).map_err(crate::Error::from)?;
|
|
|
|
|
Ok(())
|
2024-11-03 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-04 19:54:00 +00:00
|
|
|
|
|
|
|
|
struct Gui<'a> {
|
|
|
|
|
display: views::Display<'a>,
|
2024-11-04 00:14:54 +00:00
|
|
|
}
|
2024-11-04 19:54:00 +00:00
|
|
|
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<egui::Color32> = (0..circles.len())
|
|
|
|
|
.map(|_|views::random_color()).collect();
|
2024-11-04 00:14:54 +00:00
|
|
|
|
2024-11-04 19:54:00 +00:00
|
|
|
Self {
|
|
|
|
|
display: match inputs {
|
|
|
|
|
true => views::display_gui(),
|
|
|
|
|
false => views::display_plot(circles, circle_length, line_colors),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-03 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-04 19:54:00 +00:00
|
|
|
}
|
2024-11-03 20:57:53 +00:00
|
|
|
|
2024-11-04 19:54:00 +00:00
|
|
|
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)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-04 00:14:54 +00:00
|
|
|
impl From<eframe::Error> for Error {
|
|
|
|
|
fn from(err: eframe::Error) -> Self {
|
|
|
|
|
Error(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Error> for anyhow::Error {
|
|
|
|
|
fn from(err: Error) -> Self {
|
|
|
|
|
anyhow::anyhow!(err.0.to_string())
|
|
|
|
|
}
|
2024-11-03 20:57:53 +00:00
|
|
|
}
|