ui changes
This commit is contained in:
@@ -21,17 +21,6 @@ pub const BUILD_INFO: &str = formatc!(
|
|||||||
/// Range of acceptable input values for integral_num
|
/// Range of acceptable input values for integral_num
|
||||||
pub const INTEGRAL_NUM_RANGE: RangeInclusive<usize> = 1..=50000;
|
pub const INTEGRAL_NUM_RANGE: RangeInclusive<usize> = 1..=50000;
|
||||||
|
|
||||||
/// Minimum X value for calculating an Integral
|
|
||||||
pub const INTEGRAL_X_MIN: f64 = -1000.0;
|
|
||||||
|
|
||||||
/// Maximum X value for calculating an Integral
|
|
||||||
pub const INTEGRAL_X_MAX: f64 = 1000.0;
|
|
||||||
|
|
||||||
const_assert!(INTEGRAL_X_MAX > INTEGRAL_X_MIN);
|
|
||||||
|
|
||||||
/// Range of acceptable x coordinates for calculating an integral
|
|
||||||
pub const INTEGRAL_X_RANGE: RangeInclusive<f64> = INTEGRAL_X_MIN..=INTEGRAL_X_MAX;
|
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
/// Default minimum X value to display
|
/// Default minimum X value to display
|
||||||
pub const DEFAULT_MIN_X: f64 = -10.0;
|
pub const DEFAULT_MIN_X: f64 = -10.0;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use egui::{
|
|||||||
plot::Plot, style::Margin, Button, CentralPanel, ComboBox, Context, Frame, Key, Layout,
|
plot::Plot, style::Margin, Button, CentralPanel, ComboBox, Context, Frame, Key, Layout,
|
||||||
SidePanel, Slider, TopBottomPanel, Vec2, Window,
|
SidePanel, Slider, TopBottomPanel, Vec2, Window,
|
||||||
};
|
};
|
||||||
|
use egui::{DragValue, Ui};
|
||||||
use emath::{Align, Align2};
|
use emath::{Align, Align2};
|
||||||
use epaint::Rounding;
|
use epaint::Rounding;
|
||||||
use instant::Instant;
|
use instant::Instant;
|
||||||
@@ -271,9 +272,10 @@ impl MathApp {
|
|||||||
SidePanel::left("side_panel")
|
SidePanel::left("side_panel")
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
|
let any_using_integral = self.functions.any_using_integral();
|
||||||
let prev_sum = self.settings.riemann_sum;
|
let prev_sum = self.settings.riemann_sum;
|
||||||
// ComboBox for selecting what Riemann sum type to use
|
// ComboBox for selecting what Riemann sum type to use
|
||||||
ui.add_enabled_ui(self.functions.any_using_integral(), |ui| {
|
ui.add_enabled_ui(any_using_integral, |ui| {
|
||||||
ComboBox::from_label("Riemann Sum")
|
ComboBox::from_label("Riemann Sum")
|
||||||
.selected_text(self.settings.riemann_sum.to_string())
|
.selected_text(self.settings.riemann_sum.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
@@ -293,9 +295,57 @@ impl MathApp {
|
|||||||
"Right",
|
"Right",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
let riemann_changed = prev_sum != self.settings.riemann_sum;
|
let riemann_changed = prev_sum != self.settings.riemann_sum;
|
||||||
|
|
||||||
|
let min_x_old = self.settings.integral_min_x;
|
||||||
|
let max_x_old = self.settings.integral_max_x;
|
||||||
|
|
||||||
|
let (min_x_changed, max_x_changed) = ui
|
||||||
|
.horizontal(|ui: &mut Ui| {
|
||||||
|
let spacing_mut = ui.spacing_mut();
|
||||||
|
|
||||||
|
spacing_mut.item_spacing = Vec2::new(1.0, 0.0);
|
||||||
|
spacing_mut.interact_size *= 0.5;
|
||||||
|
|
||||||
|
ui.label("Integral: [");
|
||||||
|
let min_x_changed = ui
|
||||||
|
.add(DragValue::new(&mut self.settings.integral_min_x))
|
||||||
|
.changed();
|
||||||
|
ui.label(",");
|
||||||
|
let max_x_changed = ui
|
||||||
|
.add(DragValue::new(&mut self.settings.integral_max_x))
|
||||||
|
.changed();
|
||||||
|
ui.label("]");
|
||||||
|
(min_x_changed, max_x_changed)
|
||||||
|
})
|
||||||
|
.inner;
|
||||||
|
|
||||||
|
// Checks integral bounds, and if they are invalid, fix them
|
||||||
|
if self.settings.integral_min_x >= self.settings.integral_max_x {
|
||||||
|
if max_x_changed {
|
||||||
|
self.settings.integral_max_x = max_x_old;
|
||||||
|
} else if min_x_changed {
|
||||||
|
self.settings.integral_min_x = min_x_old;
|
||||||
|
} else {
|
||||||
|
// No clue how this would happen, but just in case
|
||||||
|
self.settings.integral_min_x = DEFAULT_MIN_X;
|
||||||
|
self.settings.integral_max_x = DEFAULT_MAX_X;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number of Rectangles for Riemann sum
|
||||||
|
let integral_num_changed = ui
|
||||||
|
.add_enabled(
|
||||||
|
any_using_integral,
|
||||||
|
Slider::new(&mut self.settings.integral_num, INTEGRAL_NUM_RANGE)
|
||||||
|
.text("Interval"),
|
||||||
|
)
|
||||||
|
.changed();
|
||||||
|
|
||||||
|
self.settings.integral_changed = any_using_integral
|
||||||
|
&& (max_x_changed | min_x_changed | integral_num_changed | riemann_changed);
|
||||||
|
});
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
self.settings.do_extrema.bitxor_assign(
|
self.settings.do_extrema.bitxor_assign(
|
||||||
@@ -317,50 +367,10 @@ impl MathApp {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
let min_x_old = self.settings.integral_min_x;
|
|
||||||
let min_x_changed = ui
|
|
||||||
.add(
|
|
||||||
Slider::new(&mut self.settings.integral_min_x, INTEGRAL_X_RANGE)
|
|
||||||
.text("Min X"),
|
|
||||||
)
|
|
||||||
.changed();
|
|
||||||
|
|
||||||
let max_x_old = self.settings.integral_max_x;
|
|
||||||
let max_x_changed = ui
|
|
||||||
.add(
|
|
||||||
Slider::new(&mut self.settings.integral_max_x, INTEGRAL_X_RANGE)
|
|
||||||
.text("Max X"),
|
|
||||||
)
|
|
||||||
.changed();
|
|
||||||
|
|
||||||
// Checks integral bounds, and if they are invalid, fix them
|
|
||||||
if self.settings.integral_min_x >= self.settings.integral_max_x {
|
|
||||||
if max_x_changed {
|
|
||||||
self.settings.integral_max_x = max_x_old;
|
|
||||||
} else if min_x_changed {
|
|
||||||
self.settings.integral_min_x = min_x_old;
|
|
||||||
} else {
|
|
||||||
// No clue how this would happen, but just in case
|
|
||||||
self.settings.integral_min_x = DEFAULT_MIN_X;
|
|
||||||
self.settings.integral_max_x = DEFAULT_MAX_X;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Number of Rectangles for Riemann sum
|
|
||||||
let integral_num_changed = ui
|
|
||||||
.add(
|
|
||||||
Slider::new(&mut self.settings.integral_num, INTEGRAL_NUM_RANGE)
|
|
||||||
.text("Interval"),
|
|
||||||
)
|
|
||||||
.changed();
|
|
||||||
|
|
||||||
self.settings.integral_changed =
|
|
||||||
max_x_changed | min_x_changed | integral_num_changed | riemann_changed;
|
|
||||||
|
|
||||||
self.functions.display_entries(ui);
|
self.functions.display_entries(ui);
|
||||||
|
|
||||||
// Only render if there's enough space
|
// Only render if there's enough space
|
||||||
if ui.available_height() > 0.0 {
|
if ui.available_height() > 14.0 {
|
||||||
ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
|
ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
|
||||||
// Contents put in reverse order from bottom to top due to the 'buttom_up' layout
|
// Contents put in reverse order from bottom to top due to the 'buttom_up' layout
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user