From 5c38fe514fdf21eeddd3af4a5d6071197a9cc730 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 1 Mar 2022 00:36:13 -0500 Subject: [PATCH] UI improvements --- Cargo.toml | 1 + src/egui_app.rs | 4 ++-- src/function.rs | 20 ---------------- src/lib.rs | 13 +++++++--- www/index.html | 14 ++++++++++- www/style.css | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 378ebc1..e3c5b04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ meval = { git = "https://github.com/Titaniumtown/meval-rs.git" } eframe = { git = "https://github.com/Titaniumtown/egui", default-features = false, features = ["egui_glow"] } git-version = "0.3.5" include-flate = { git = "https://github.com/Titaniumtown/include-flate.git" } +web-sys = "0.3.56" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] instant = { version = "0.1.12" } diff --git a/src/egui_app.rs b/src/egui_app.rs index 068af84..8f9ce2d 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -241,8 +241,8 @@ impl epi::App for MathApp { Plot::new("plot") .set_margin_fraction(Vec2::ZERO) - .view_aspect(1.0) - .data_aspect(1.0) + // .view_aspect(1.0) + // .data_aspect(1.0) .include_y(0) .show(ui, |plot_ui| { let bounds = plot_ui.plot_bounds(); diff --git a/src/function.rs b/src/function.rs index 2f732e6..61063ab 100644 --- a/src/function.rs +++ b/src/function.rs @@ -23,26 +23,6 @@ pub struct Function { integral_num: usize, } -impl Clone for Function { - fn clone(&self) -> Self { - let expr: Expr = self.func_str.parse().unwrap(); - let func = expr.bind("x").unwrap(); - Self { - function: Box::new(func), - func_str: self.func_str.clone(), - min_x: self.min_x, - max_x: self.max_x, - pixel_width: self.pixel_width, - back_cache: self.back_cache.clone(), - front_cache: self.front_cache.clone(), - integral: self.integral, - integral_min_x: self.integral_min_x, - integral_max_x: self.integral_max_x, - integral_num: self.integral_num, - } - } -} - impl Function { pub fn new( func_str: String, min_x: f64, max_x: f64, pixel_width: usize, integral: bool, diff --git a/src/lib.rs b/src/lib.rs index 8045494..4c2171c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,9 +35,16 @@ pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { init_tracing_wasm(); // Used in order to hook into `panic!()` to log in the browser's console - log_helper("Initializing console_error_panic_hook..."); - std::panic::set_hook(Box::new(console_error_panic_hook::hook)); - log_helper("Initialized console_error_panic_hook!"); + log_helper("Initializing panic hooks..."); + std::panic::set_hook(Box::new(|panic_info| { + web_sys::window() + .and_then(|window| window.document()) + .and_then(|document| document.body()) + .and_then(|element| element.set_attribute("data-panicked", "true").ok()); + + console_error_panic_hook::hook(panic_info); + })); + log_helper("Initialized panic hooks!"); log_helper("Finished initializing!"); diff --git a/www/index.html b/www/index.html index d9d7daa..32ec492 100644 --- a/www/index.html +++ b/www/index.html @@ -7,17 +7,29 @@ Integral Demonstration - + +
+

application encountered a panic!

+
the application will no longer respond to user inputs
+
check the console for more information
+
+
+

+ Loading… +

+
+