From 3d1260ec5f1a7ac4e59a118c2abe4c0bf489cf9e Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 24 Mar 2023 10:33:01 -0400 Subject: [PATCH] fixup --- parsing/build.rs | 9 ++------- parsing/src/suggestions.rs | 18 ++++++++---------- src/function_manager.rs | 16 ++++++++-------- src/main.rs | 2 +- src/math_app.rs | 11 ++++------- src/misc.rs | 27 ++++++++++----------------- tests/parsing.rs | 4 ++-- 7 files changed, 35 insertions(+), 52 deletions(-) diff --git a/parsing/build.rs b/parsing/build.rs index 6777916..915e854 100644 --- a/parsing/build.rs +++ b/parsing/build.rs @@ -19,13 +19,8 @@ fn generate_hashmap() { let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs"); let mut file = BufWriter::new(File::create(&path).expect("Could not create file")); - let string_hashmap = compile_hashmap( - SUPPORTED_FUNCTIONS - .to_vec() - .iter() - .map(|a| a.to_string()) - .collect(), - ); + let string_hashmap = + compile_hashmap(SUPPORTED_FUNCTIONS.iter().map(|a| a.to_string()).collect()); let mut hashmap = phf_codegen::Map::new(); diff --git a/parsing/src/suggestions.rs b/parsing/src/suggestions.rs index 7990852..27ea51c 100644 --- a/parsing/src/suggestions.rs +++ b/parsing/src/suggestions.rs @@ -258,21 +258,19 @@ impl<'a> Hint<'a> { #[inline] #[allow(dead_code)] - pub const fn single(&self) -> Option<&&str> { - if let Hint::Single(data) = self { - Some(data) - } else { - None + pub const fn single(&self) -> Option<&str> { + match self { + Hint::Single(data) => Some(data), + _ => None, } } #[inline] #[allow(dead_code)] - pub const fn many(&self) -> Option<&&[&str]> { - if let Hint::Many(data) = self { - Some(data) - } else { - None + pub const fn many(&self) -> Option<&[&str]> { + match self { + Hint::Many(data) => Some(data), + _ => None, } } } diff --git a/src/function_manager.rs b/src/function_manager.rs index cbfa58b..1b027db 100644 --- a/src/function_manager.rs +++ b/src/function_manager.rs @@ -95,7 +95,7 @@ impl FunctionManager { let mut movement: Movement = Movement::default(); let size_multiplier = vec2(1.0, { - let had_focus = ui.ctx().memory(|x| x.has_focus(te_id)); + let had_focus = ui.memory(|x| x.has_focus(te_id)); (ui.ctx().animate_bool(te_id, had_focus) * 1.5) + 1.0 }); @@ -115,7 +115,7 @@ impl FunctionManager { ); // Only keep valid chars - new_string.retain(|c| crate::misc::is_valid_char(c)); + new_string.retain(crate::misc::is_valid_char); // If not fully open, return here as buttons cannot yet be displayed, therefore the user is inable to mark it for deletion let animate_bool = ui.ctx().animate_bool(te_id, re.has_focus()); @@ -136,13 +136,13 @@ impl FunctionManager { } // Put here so these key presses don't interact with other elements - let (enter_pressed, tab_pressed) = ui.input_mut(|x| { - ( - x.consume_key(Modifiers::NONE, Key::Enter), - x.consume_key(Modifiers::NONE, Key::Tab), - ) + let movement_complete_action = ui.input_mut(|x| { + x.consume_key(Modifiers::NONE, Key::Enter) + | x.consume_key(Modifiers::NONE, Key::Tab) + | x.key_pressed(Key::ArrowRight) }); - if enter_pressed | tab_pressed | ui.input(|x| x.key_pressed(Key::ArrowRight)) { + + if movement_complete_action { movement = Movement::Complete; } diff --git a/src/main.rs b/src/main.rs index 973b744..3af354e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ mod widgets; #[cfg(not(target_arch = "wasm32"))] fn main() -> eframe::Result<()> { let subscriber = tracing_subscriber::FmtSubscriber::builder() - .with_max_level(tracing::Level::TRACE) + .with_max_level(tracing::Level::INFO) .finish(); tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); diff --git a/src/math_app.rs b/src/math_app.rs index ac600f9..4fa5292 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -1,15 +1,11 @@ use crate::{ - consts::*, - function_entry::Riemann, - function_manager::FunctionManager, - misc::{option_vec_printer, HashBytesHelper}, + consts::*, function_entry::Riemann, function_manager::FunctionManager, misc::option_vec_printer, }; use eframe::App; use egui::{ - plot::Plot, style::Margin, Button, CentralPanel, ComboBox, Context, Frame, Key, Layout, - SidePanel, TopBottomPanel, Vec2, Window, + plot::Plot, style::Margin, Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, + Key, Layout, SidePanel, TopBottomPanel, Ui, Vec2, Window, }; -use egui::{DragValue, Ui}; use emath::{Align, Align2}; use epaint::Rounding; use instant::Instant; @@ -558,6 +554,7 @@ impl App for MathApp { inner_margin: Margin::symmetric(0.0, 0.0), rounding: Rounding::none(), // fill: crate::style::STYLE.window_fill(), + fill: Color32::from_gray(27), ..Frame::none() }) .show(ctx, |ui| { diff --git a/src/misc.rs b/src/misc.rs index e7e04d2..9eb3954 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -127,23 +127,16 @@ pub fn newtons_method( } /// Inputs `Vec>` and outputs a `String` containing a pretty representation of the Vector -pub fn option_vec_printer(data: &[Option]) -> String -where - T: ToString, -{ - [ - "[", - &data - .iter() - .map(move |x| { - x.as_ref() - .map(|x_1| x_1.to_string()) - .unwrap_or_else(|| "None".to_owned()) - }) - .join(", "), - "]", - ] - .concat() +pub fn option_vec_printer(data: &[Option]) -> String { + let formatted: String = data + .into_iter() + .map(|item| match item { + Some(x) => x.to_string(), + None => "None".to_owned(), + }) + .join(", "); + + format!("[{}]", formatted) } /// Returns a vector of length `max_i` starting at value `min_x` with step of `step` diff --git a/tests/parsing.rs b/tests/parsing.rs index f5333a5..a61bac9 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -281,12 +281,12 @@ fn get_last_term() { #[test] fn hint_accessor() { assert_eq!(Hint::Single("hint").many(), None); - assert_eq!(Hint::Single("hint").single(), Some(&"hint")); + assert_eq!(Hint::Single("hint").single(), Some("hint")); assert_eq!(Hint::Many(&["hint", "hint2"]).single(), None); assert_eq!( Hint::Many(&["hint", "hint2"]).many(), - Some(&["hint", "hint2"].as_slice()) + Some(["hint", "hint2"].as_slice()) ); assert_eq!(Hint::None.single(), None);