hints
This commit is contained in:
parent
345851d8b4
commit
6d57d96bb2
@ -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",
|
||||
|
||||
4
TODO.md
4
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
|
||||
|
||||
@ -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<usize> = 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]);
|
||||
|
||||
@ -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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user