cleanup + remove Instant + remove Info window

This commit is contained in:
Simon Gardling 2025-12-05 13:50:55 -05:00
parent 63bd73e444
commit 957c286e59
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
6 changed files with 10 additions and 70 deletions

13
Cargo.lock generated
View File

@ -1325,18 +1325,6 @@ dependencies = [
"str_stack", "str_stack",
] ]
[[package]]
name = "instant"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
version = "0.4.17" version = "0.4.17"
@ -3997,7 +3985,6 @@ dependencies = [
"egui_plot", "egui_plot",
"emath", "emath",
"epaint", "epaint",
"instant",
"itertools 0.14.0", "itertools 0.14.0",
"lol_alloc", "lol_alloc",
"parsing", "parsing",

View File

@ -76,11 +76,9 @@ run_script = "0.11"
itertools = "0.14" itertools = "0.14"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
instant = "0.1"
tracing-subscriber = "0.3" tracing-subscriber = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1", features = ["wasm-bindgen"] }
lol_alloc = "0.4.1" lol_alloc = "0.4.1"
wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] } wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
web-sys = "0.3" web-sys = "0.3"

View File

@ -1,6 +1,6 @@
use epaint::{ use epaint::{
text::{FontData, FontDefinitions, FontTweak},
FontFamily, FontFamily,
text::{FontData, FontDefinitions, FontTweak},
}; };
use run_script::ScriptOptions; use run_script::ScriptOptions;
use std::{ use std::{

View File

@ -13,10 +13,7 @@ mod widgets;
pub use crate::{ pub use crate::{
function_entry::{FunctionEntry, Riemann}, function_entry::{FunctionEntry, Riemann},
math_app::AppSettings, math_app::AppSettings,
misc::{ misc::{EguiHelper, newtons_method, option_vec_printer, step_helper},
hashed_storage_create, hashed_storage_read, newtons_method, option_vec_printer,
step_helper, EguiHelper,
},
unicode_helper::{to_chars_array, to_unicode_hash}, unicode_helper::{to_chars_array, to_unicode_hash},
}; };

View File

@ -13,7 +13,6 @@ use egui_plot::Plot;
use emath::{Align, Align2}; use emath::{Align, Align2};
use epaint::Margin; use epaint::Margin;
use instant::Instant;
use itertools::Itertools; use itertools::Itertools;
use std::{io::Read, ops::BitXorAssign}; use std::{io::Read, ops::BitXorAssign};
@ -74,9 +73,6 @@ struct Opened {
/// Help window /// Help window
pub help: bool, pub help: bool,
/// Info window
pub info: bool,
/// Sidepanel /// Sidepanel
pub side_panel: bool, pub side_panel: bool,
@ -88,7 +84,6 @@ impl Default for Opened {
fn default() -> Opened { fn default() -> Opened {
Self { Self {
help: false, help: false,
info: false,
side_panel: true, side_panel: true,
welcome: true, welcome: true,
} }
@ -100,8 +95,8 @@ pub struct MathApp {
/// Stores vector of functions /// Stores vector of functions
functions: FunctionManager, functions: FunctionManager,
/// Contains the list of Areas calculated (the vector of f64) and time it took for the last frame (the Duration). Stored in a Tuple. /// Contains the list of Areas calculated
last_info: (Option<String>, Option<String>), areas: Option<String>,
/// Stores opened windows/elements for later reference /// Stores opened windows/elements for later reference
opened: Opened, opened: Opened,
@ -139,7 +134,6 @@ impl MathApp {
tracing::info!("Threading: Disabled"); tracing::info!("Threading: Disabled");
tracing::info!("Initializing..."); tracing::info!("Initializing...");
let start = Instant::now();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] { if #[cfg(target_arch = "wasm32")] {
@ -222,7 +216,7 @@ impl MathApp {
// Set spacing // Set spacing
// cc.egui_ctx.set_spacing(crate::style::SPACING); // cc.egui_ctx.set_spacing(crate::style::SPACING);
tracing::info!("Initialized! Took: {:?}", start.elapsed()); tracing::info!("Initialized!");
Self { Self {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -231,7 +225,7 @@ impl MathApp {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
functions: FunctionManager::default(), functions: FunctionManager::default(),
last_info: (None, None), areas: None,
opened: Opened::default(), opened: Opened::default(),
settings: AppSettings::default(), settings: AppSettings::default(),
} }
@ -354,9 +348,8 @@ impl MathApp {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ {
tracing::info!("Saving function data"); tracing::info!("Saving function data");
use crate::misc::hashed_storage_create;
let saved_data = hashed_storage_create( let saved_data = crate::misc::hashed_storage_create(
&bincode::serialize(&self.functions) &bincode::serialize(&self.functions)
.expect("unable to deserialize functions"), .expect("unable to deserialize functions"),
); );
@ -386,16 +379,6 @@ impl MathApp {
impl App for MathApp { impl App for MathApp {
/// Called each time the UI needs repainting. /// Called each time the UI needs repainting.
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
// start timer
let start = if self.opened.info {
Some(instant::Instant::now())
} else {
// if disabled, clear the stored formatted time
self.last_info.1 = None;
None
};
// If keyboard input isn't being grabbed, check for key combos // If keyboard input isn't being grabbed, check for key combos
if !ctx.wants_keyboard_input() { if !ctx.wants_keyboard_input() {
// If `H` key is pressed, toggle Side Panel // If `H` key is pressed, toggle Side Panel
@ -439,18 +422,8 @@ impl App for MathApp {
.clicked(), .clicked(),
); );
// Toggles opening the Info window
self.opened.info.bitxor_assign(
ui.add(Button::new("Info"))
.on_hover_text(match self.opened.info {
true => "Close Info Window",
false => "Open Info Window",
})
.clicked(),
);
// Display Area and time of last frame // Display Area and time of last frame
if let Some(ref area) = self.last_info.0 { if let Some(ref area) = self.areas {
ui.label(area); ui.label(area);
} }
}); });
@ -503,18 +476,6 @@ impl App for MathApp {
} }
} }
// Window with information about the build and current commit
Window::new("Info")
.open(&mut self.opened.info)
.default_pos([200.0, 200.0])
.resizable(false)
.collapsible(false)
.show(ctx, |ui| {
if let Some(ref took) = self.last_info.1 {
ui.label(took);
}
});
// If side panel is enabled, show it. // If side panel is enabled, show it.
if self.opened.side_panel { if self.opened.side_panel {
self.side_panel(ctx); self.side_panel(ctx);
@ -597,15 +558,12 @@ impl App for MathApp {
}) })
.collect(); .collect();
self.last_info.0 = if area.iter().any(|e| e.is_some()) { self.areas = if area.iter().any(|e| e.is_some()) {
Some(format!("Area: {}", option_vec_printer(area.as_slice()))) Some(format!("Area: {}", option_vec_printer(area.as_slice())))
} else { } else {
None None
}; };
}); });
}); });
// Calculate and store the last time it took to draw the frame
self.last_info.1 = start.map(|a| format!("Took: {}ms", a.elapsed().as_micros()));
} }
} }

View File

@ -1,5 +1,5 @@
use base64::engine::general_purpose;
use base64::Engine; use base64::Engine;
use base64::engine::general_purpose;
use egui_plot::{Line, PlotPoint, PlotPoints, Points}; use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2; use emath::Pos2;
use itertools::Itertools; use itertools::Itertools;