From cd3078da9c494e384a7fa66c1beb79b3f32085bc Mon Sep 17 00:00:00 2001 From: aprzn Date: Fri, 25 Aug 2023 21:32:05 -0400 Subject: [PATCH] next step is to query for song id --- NONGfisher/src/main.rs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/NONGfisher/src/main.rs b/NONGfisher/src/main.rs index 322f38d..eb418a2 100644 --- a/NONGfisher/src/main.rs +++ b/NONGfisher/src/main.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] use eframe::{ - egui::{CentralPanel, Context, Layout, TextFormat}, + egui::{CentralPanel, Context, Layout, TextFormat, Visuals}, emath::Align, epaint::{text::LayoutJob, Color32, FontId}, Frame, @@ -38,18 +38,26 @@ struct SfhResponse { songs: Vec, } +enum Event { + IdSubmit { id: String }, +} + enum App { - IdSelect { search_string: String }, + IdSelect { search_string: String, enabled: bool }, } impl App { fn new() -> Self { Self::IdSelect { search_string: String::new(), + enabled: true } } fn update(&mut self, ctx: &Context, frame: &mut Frame) { + let mut events: Vec = vec![]; + + ctx.set_visuals(Visuals::light()); let mut title_text = LayoutJob::default(); title_text.append( "NONG", @@ -61,7 +69,7 @@ impl App { }, ); title_text.append( - "fisher", + "fisher\n", 0.0, TextFormat { color: Color32::from_rgb(0x60, 0x80, 0xd0), @@ -76,14 +84,30 @@ impl App { ui.label(title_text); match self { - Self::IdSelect { search_string } => { - ui.horizontal(|ui| { - ui.text_edit_singleline(search_string); + Self::IdSelect { search_string, enabled } => { + ui.label("Enter level ID:"); + ui.add_enabled_ui(*enabled, |ui| { + ui.text_edit_singleline(search_string).request_focus(); }); + if *enabled { + if ui.button("submit").clicked() { + events.push(Event::IdSubmit { id: search_string.clone() }); + } + } else { + ui.label("loading..."); + } } } }); }); + + for event in events { + match event { + Event::IdSubmit { id } => { + *self = Self::IdSelect { search_string: id, enabled: false }; + }, + } + } } }