diff --git a/Cargo.toml b/Cargo.toml index 957da48..cd74433 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,15 +13,20 @@ opt-level = "z" #optimize for size lto = true strip = true +[profile.dev] +debug = true +codegen-units = 1 +opt-level = "z" #optimize for size +lto = true + [dependencies] meval = { git = "https://github.com/Titaniumtown/meval-rs.git" } -egui = { git = "https://github.com/Titaniumtown/egui", branch = "patch-1", default-features = false } eframe = { git = "https://github.com/Titaniumtown/egui", branch = "patch-1", default-features = false, features = ["egui_glow"] } instant = { version = "0.1.12", features = ["wasm-bindgen"] } git-version = "0.3.5" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.7" -tracing-wasm = "0.2.1" wee_alloc = "0.4.5" -wasm-bindgen = "0.2.79" +wasm-bindgen = { version = "0.2.79", default-features = false, features = ["std"] } +tracing-wasm = "0.2.1" diff --git a/src/egui_app.rs b/src/egui_app.rs index 27581ff..7f199a4 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -66,7 +66,6 @@ impl epi::App for MathApp { fn name(&self) -> &str { "Integral Demonstration" } // Called once before the first frame. - #[inline] fn setup( &mut self, _ctx: &egui::Context, _frame: &epi::Frame, _storage: Option<&dyn epi::Storage>, ) { @@ -78,6 +77,7 @@ impl epi::App for MathApp { // Note: This Instant implementation does not show microseconds when using wasm. let start = instant::Instant::now(); + // Reduce size of final binary by just including one font let mut fonts = egui::FontDefinitions::default(); fonts.font_data.insert( "Ubuntu-Light".to_owned(), @@ -114,7 +114,7 @@ impl epi::App for MathApp { egui::TopBottomPanel::top("top_bar").show(ctx, |ui| { ui.horizontal(|ui| { - if ui.add(egui::Button::new("Add function")).clicked() { + if ui.add(egui::Button::new("Add Function")).clicked() { // min_x and max_x will be updated later, doesn't matter here self.functions.push(Function::new( String::from(DEFAULT_FUNCION), @@ -139,7 +139,7 @@ impl epi::App for MathApp { egui::SidePanel::left("side_panel") .resizable(false) .show(ctx, |ui| { - ui.heading("Side Panel"); + // ui.heading("Side Panel"); let min_x_old = self.integral_min_x; let min_x_response = @@ -166,7 +166,7 @@ impl epi::App for MathApp { let mut integral_toggle: bool = false; ui.horizontal(|ui| { ui.label("Function: "); - if ui.add(Button::new("Toggle Integrals")).clicked() { + if ui.add(Button::new("Toggle Integral")).clicked() { integral_toggle = true; } ui.text_edit_singleline(&mut self.func_strs[i]); diff --git a/src/function.rs b/src/function.rs index 7516b7b..b97614b 100644 --- a/src/function.rs +++ b/src/function.rs @@ -1,5 +1,4 @@ -use egui::plot::Value; -use egui::widgets::plot::Bar; +use eframe::egui::{plot::Value, widgets::plot::Bar}; use meval::Expr; // Struct that stores and manages the output of a function @@ -109,7 +108,7 @@ impl Function { #[inline] fn run_func(&self, x: f64) -> f64 { (self.function)(x) } - #[inline] + #[inline(always)] pub fn update( &mut self, func_str: String, integral: bool, integral_min_x: Option, integral_max_x: Option, integral_num: Option, @@ -160,6 +159,7 @@ impl Function { } } + #[inline(always)] pub fn update_bounds(&mut self, min_x: f64, max_x: f64, pixel_width: usize) { if pixel_width != self.pixel_width { self.back_cache = None; diff --git a/src/lib.rs b/src/lib.rs index 28fae50..f93b40c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,15 +21,25 @@ extern "C" { fn log(s: &str); } +#[cfg(target_arch = "wasm32")] +#[cfg(debug_assertions)] +fn init_tracing_wasm() { + log("Initializing tracing_wasm..."); + tracing_wasm::set_as_global_default(); + log("Initialized tracing_wasm!"); +} + +#[cfg(target_arch = "wasm32")] +#[cfg(not(debug_assertions))] +fn init_tracing_wasm() { } + #[cfg(target_arch = "wasm32")] #[wasm_bindgen] pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { log("Initializing..."); // See performance in browser profiler! - log("Initializing tracing_wasm..."); - tracing_wasm::set_as_global_default(); - log("Initialized tracing_wasm!"); + init_tracing_wasm(); // Used in order to hook into `panic!()` to log in the browser's console log("Initializing console_error_panic_hook..."); diff --git a/src/main.rs b/src/main.rs index a8f225f..6dd3eba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ mod egui_app; - mod function; mod misc; diff --git a/start-server.sh b/start-server.sh index 9f7758e..4f6584e 100755 --- a/start-server.sh +++ b/start-server.sh @@ -1,6 +1,17 @@ #!/bin/bash set -e -bash build.sh +if test "$1" == "" || test "$1" == "release"; then + bash build.sh +elif test "$1" == "debug"; then + wasm-pack build --target web --debug --no-typescript + + rm -fr tmp | true #delete tmp folder if exists + mkdir tmp tmp/pkg + cp -r pkg/integral_site_bg.wasm pkg/integral_site.js tmp/pkg/ + cp www/index.html www/style.css tmp/ + + sed -i 's/\.\.\/pkg/\.\/pkg/g' tmp/index.html +fi basic-http-server tmp/ \ No newline at end of file