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,
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 =

View File

@ -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<f64>,
integral_max_x: Option<f64>, integral_num: Option<usize>,
func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool,
integral_min_x: Option<f64>, integral_max_x: Option<f64>, integral_num: Option<usize>,
) -> Self {
// Makes sure proper arguments are passed when integral is enabled
if integral {
@ -171,9 +171,9 @@ impl Function {
let front_values: Vec<Value> = 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();