This commit is contained in:
Simon Gardling 2022-03-28 20:05:21 -04:00
parent 345851d8b4
commit 6d57d96bb2
4 changed files with 25 additions and 12 deletions

View File

@ -22,7 +22,7 @@ opt-level = 2
lto = false lto = false
[dependencies] [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 } shadow-rs = { version = "0.11.0", default-features = false }
const_format = { version = "0.2.22", default-features = false, features = [ const_format = { version = "0.2.22", default-features = false, features = [
"fmt", "fmt",

View File

@ -17,7 +17,7 @@
10. Look into other, better methods of compression that would be faster 10. Look into other, better methods of compression that would be faster
11. Better handling of panics and errors to display to the user 11. Better handling of panics and errors to display to the user
12. Hints for functions 12. Hints for functions
- Random default functions - Random default functions for demo purposes
- Syntax - Syntax
- Parentheses - Parentheses (Done)
- Function names - Function names

View File

@ -1,6 +1,6 @@
use crate::function::{FunctionEntry, Riemann, DEFAULT_FUNCTION_ENTRY}; use crate::function::{FunctionEntry, Riemann, DEFAULT_FUNCTION_ENTRY};
use crate::misc::{dyn_mut_iter, option_vec_printer, JsonFileOutput, SerdeValueHelper}; 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 crate::consts::*;
use eframe::{egui, epi}; use eframe::{egui, epi};
@ -446,8 +446,6 @@ impl MathApp {
let functions_len = self.functions.len(); let functions_len = self.functions.len();
let mut remove_i: Option<usize> = None; let mut remove_i: Option<usize> = None;
let mut gave_hint: bool = false;
for (i, function) in self.functions.iter_mut().enumerate() { for (i, function) in self.functions.iter_mut().enumerate() {
let mut integral_enabled = function.integral; let mut integral_enabled = function.integral;
let mut derivative_enabled = function.derivative; let mut derivative_enabled = function.derivative;
@ -493,13 +491,11 @@ impl MathApp {
.clicked(); .clicked();
// Contains the function string in a text box that the user can edit // Contains the function string in a text box that the user can edit
TextEdit::singleline(&mut self.func_strs[i]) let hint = generate_hint(&self.func_strs[i]);
.hint_text(if gave_hint { "" } else { "x^2" })
.ui(ui);
if self.func_strs[i].is_empty() { TextEdit::singleline(&mut self.func_strs[i])
gave_hint = true; .hint_text(hint, true)
} .ui(ui);
}); });
let proc_func_str = process_func_str(&self.func_strs[i]); let proc_func_str = process_func_str(&self.func_strs[i]);

View File

@ -204,6 +204,23 @@ pub fn test_func(function_string: &str) -> Option<String> {
} }
} }
pub fn generate_hint(input: &str) -> String {
if input.is_empty() {
return "x^2".to_owned();
}
let chars: Vec<char> = 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;