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",
]
[[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]]
name = "is-terminal"
version = "0.4.17"
@ -3997,7 +3985,6 @@ dependencies = [
"egui_plot",
"emath",
"epaint",
"instant",
"itertools 0.14.0",
"lol_alloc",
"parsing",

View File

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

View File

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

View File

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

View File

@ -13,7 +13,6 @@ use egui_plot::Plot;
use emath::{Align, Align2};
use epaint::Margin;
use instant::Instant;
use itertools::Itertools;
use std::{io::Read, ops::BitXorAssign};
@ -74,9 +73,6 @@ struct Opened {
/// Help window
pub help: bool,
/// Info window
pub info: bool,
/// Sidepanel
pub side_panel: bool,
@ -88,7 +84,6 @@ impl Default for Opened {
fn default() -> Opened {
Self {
help: false,
info: false,
side_panel: true,
welcome: true,
}
@ -100,8 +95,8 @@ pub struct MathApp {
/// Stores vector of functions
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.
last_info: (Option<String>, Option<String>),
/// Contains the list of Areas calculated
areas: Option<String>,
/// Stores opened windows/elements for later reference
opened: Opened,
@ -139,7 +134,6 @@ impl MathApp {
tracing::info!("Threading: Disabled");
tracing::info!("Initializing...");
let start = Instant::now();
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -222,7 +216,7 @@ impl MathApp {
// Set spacing
// cc.egui_ctx.set_spacing(crate::style::SPACING);
tracing::info!("Initialized! Took: {:?}", start.elapsed());
tracing::info!("Initialized!");
Self {
#[cfg(target_arch = "wasm32")]
@ -231,7 +225,7 @@ impl MathApp {
#[cfg(not(target_arch = "wasm32"))]
functions: FunctionManager::default(),
last_info: (None, None),
areas: None,
opened: Opened::default(),
settings: AppSettings::default(),
}
@ -354,9 +348,8 @@ impl MathApp {
#[cfg(target_arch = "wasm32")]
{
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)
.expect("unable to deserialize functions"),
);
@ -386,16 +379,6 @@ impl MathApp {
impl App for MathApp {
/// Called each time the UI needs repainting.
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 !ctx.wants_keyboard_input() {
// If `H` key is pressed, toggle Side Panel
@ -439,18 +422,8 @@ impl App for MathApp {
.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
if let Some(ref area) = self.last_info.0 {
if let Some(ref area) = self.areas {
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 self.opened.side_panel {
self.side_panel(ctx);
@ -597,15 +558,12 @@ impl App for MathApp {
})
.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())))
} else {
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::general_purpose;
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2;
use itertools::Itertools;