This commit is contained in:
Simon Gardling 2022-02-23 15:38:07 -05:00
parent e7583b5497
commit 79457ad168
3 changed files with 13 additions and 14 deletions

View File

@ -1,17 +1,16 @@
use core::num;
use crate::chart_manager::ChartManager; use crate::chart_manager::ChartManager;
use crate::misc::{add_asterisks, digits_precision, test_func, Cache, Function}; use crate::misc::{digits_precision, test_func};
use eframe::{egui, epi}; use eframe::{egui, epi};
use egui::widgets::plot::{Bar, BarChart}; use egui::widgets::plot::{Bar, BarChart};
use egui::{ use egui::{
plot::{HLine, Line, Plot, Text, Value, Values}, plot::{Line, Plot, Value, Values},
Pos2,
}; };
use egui::{Color32, ColorImage, Ui}; use egui::{Color32};
use emath::Rect;
use epaint::{RectShape, Rounding, Stroke};
use meval::Expr;
pub struct MathApp { pub struct MathApp {
func_str: String, func_str: String,
@ -46,13 +45,13 @@ impl epi::App for MathApp {
/// Called each time the UI needs repainting, which may be many times per second. /// Called each time the UI needs repainting, which may be many times per second.
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
let Self { let Self {
func_str, func_str,
min_x, min_x,
max_x, max_x,
num_interval, num_interval,
resolution, resolution: _,
chart_manager, chart_manager,
} = self; } = self;
@ -65,7 +64,7 @@ impl epi::App for MathApp {
ui.text_edit_singleline(func_str); ui.text_edit_singleline(func_str);
}); });
let func_test_output = test_func(func_str.clone()); let func_test_output = test_func(func_str.clone());
if func_test_output != "" { if !func_test_output.is_empty() {
parse_error = func_test_output; parse_error = func_test_output;
} }
@ -76,7 +75,7 @@ impl epi::App for MathApp {
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
if parse_error != "" { if !parse_error.is_empty() {
ui.label(format!("Error: {}", parse_error)); ui.label(format!("Error: {}", parse_error));
return; return;
} }

View File

@ -4,7 +4,7 @@
mod chart_manager; mod chart_manager;
mod egui_app; mod egui_app;
mod misc; mod misc;
use std::panic;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use eframe::{egui, epi}; use eframe::{egui, epi};

View File

@ -109,7 +109,7 @@ pub fn test_func(function_string: String) -> String {
// Rounds f64 to specific number of digits // Rounds f64 to specific number of digits
pub fn digits_precision(x: f64, digits: usize) -> f64 { pub fn digits_precision(x: f64, digits: usize) -> f64 {
let large_number: f64 = (10.0 as f64).powf(digits as f64); let large_number: f64 = 10.0_f64.powf(digits as f64);
(x * large_number).round() / large_number (x * large_number).round() / large_number
} }