add top panel

This commit is contained in:
Simon Gardling 2022-02-26 00:24:42 -05:00
parent cdc142d39e
commit c20ea511ba
2 changed files with 20 additions and 12 deletions

View File

@ -31,7 +31,7 @@ pub struct MathApp {
integral_num: usize, integral_num: usize,
help_open: bool help_open: bool,
} }
impl Default for MathApp { impl Default for MathApp {
@ -108,26 +108,34 @@ impl epi::App for MathApp {
ui.label("- signum, min, max"); ui.label("- signum, min, max");
}); });
let mut parse_error: String = "".to_string(); egui::TopBottomPanel::top("top_bar").show(ctx, |ui| {
egui::SidePanel::left("side_panel") ui.horizontal(|ui| {
.resizable(false)
.show(ctx, |ui| {
ui.heading("Side Panel");
if ui.add(egui::Button::new("Add function")).clicked() { if ui.add(egui::Button::new("Add function")).clicked() {
// min_x and max_x will be updated later, doesn't matter here // 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, 1.0,
100, 100,
false, false,
None, None,
None, None,
None)); None,
));
func_strs.push(String::from(DEFAULT_FUNCION)); func_strs.push(String::from(DEFAULT_FUNCION));
} }
if ui.add(egui::Button::new("Open Help")).clicked() { if ui.add(egui::Button::new("Open Help")).clicked() {
*help_open = true; *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_old = *integral_min_x;
let min_x_response = let min_x_response =

View File

@ -54,8 +54,8 @@ pub struct Function {
impl Function { impl Function {
pub fn new( pub fn new(
func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool, integral_min_x: Option<f64>, func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool,
integral_max_x: Option<f64>, integral_num: Option<usize>, integral_min_x: Option<f64>, integral_max_x: Option<f64>, integral_num: Option<usize>,
) -> Self { ) -> Self {
// Makes sure proper arguments are passed when integral is enabled // Makes sure proper arguments are passed when integral is enabled
if integral { if integral {
@ -171,9 +171,9 @@ impl Function {
let front_values: Vec<Value> = match self.back_cache.is_valid() { let front_values: Vec<Value> = match self.back_cache.is_valid() {
false => { false => {
let absrange = (self.max_x - self.min_x).abs(); 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) 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() // .step_by()
.map(|x| (x, self.run_func(x))) .map(|x| (x, self.run_func(x)))
.collect(); .collect();