fix bounds

This commit is contained in:
Simon Gardling 2022-02-23 18:31:26 -05:00
parent 04202257fe
commit 474ccb949f
2 changed files with 23 additions and 8 deletions

View File

@ -1,7 +1,6 @@
## TODO: ## TODO:
1. Port to [egui](https://github.com/emilk/egui) 1. Port to [egui](https://github.com/emilk/egui)
- Proper support for dynamic chart display size. - Proper support for dynamic chart display size.
- Fix bounds
- Add time took to generate - Add time took to generate
2. Multiple functions in one graph. 2. Multiple functions in one graph.
3. Non `y=` functions. 3. Non `y=` functions.

View File

@ -1,5 +1,3 @@
use crate::chart_manager::ChartManager; use crate::chart_manager::ChartManager;
use crate::misc::{digits_precision, test_func}; use crate::misc::{digits_precision, test_func};
use eframe::{egui, epi}; use eframe::{egui, epi};
@ -10,8 +8,6 @@ use egui::{
use egui::{Color32}; use egui::{Color32};
pub struct MathApp { pub struct MathApp {
func_str: String, func_str: String,
min_x: f64, min_x: f64,
@ -35,7 +31,7 @@ impl Default for MathApp {
} }
impl epi::App for MathApp { impl epi::App for MathApp {
fn name(&self) -> &str { "eframe template" } fn name(&self) -> &str { "Integral Demo" }
/// Called once before the first frame. /// Called once before the first frame.
fn setup( fn setup(
@ -55,6 +51,9 @@ impl epi::App for MathApp {
chart_manager, chart_manager,
} = self; } = self;
let min_x_total: f32 = -1000.0;
let max_x_total: f32 = 1000.0;
let mut parse_error: String = "".to_string(); let mut parse_error: String = "".to_string();
egui::SidePanel::left("side_panel").show(ctx, |ui| { egui::SidePanel::left("side_panel").show(ctx, |ui| {
ui.heading("Side Panel"); ui.heading("Side Panel");
@ -68,8 +67,25 @@ impl epi::App for MathApp {
parse_error = func_test_output; parse_error = func_test_output;
} }
ui.add(egui::Slider::new(min_x, -1000.0..=1000.0).text("Min X")); let x_range = min_x_total as f64..=max_x_total as f64;
ui.add(egui::Slider::new(max_x, *min_x..=1000.0).text("Max X")); let min_x_old = min_x.clone();
let min_x_response = ui.add(egui::Slider::new(min_x, x_range.clone()).text("Min X"));
let max_x_old = max_x.clone();
let max_x_response = ui.add(egui::Slider::new(max_x, x_range).text("Max X"));
if min_x >= max_x {
if max_x_response.changed() {
*max_x = max_x_old;
} else if min_x_response.changed() {
*min_x = min_x_old;
} else {
*min_x = -10.0;
*max_x = 10.0;
}
}
ui.add(egui::Slider::new(num_interval, 1..=usize::MAX).text("Interval")); ui.add(egui::Slider::new(num_interval, 1..=usize::MAX).text("Interval"));
}); });