Refactored some small logic. Blank ICAO ready by default

This commit is contained in:
Luke Else 2024-08-05 09:55:22 +01:00
parent 566603e961
commit 3e724cf340
7 changed files with 22 additions and 4 deletions

View File

@ -10,3 +10,4 @@ egui = "0.28.1"
eframe = "0.28.1" eframe = "0.28.1"
tracing-subscriber = "0.3.16" tracing-subscriber = "0.3.16"
strum = { version = "0.26.3", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] }
tokio = "1.39.2"

1
src/app/metar/mod.rs Normal file
View File

@ -0,0 +1 @@

View File

@ -1,3 +1,5 @@
mod metar;
mod req;
mod ui; mod ui;
/// Stuct to store the state of the running application /// Stuct to store the state of the running application

1
src/app/req/mod.rs Normal file
View File

@ -0,0 +1 @@

View File

@ -6,7 +6,6 @@ pub mod tabs;
impl<'a> eframe::App for App<'a> { impl<'a> eframe::App for App<'a> {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let frame = egui::Frame::default().fill(ONE_DARK.bg); let frame = egui::Frame::default().fill(ONE_DARK.bg);
// Display the top bar of tabs // Display the top bar of tabs
tabs::display_tabs(&mut self.tab_state, ctx, &frame); tabs::display_tabs(&mut self.tab_state, ctx, &frame);

View File

@ -1,19 +1,33 @@
use egui::Key;
use super::Tab; use super::Tab;
#[derive(Debug, Default, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct MetarTab { pub struct MetarTab {
pub icaos: Vec<String>, pub icaos: Vec<String>,
pub metars: Vec<String>, pub metars: Vec<String>,
} }
impl Default for MetarTab {
fn default() -> Self {
Self {
icaos: vec!["".to_string()],
metars: vec![],
}
}
}
impl Tab for MetarTab { impl Tab for MetarTab {
fn display_tab(&mut self, ctx: &egui::Context, frame: &egui::Frame) { fn display_tab(&mut self, ctx: &egui::Context, frame: &egui::Frame) {
egui::CentralPanel::default().frame(*frame).show(ctx, |ui| { 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));
for icao in self.icaos.iter_mut() { for icao in self.icaos.iter_mut() {
ui.text_edit_singleline(icao); ui.text_edit_singleline(icao);
} }
if ui.button("Add More").clicked() || ui.input(|i| i.key_pressed(egui::Key::Tab)) { if ui.button("Add More").clicked() || new_icao_focus {
self.icaos.push("".to_string()); self.icaos.push("".to_string());
} }
}); });

View File

@ -1,4 +1,4 @@
pub mod metar_tab; mod metar_tab;
use std::collections::HashMap; use std::collections::HashMap;