This commit is contained in:
Simon Gardling
2022-05-05 10:39:34 -04:00
parent e170dee22a
commit 73e3760a8b
9 changed files with 57 additions and 64 deletions

View File

@@ -30,11 +30,6 @@ impl fmt::Display for Riemann {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
}
lazy_static::lazy_static! {
/// Represents a "default" instance of `FunctionEntry`
pub static ref DEFAULT_FUNCTION_ENTRY: FunctionEntry = FunctionEntry::default();
}
/// `FunctionEntry` is a function that can calculate values, integrals, derivatives, etc etc
#[derive(Clone)]
pub struct FunctionEntry {
@@ -71,11 +66,11 @@ pub struct FunctionEntry {
pub settings_opened: bool,
}
impl Default for FunctionEntry {
impl const Default for FunctionEntry {
/// Creates default FunctionEntry instance (which is empty)
fn default() -> FunctionEntry {
FunctionEntry {
function: BackingFunction::new("").unwrap(),
function: BackingFunction::EMPTY,
raw_func_str: String::new(),
min_x: -1.0,
max_x: 1.0,

View File

@@ -1,7 +1,7 @@
use crate::consts::is_mobile;
use crate::function_entry::{FunctionEntry, DEFAULT_FUNCTION_ENTRY};
use crate::function_entry::FunctionEntry;
use crate::widgets::{move_cursor_to_end, widgets_ontop, Movement};
use egui::{Button, Key, Modifiers, RichText, WidgetText};
use egui::{Button, Key, Modifiers, WidgetText};
use emath::vec2;
use parsing::suggestions::Hint;
use std::ops::BitXorAssign;
@@ -14,11 +14,16 @@ pub struct FunctionManager {
impl Default for FunctionManager {
fn default() -> Self {
Self {
functions: vec![(Uuid::new_v4(), DEFAULT_FUNCTION_ENTRY.clone())],
functions: vec![(Uuid::new_v4(), FunctionEntry::default())],
}
}
}
/// Function that creates button that's used with the `button_area`
const fn button_area_button(text: impl Into<WidgetText>) -> Button {
Button::new(text).frame(false)
}
impl FunctionManager {
pub fn display_entries(&mut self, ui: &mut egui::Ui) {
// ui.label("Functions:");
@@ -127,11 +132,6 @@ impl FunctionManager {
}
}
/// Function that creates button that's used with the `button_area`
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
const BUTTONS_Y_OFFSET: f32 = 1.32;
@@ -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("".to_owned()))
.add_enabled(can_remove, button_area_button(""))
.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("".to_owned()))
ui.add(button_area_button(""))
.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".to_owned()))
ui.add(button_area_button("d/dx"))
.on_hover_text(match function.derivative {
true => "Don't Differentiate",
false => "Differentiate",
@@ -194,7 +194,7 @@ impl FunctionManager {
pub fn new_function(&mut self) {
self.functions
.push((Uuid::new_v4(), DEFAULT_FUNCTION_ENTRY.clone()));
.push((Uuid::new_v4(), FunctionEntry::default()));
}
pub fn any_using_integral(&self) -> bool {

View File

@@ -3,6 +3,8 @@
#![feature(stmt_expr_attributes)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]
#![feature(const_convert)]
#![feature(const_default_impls)]
#[macro_use]
extern crate static_assertions;

View File

@@ -63,7 +63,7 @@ pub struct AppSettings {
pub plot_width: usize,
}
impl Default for AppSettings {
impl const Default for AppSettings {
/// Default implementation of `AppSettings`, this is how the application
/// starts up
fn default() -> Self {
@@ -88,7 +88,7 @@ struct Opened {
pub welcome: bool,
}
impl Default for Opened {
impl const Default for Opened {
fn default() -> Opened {
Self {
help: false,