store formatted time

This commit is contained in:
Simon Gardling 2022-05-18 11:46:55 -04:00
parent 80b2c2c12d
commit 45c7fb47b7

View File

@ -10,7 +10,7 @@ use egui::{
}; };
use emath::{Align, Align2}; use emath::{Align, Align2};
use epaint::Rounding; use epaint::Rounding;
use instant::{Duration, Instant}; use instant::Instant;
use std::{io::Read, ops::BitXorAssign}; use std::{io::Read, ops::BitXorAssign};
#[cfg(threading)] #[cfg(threading)]
@ -91,7 +91,7 @@ pub struct MathApp {
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 (the vector of f64) and time it took for the last frame (the Duration). Stored in a Tuple.
last_info: (Vec<Option<f64>>, Option<Duration>), last_info: (Vec<Option<f64>>, Option<String>),
/// Whether or not dark mode is enabled /// Whether or not dark mode is enabled
dark_mode: bool, dark_mode: bool,
@ -381,6 +381,9 @@ impl App for MathApp {
let start = if self.opened.info { let start = if self.opened.info {
Some(instant::Instant::now()) Some(instant::Instant::now())
} else { } else {
// if disabled, clear the stored formatted time
self.last_info.1 = None;
None None
}; };
@ -510,8 +513,8 @@ impl App for MathApp {
.show(ctx, |ui| { .show(ctx, |ui| {
ui.add(egui::Label::new(&*BUILD_INFO)); ui.add(egui::Label::new(&*BUILD_INFO));
if let Some(took) = self.last_info.1 { if let Some(ref took) = self.last_info.1 {
ui.label(format!("Took: {:?}", took)); ui.label(took);
} }
}); });
@ -588,7 +591,7 @@ impl App for MathApp {
}); });
// Calculate and store the last time it took to draw the frame // Calculate and store the last time it took to draw the frame
self.last_info.1 = start.map(|a| a.elapsed()); self.last_info.1 = start.map(|a| format!("Took: {:?}", a.elapsed()));
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ {