UI/UX improvements

This commit is contained in:
Simon Gardling 2022-03-01 18:57:47 -05:00
parent ef5a122019
commit f2191b26ed

View File

@ -5,7 +5,7 @@ use crate::misc::{add_asterisks, digits_precision, test_func};
use eframe::{egui, epi}; use eframe::{egui, epi};
use egui::plot::Plot; use egui::plot::Plot;
use egui::widgets::Button; use egui::widgets::Button;
use egui::{Color32, FontData, FontFamily, RichText, Vec2}; use egui::{Color32, FontData, FontFamily, Frame, RichText, Vec2};
use git_version::git_version; use git_version::git_version;
use include_flate::flate; use include_flate::flate;
@ -147,7 +147,11 @@ impl epi::App for MathApp {
// Creates Top bar that contains some general options // Creates Top bar that contains some general options
egui::TopBottomPanel::top("top_bar").show(ctx, |ui| { egui::TopBottomPanel::top("top_bar").show(ctx, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.add(egui::Button::new("Add Function")).clicked() { if ui
.add(egui::Button::new("Add Function"))
.on_hover_text("Create and graph new function")
.clicked()
{
self.functions.push(Function::new( self.functions.push(Function::new(
String::from(DEFAULT_FUNCION), String::from(DEFAULT_FUNCION),
-1.0, // Doesn't matter, updated later -1.0, // Doesn't matter, updated later
@ -162,11 +166,19 @@ impl epi::App for MathApp {
self.func_strs.push(String::from(DEFAULT_FUNCION)); self.func_strs.push(String::from(DEFAULT_FUNCION));
} }
if ui.add(egui::Button::new("Help")).clicked() { if ui
.add(egui::Button::new("Help"))
.on_hover_text("Open Help Window")
.clicked()
{
self.help_open = !self.help_open; self.help_open = !self.help_open;
} }
if ui.add(egui::Button::new("Info")).clicked() { if ui
.add(egui::Button::new("Info"))
.on_hover_text("Open Info Window")
.clicked()
{
self.info_open = !self.info_open; self.info_open = !self.info_open;
} }
}); });
@ -206,21 +218,25 @@ impl epi::App for MathApp {
}); });
let min_x_old = self.integral_min_x; let min_x_old = self.integral_min_x;
let min_x_response = ui.add( let min_x_changed = ui
.add(
egui::Slider::new(&mut self.integral_min_x, INTEGRAL_X_RANGE.clone()) egui::Slider::new(&mut self.integral_min_x, INTEGRAL_X_RANGE.clone())
.text("Min X"), .text("Min X"),
); )
.changed();
let max_x_old = self.integral_max_x; let max_x_old = self.integral_max_x;
let max_x_response = ui.add( let max_x_changed = ui
.add(
egui::Slider::new(&mut self.integral_max_x, INTEGRAL_X_RANGE).text("Max X"), egui::Slider::new(&mut self.integral_max_x, INTEGRAL_X_RANGE).text("Max X"),
); )
.changed();
// Checks bounds, and if they are invalid, fix them // Checks bounds, and if they are invalid, fix them
if self.integral_min_x >= self.integral_max_x { if self.integral_min_x >= self.integral_max_x {
if max_x_response.changed() { if max_x_changed {
self.integral_max_x = max_x_old; self.integral_max_x = max_x_old;
} else if min_x_response.changed() { } else if min_x_changed {
self.integral_min_x = min_x_old; self.integral_min_x = min_x_old;
} else { } else {
// No clue how this would happen, but just in case // No clue how this would happen, but just in case
@ -239,7 +255,15 @@ impl epi::App for MathApp {
// Entry for a function // Entry for a function
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Function: "); ui.label("Function: ");
if ui.add(Button::new("")).clicked() { let mut integral_opt_text = "Integrate";
if function.integral {
integral_opt_text = "Don't integrate";
}
if ui
.add(Button::new(""))
.on_hover_text(integral_opt_text)
.clicked()
{
integral_toggle = true; integral_toggle = true;
} }
ui.text_edit_singleline(&mut self.func_strs[i]); ui.text_edit_singleline(&mut self.func_strs[i]);
@ -272,16 +296,12 @@ impl epi::App for MathApp {
} }
// Open Source and Licensing information // Open Source and Licensing information
ui.horizontal(|ui| {
ui.hyperlink_to( ui.hyperlink_to(
"I'm Opensource!", "I'm Opensource!",
"https://github.com/Titaniumtown/integral_site", "https://github.com/Titaniumtown/integral_site",
); );
ui.label( ui.label(RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY))
RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY),
)
.on_hover_text(LICENSE_INFO); .on_hover_text(LICENSE_INFO);
});
// Displays commit info // Displays commit info
ui.horizontal(|ui| { ui.horizontal(|ui| {
@ -290,7 +310,9 @@ impl epi::App for MathApp {
// Only include hyperlink if the build doesn't have untracked files // Only include hyperlink if the build doesn't have untracked files
if GIT_VERSION.contains("-modified") { if GIT_VERSION.contains("-modified") {
// If git version is modified, don't display a link to the commit on github (as the commit will not exist) // If git version is modified, don't display a link to the commit on github (as the commit will not exist)
ui.label(GIT_VERSION); ui.label(GIT_VERSION).on_hover_text(
"This build has been modified from the latest git commit.",
);
} else { } else {
ui.hyperlink_to( ui.hyperlink_to(
GIT_VERSION, GIT_VERSION,
@ -308,16 +330,24 @@ impl epi::App for MathApp {
let mut area_list: Vec<f64> = Vec::new(); // Stores list of areas resulting from calculating the integral of functions let mut area_list: Vec<f64> = Vec::new(); // Stores list of areas resulting from calculating the integral of functions
// Stores the final Plot // Stores the final Plot
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default()
.frame(Frame::none())
.show(ctx, |ui| {
if !parse_error.is_empty() { if !parse_error.is_empty() {
ui.label(parse_error); ui.centered_and_justified(|ui| {
ui.heading(parse_error);
});
return; return;
} }
let available_width: usize = ui.available_width() as usize; let available_width: usize = ui.available_width() as usize;
let plot_size = ui.available_size();
let plot_size = Vec2::new(plot_size.x, plot_size.y);
ui.allocate_ui(plot_size, |ui| {
Plot::new("plot") Plot::new("plot")
.set_margin_fraction(Vec2::ZERO) .set_margin_fraction(Vec2::ZERO)
// .view_aspect(1.0) // .view_aspect(1.0)
// .view_aspect()
.data_aspect(1.0) .data_aspect(1.0)
.include_y(0) .include_y(0)
.show(ui, |plot_ui| { .show(ui, |plot_ui| {
@ -347,6 +377,7 @@ impl epi::App for MathApp {
} }
}); });
}); });
});
let duration = start.elapsed(); let duration = start.elapsed();
@ -364,4 +395,6 @@ impl epi::App for MathApp {
)); ));
}); });
} }
fn max_size_points(&self) -> egui::Vec2 { egui::Vec2::new(f32::MAX, f32::MAX) } // Allow proper scaling
} }