From c20ea511baa52936acf731421f1369ba8f2d7609 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Sat, 26 Feb 2022 00:24:42 -0500 Subject: [PATCH] add top panel --- src/egui_app.rs | 24 ++++++++++++++++-------- src/function.rs | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/egui_app.rs b/src/egui_app.rs index 5f0425f..b64dff7 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -31,7 +31,7 @@ pub struct MathApp { integral_num: usize, - help_open: bool + help_open: bool, } impl Default for MathApp { @@ -108,26 +108,34 @@ impl epi::App for MathApp { ui.label("- signum, min, max"); }); - let mut parse_error: String = "".to_string(); - egui::SidePanel::left("side_panel") - .resizable(false) - .show(ctx, |ui| { - ui.heading("Side Panel"); + egui::TopBottomPanel::top("top_bar").show(ctx, |ui| { + ui.horizontal(|ui| { if ui.add(egui::Button::new("Add function")).clicked() { // min_x and max_x will be updated later, doesn't matter here - functions.push(Function::new(String::from(DEFAULT_FUNCION), -1.0, + functions.push(Function::new( + String::from(DEFAULT_FUNCION), + -1.0, 1.0, 100, false, None, None, - None)); + None, + )); func_strs.push(String::from(DEFAULT_FUNCION)); } if ui.add(egui::Button::new("Open Help")).clicked() { *help_open = true; } + }); + }); + + let mut parse_error: String = "".to_string(); + egui::SidePanel::left("side_panel") + .resizable(false) + .show(ctx, |ui| { + ui.heading("Side Panel"); let min_x_old = *integral_min_x; let min_x_response = diff --git a/src/function.rs b/src/function.rs index 4d19111..6b29a38 100644 --- a/src/function.rs +++ b/src/function.rs @@ -54,8 +54,8 @@ pub struct Function { impl Function { pub fn new( - func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool, integral_min_x: Option, - integral_max_x: Option, integral_num: Option, + func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool, + integral_min_x: Option, integral_max_x: Option, integral_num: Option, ) -> Self { // Makes sure proper arguments are passed when integral is enabled if integral { @@ -171,9 +171,9 @@ impl Function { let front_values: Vec = match self.back_cache.is_valid() { false => { let absrange = (self.max_x - self.min_x).abs(); - let resolution: f64 = (self.pixel_width as f64/absrange) as f64; + let resolution: f64 = (self.pixel_width as f64 / absrange) as f64; let front_data: Vec<(f64, f64)> = (1..=self.pixel_width) - .map(|x| ((x as f64 / resolution as f64)) + self.min_x) + .map(|x| (x as f64 / resolution as f64) + self.min_x) // .step_by() .map(|x| (x, self.run_func(x))) .collect();