generated from luke-else/egui-template
	Added async traits crate to code to allow dynamic dispatch with async functions in traits
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Continuous integration / Check (push) Failing after 1m53s
				
			
		
			
				
	
				Continuous integration / Test Suite (push) Failing after 2m23s
				
			
		
			
				
	
				Continuous integration / Rustfmt (push) Failing after 36s
				
			
		
			
				
	
				Continuous integration / Clippy (push) Failing after 1m53s
				
			
		
			
				
	
				Continuous integration / build (push) Failing after 2m16s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Continuous integration / Check (push) Failing after 1m53s
				
			Continuous integration / Test Suite (push) Failing after 2m23s
				
			Continuous integration / Rustfmt (push) Failing after 36s
				
			Continuous integration / Clippy (push) Failing after 1m53s
				
			Continuous integration / build (push) Failing after 2m16s
				
			This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
use crate::app::App;
 | 
			
		||||
use futures::executor::block_on;
 | 
			
		||||
use crate::theme::onedark::ONE_DARK;
 | 
			
		||||
 | 
			
		||||
pub mod tabs;
 | 
			
		||||
@@ -11,10 +12,17 @@ impl<'a> eframe::App for App<'a> {
 | 
			
		||||
 | 
			
		||||
        // Display tabs for main UI
 | 
			
		||||
        match self.tab_state.get_current_tab() {
 | 
			
		||||
            Some(tab) => tab.display_tab(ctx, &frame),
 | 
			
		||||
            Some(tab) => {
 | 
			
		||||
                println!("Displaying tab");
 | 
			
		||||
                block_on(tab.display_tab(ctx, &frame));
 | 
			
		||||
            },
 | 
			
		||||
 | 
			
		||||
            // What to do if the tab is not available
 | 
			
		||||
            _ => (),
 | 
			
		||||
        }
 | 
			
		||||
            None => {
 | 
			
		||||
                println!("No tab available");
 | 
			
		||||
            },
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        ()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
use egui::Key;
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
 | 
			
		||||
use crate::app::metar::Metar;
 | 
			
		||||
 | 
			
		||||
@@ -21,8 +22,10 @@ impl Default for MetarTab {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[async_trait]
 | 
			
		||||
impl Tab for MetarTab {
 | 
			
		||||
    async fn display_tab(&mut self, ctx: &egui::Context, frame: &egui::Frame) {
 | 
			
		||||
        println!("Displaying METAR Tab");
 | 
			
		||||
        egui::CentralPanel::default().frame(*frame).show(ctx, |ui| {
 | 
			
		||||
            // Given Key pressed, place focus on next item
 | 
			
		||||
            let new_icao_focus: bool = ui.input(|i| i.key_pressed(Key::Space));
 | 
			
		||||
@@ -33,7 +36,6 @@ impl Tab for MetarTab {
 | 
			
		||||
 | 
			
		||||
            if ui.button("Add More").clicked() || new_icao_focus {
 | 
			
		||||
                self.icaos.push("".to_string());
 | 
			
		||||
                self.metar.api.make_request(String::from("google.com"));
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,9 @@ use std::collections::HashMap;
 | 
			
		||||
use strum::EnumIter;
 | 
			
		||||
use strum::IntoEnumIterator;
 | 
			
		||||
 | 
			
		||||
// Allow Async Traits
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
 | 
			
		||||
use self::metar_tab::MetarTab;
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Copy, Debug, Default, EnumIter, Eq, Hash, PartialEq)]
 | 
			
		||||
@@ -48,7 +51,7 @@ impl TabState {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get the currently selected Tab
 | 
			
		||||
    pub fn get_current_tab(&mut self) -> Option<&mut Box<dyn Tab + Send>> {
 | 
			
		||||
    pub fn get_current_tab(&mut self) -> Option<&mut Box<dyn Tab>> {
 | 
			
		||||
        self.get_tab_state(self.current_tab)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -64,6 +67,7 @@ impl TabState {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Tab traits that allow tab display on the main application window
 | 
			
		||||
#[async_trait]
 | 
			
		||||
pub trait Tab {
 | 
			
		||||
    async fn display_tab(&mut self, ctx: &egui::Context, frame: &egui::Frame);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user