diff --git a/Cargo.toml b/Cargo.toml index 4cdd01a..d4d7f05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ opt-level = 2 lto = false [dependencies] -eframe = { git = "https://github.com/emilk/egui.git", default-features = false } +eframe = { git = "https://github.com/Titaniumtown/egui.git", default-features = false } shadow-rs = { version = "0.11.0", default-features = false } const_format = { version = "0.2.22", default-features = false, features = [ "fmt", diff --git a/TODO.md b/TODO.md index f3f2b1d..dd3fec4 100644 --- a/TODO.md +++ b/TODO.md @@ -17,7 +17,7 @@ 10. Look into other, better methods of compression that would be faster 11. Better handling of panics and errors to display to the user 12. Hints for functions - - Random default functions + - Random default functions for demo purposes - Syntax - - Parentheses + - Parentheses (Done) - Function names diff --git a/src/egui_app.rs b/src/egui_app.rs index abb7060..f3ce289 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -1,6 +1,6 @@ use crate::function::{FunctionEntry, Riemann, DEFAULT_FUNCTION_ENTRY}; use crate::misc::{dyn_mut_iter, option_vec_printer, JsonFileOutput, SerdeValueHelper}; -use crate::parsing::{process_func_str, test_func}; +use crate::parsing::{generate_hint, process_func_str, test_func}; use crate::consts::*; use eframe::{egui, epi}; @@ -446,8 +446,6 @@ impl MathApp { let functions_len = self.functions.len(); let mut remove_i: Option = None; - - let mut gave_hint: bool = false; for (i, function) in self.functions.iter_mut().enumerate() { let mut integral_enabled = function.integral; let mut derivative_enabled = function.derivative; @@ -493,13 +491,11 @@ impl MathApp { .clicked(); // Contains the function string in a text box that the user can edit - TextEdit::singleline(&mut self.func_strs[i]) - .hint_text(if gave_hint { "" } else { "x^2" }) - .ui(ui); + let hint = generate_hint(&self.func_strs[i]); - if self.func_strs[i].is_empty() { - gave_hint = true; - } + TextEdit::singleline(&mut self.func_strs[i]) + .hint_text(hint, true) + .ui(ui); }); let proc_func_str = process_func_str(&self.func_strs[i]); diff --git a/src/parsing.rs b/src/parsing.rs index 9ca6690..eb0849b 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -204,6 +204,23 @@ pub fn test_func(function_string: &str) -> Option { } } +pub fn generate_hint(input: &str) -> String { + if input.is_empty() { + return "x^2".to_owned(); + } + + let chars: Vec = input.chars().collect(); + + let open_parens = chars.iter().filter(|c| **c == '(').count(); + let closed_parents = chars.iter().filter(|c| **c == ')').count(); + + if open_parens > closed_parents { + return ")".to_owned(); + } + + String::new() +} + #[cfg(test)] mod tests { use super::*;