Skip to content
Snippets Groups Projects
Select Git revision
4 results Searching

lib.rs

Blame
  • lib.rs 16.82 KiB
    #![warn(clippy::all, rust_2018_idioms)]
    
    mod transfer_functions;
    
    #[allow(unused_imports)]
    use basic_print::basic_print; // basic print for print-debugging
    
    use frequency_response_app::FreqResp;
    use pole_position_app::PolePos;
    
    pub struct ControlApp {
        cur_app_idx: Option<usize>,
        apps: Vec<Box<dyn CentralApp>>,
    }
    
    trait CentralApp {
        fn get_label(&self) -> &str;
        fn draw_app(&mut self, ui: &mut egui::Ui);
    }
    
    impl eframe::App for ControlApp {
        fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
            egui::TopBottomPanel::top("app_selection_panel").show(ctx, |ui| {
                if self.top_bar(ui) {
                    #[cfg(not(target_arch = "wasm32"))] // no quit on web pages!
                    _frame.close();
                }
            });
    
            egui::CentralPanel::default().show(ctx, |ui| {
                ui.centered_and_justified(|ui| {
                    match self.cur_app_idx {
                        None => {
                            ui.label("Select an application in the bar above.");
                        }
                        Some(idx) => {
                            self.apps[idx].draw_app(ui);
                        }
                    };
                });
            });
        }
    }
    
    impl ControlApp {
        pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
            // This is also where you can customized the look at feel of egui using
            // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
    
            let apps: Vec<Box<dyn CentralApp>> = vec![
                Box::new(PolePos::new("Pole Positioning".to_string())),
                Box::new(FreqResp::new("Frequency Response".to_string())),
            ];
    
            if cfg!(debug_assertions) {
                ControlApp {
                    cur_app_idx: Some(0),
                    apps,
                }
            } else {
                ControlApp {
                    cur_app_idx: None,
                    apps,
                }
            }
        }
    
        fn top_bar(&mut self, ui: &mut egui::Ui) -> bool {
            #[allow(unused_mut)]
            let mut quit = false;