UI improvements

This commit is contained in:
Simon Gardling 2022-02-25 11:57:31 -05:00
parent b98640d54a
commit 274d072bfe
3 changed files with 34 additions and 8 deletions

View File

@ -7,6 +7,7 @@
- Generation of data - Generation of data
- Management - Management
- Handle by IDs - Handle by IDs
- Integrals between functions
- UI - UI
- Dynamically create inputs - Dynamically create inputs
- Different colors - Different colors

View File

@ -3,8 +3,9 @@ use std::ops::RangeInclusive;
use crate::function::Function; use crate::function::Function;
use crate::misc::{digits_precision, test_func}; use crate::misc::{digits_precision, test_func};
use eframe::{egui, epi}; use eframe::{egui, epi};
use egui::plot::{Line, Plot, Value, Values}; use egui::plot::{Line, Plot, Values};
use egui::widgets::plot::{Bar, BarChart}; use egui::widgets::plot::BarChart;
use egui::widgets::Button;
use egui::Color32; use egui::Color32;
use git_version::git_version; use git_version::git_version;
@ -16,6 +17,7 @@ const INTEGRAL_NUM_RANGE: RangeInclusive<usize> = 10..=1000000;
const MIN_X_TOTAL: f64 = -1000.0; const MIN_X_TOTAL: f64 = -1000.0;
const MAX_X_TOTAL: f64 = 1000.0; const MAX_X_TOTAL: f64 = 1000.0;
const X_RANGE: RangeInclusive<f64> = MIN_X_TOTAL..=MAX_X_TOTAL; const X_RANGE: RangeInclusive<f64> = MIN_X_TOTAL..=MAX_X_TOTAL;
const DEFAULT_FUNCION: &str = "x^2";
pub struct MathApp { pub struct MathApp {
functions: Vec<Function>, functions: Vec<Function>,
@ -32,13 +34,12 @@ pub struct MathApp {
impl Default for MathApp { impl Default for MathApp {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
let def_func_str = "x^2".to_string();
let def_min_x = -10.0; let def_min_x = -10.0;
let def_max_x = 10.0; let def_max_x = 10.0;
let def_interval: usize = 1000; let def_interval: usize = 1000;
let def_funcs: Vec<Function> = vec![Function::new( let def_funcs: Vec<Function> = vec![Function::new(
def_func_str, String::from(DEFAULT_FUNCION),
def_min_x, def_min_x,
def_max_x, def_max_x,
true, true,
@ -104,17 +105,29 @@ impl epi::App for MathApp {
ui.label("- signum, min, max"); ui.label("- signum, min, max");
}); });
let mut func_new_strings: Vec<String> = Vec::new(); let mut new_func_data: Vec<(String, bool)> = Vec::new();
let mut parse_error: String = "".to_string(); let mut parse_error: String = "".to_string();
egui::SidePanel::left("side_panel") egui::SidePanel::left("side_panel")
.resizable(false) .resizable(false)
.show(ctx, |ui| { .show(ctx, |ui| {
ui.heading("Side Panel"); ui.heading("Side Panel");
if ui.add(egui::Button::new("Add function")).clicked() {
functions.push(Function::new(String::from(DEFAULT_FUNCION), *min_x,
*max_x,
true,
Some(*min_x),
Some(*max_x),
Some(*integral_num)));
}
for function in functions.iter() { for function in functions.iter() {
let mut func_str = function.get_string(); let mut func_str = function.get_string();
let mut integral_toggle: bool = false;
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Function: "); ui.label("Function: ");
if ui.add(Button::new("Toggle Integrals")).clicked() {
integral_toggle = true;
}
ui.text_edit_singleline(&mut func_str); ui.text_edit_singleline(&mut func_str);
}); });
@ -123,7 +136,7 @@ impl epi::App for MathApp {
parse_error += &func_test_output; parse_error += &func_test_output;
} }
func_new_strings.push(func_str); new_func_data.push((func_str, integral_toggle));
} }
let min_x_old = *min_x; let min_x_old = *min_x;
@ -178,7 +191,15 @@ impl epi::App for MathApp {
let mut i: usize = 0; let mut i: usize = 0;
for function in functions.iter_mut() { for function in functions.iter_mut() {
function.update(func_new_strings[i].clone(), *min_x, *max_x, true, Some(*integral_min_x), Some(*integral_max_x), Some(*integral_num)); let (func_str, integral_toggle) = (new_func_data[i].0.clone(), new_func_data[i].1);
let integral: bool = if integral_toggle {
!function.is_integral()
} else {
function.is_integral()
};
function.update(func_str, *min_x, *max_x, integral, Some(*integral_min_x), Some(*integral_max_x), Some(*integral_num));
i += 1; i += 1;
} }
}); });

View File

@ -32,7 +32,7 @@ impl FunctionOutput {
#[inline] #[inline]
pub fn has_integral(&self) -> bool { pub fn has_integral(&self) -> bool {
match &self.front { match &self.front {
Some(x) => true, Some(_) => true,
None => false, None => false,
} }
} }
@ -123,6 +123,10 @@ impl Function {
self.max_x = max_x; self.max_x = max_x;
} }
if integral != self.integral {
self.integral = integral;
}
// Makes sure proper arguments are passed when integral is enabled // Makes sure proper arguments are passed when integral is enabled
if integral { if integral {
if integral_min_x.is_none() { if integral_min_x.is_none() {