MAJOR refactoring

This commit is contained in:
Simon Gardling
2022-05-03 11:50:13 -04:00
parent 8952552eef
commit 13a47ec30b
12 changed files with 243 additions and 218 deletions

View File

@@ -1,7 +1,7 @@
use crate::consts::is_mobile;
use crate::function_entry::{FunctionEntry, DEFAULT_FUNCTION_ENTRY};
use crate::widgets::{move_cursor_to_end, widgets_ontop, Movement};
use egui::{Button, Key, Modifiers};
use egui::{Button, Key, Modifiers, RichText, WidgetText};
use emath::vec2;
use parsing::suggestions::Hint;
use std::ops::BitXorAssign;
@@ -128,8 +128,8 @@ impl FunctionManager {
}
/// Function that creates button that's used with the `button_area`
fn button_area_button(text: impl Into<egui::WidgetText>) -> Button {
Button::new(text.into()).frame(false)
const fn button_area_button(text: String) -> Button {
Button::new_const(WidgetText::RichText(RichText::new_const(text))).frame(false)
}
/// the y offset multiplier of the `buttons_area` area
@@ -144,7 +144,7 @@ impl FunctionManager {
ui.horizontal(|ui| {
// There's more than 1 function! Functions can now be deleted
if ui
.add_enabled(can_remove, button_area_button(""))
.add_enabled(can_remove, button_area_button("".to_owned()))
.on_hover_text("Delete Function")
.clicked()
{
@@ -153,7 +153,7 @@ impl FunctionManager {
// Toggle integral being enabled or not
function.integral.bitxor_assign(
ui.add(button_area_button(""))
ui.add(button_area_button("".to_owned()))
.on_hover_text(match function.integral {
true => "Don't integrate",
false => "Integrate",
@@ -163,7 +163,7 @@ impl FunctionManager {
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
function.derivative.bitxor_assign(
ui.add(button_area_button("d/dx"))
ui.add(button_area_button("d/dx".to_owned()))
.on_hover_text(match function.derivative {
true => "Don't Differentiate",
false => "Differentiate",
@@ -172,7 +172,7 @@ impl FunctionManager {
);
function.settings_opened.bitxor_assign(
ui.add(button_area_button(""))
ui.add(button_area_button("".to_owned()))
.on_hover_text(match function.settings_opened {
true => "Close Settings",
false => "Open Settings",

View File

@@ -1,6 +1,7 @@
#![feature(const_mut_refs)]
#![feature(let_chains)]
#![feature(stmt_expr_attributes)]
#![feature(const_trait_impl)]
#[macro_use]
extern crate static_assertions;

View File

@@ -1,6 +1,7 @@
#![feature(const_mut_refs)]
#![feature(let_chains)]
#![feature(stmt_expr_attributes)]
#![feature(const_trait_impl)]
#[macro_use]
extern crate static_assertions;

View File

@@ -2,6 +2,7 @@ use crate::consts::*;
use crate::function_entry::Riemann;
use crate::function_manager::FunctionManager;
use crate::misc::{dyn_mut_iter, option_vec_printer, TextData};
use eframe::App;
use egui::{
plot::Plot, style::Margin, vec2, Button, CentralPanel, Color32, ComboBox, Context, FontData,
FontDefinitions, FontFamily, Frame, Key, RichText, SidePanel, Slider, TopBottomPanel, Vec2,
@@ -136,8 +137,6 @@ impl MathApp {
#[cfg(not(threading))]
tracing::info!("Threading: Disabled");
tracing::info!("Integration name: {}", cc.integration_info.name);
if let Some(web_info) = &cc.integration_info.web_info {
tracing::info!("Web Info: {:?}", web_info);
}
@@ -382,9 +381,9 @@ impl MathApp {
}
}
impl epi::App for MathApp {
impl App for MathApp {
/// Called each time the UI needs repainting.
fn update(&mut self, ctx: &Context, _frame: &mut epi::Frame) {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
// start timer
let start = if self.opened.info {
Some(instant::Instant::now())

View File

@@ -298,7 +298,7 @@ where
.map(|x| {
x.as_ref()
.map(|x_1| x_1.to_string())
.unwrap_or_else(|| "None".to_string())
.unwrap_or_else(|| "None".to_owned())
})
.enumerate()
.map(|(i, x)| {

View File

@@ -10,7 +10,7 @@ pub enum Movement {
None,
}
impl Default for Movement {
impl const Default for Movement {
fn default() -> Self { Self::None }
}
@@ -21,7 +21,7 @@ pub struct AutoComplete<'a> {
pub string: String,
}
impl<'a> Default for AutoComplete<'a> {
impl<'a> const Default for AutoComplete<'a> {
fn default() -> AutoComplete<'a> {
AutoComplete {
i: 0,
@@ -34,9 +34,14 @@ impl<'a> Default for AutoComplete<'a> {
impl<'a> AutoComplete<'a> {
pub fn update_string(&mut self, string: &str) {
if self.string != string {
self.i = 0;
self.string = string.to_string();
self.hint = generate_hint(string);
// catch empty strings here to avoid call to `generate_hint` and unnecessary logic
if string.is_empty() {
*self = Self::default();
} else {
self.i = 0;
self.string = string.to_string();
self.hint = generate_hint(string);
}
}
}