restructuring and better debug

This commit is contained in:
Simon Gardling
2022-02-28 10:04:22 -05:00
parent f5ce5b9f2f
commit 0520904e7e
6 changed files with 40 additions and 15 deletions

View File

@@ -13,15 +13,20 @@ opt-level = "z" #optimize for size
lto = true lto = true
strip = true strip = true
[profile.dev]
debug = true
codegen-units = 1
opt-level = "z" #optimize for size
lto = true
[dependencies] [dependencies]
meval = { git = "https://github.com/Titaniumtown/meval-rs.git" } 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"] } eframe = { git = "https://github.com/Titaniumtown/egui", branch = "patch-1", default-features = false, features = ["egui_glow"] }
instant = { version = "0.1.12", features = ["wasm-bindgen"] } instant = { version = "0.1.12", features = ["wasm-bindgen"] }
git-version = "0.3.5" git-version = "0.3.5"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"
tracing-wasm = "0.2.1"
wee_alloc = "0.4.5" 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"

View File

@@ -66,7 +66,6 @@ impl epi::App for MathApp {
fn name(&self) -> &str { "Integral Demonstration" } fn name(&self) -> &str { "Integral Demonstration" }
// Called once before the first frame. // Called once before the first frame.
#[inline]
fn setup( fn setup(
&mut self, _ctx: &egui::Context, _frame: &epi::Frame, _storage: Option<&dyn epi::Storage>, &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. // Note: This Instant implementation does not show microseconds when using wasm.
let start = instant::Instant::now(); let start = instant::Instant::now();
// Reduce size of final binary by just including one font
let mut fonts = egui::FontDefinitions::default(); let mut fonts = egui::FontDefinitions::default();
fonts.font_data.insert( fonts.font_data.insert(
"Ubuntu-Light".to_owned(), "Ubuntu-Light".to_owned(),
@@ -114,7 +114,7 @@ impl epi::App for MathApp {
egui::TopBottomPanel::top("top_bar").show(ctx, |ui| { egui::TopBottomPanel::top("top_bar").show(ctx, |ui| {
ui.horizontal(|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 // min_x and max_x will be updated later, doesn't matter here
self.functions.push(Function::new( self.functions.push(Function::new(
String::from(DEFAULT_FUNCION), String::from(DEFAULT_FUNCION),
@@ -139,7 +139,7 @@ impl epi::App for MathApp {
egui::SidePanel::left("side_panel") egui::SidePanel::left("side_panel")
.resizable(false) .resizable(false)
.show(ctx, |ui| { .show(ctx, |ui| {
ui.heading("Side Panel"); // ui.heading("Side Panel");
let min_x_old = self.integral_min_x; let min_x_old = self.integral_min_x;
let min_x_response = let min_x_response =
@@ -166,7 +166,7 @@ impl epi::App for MathApp {
let mut integral_toggle: bool = false; let mut integral_toggle: bool = false;
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Function: "); ui.label("Function: ");
if ui.add(Button::new("Toggle Integrals")).clicked() { if ui.add(Button::new("Toggle Integral")).clicked() {
integral_toggle = true; integral_toggle = true;
} }
ui.text_edit_singleline(&mut self.func_strs[i]); ui.text_edit_singleline(&mut self.func_strs[i]);

View File

@@ -1,5 +1,4 @@
use egui::plot::Value; use eframe::egui::{plot::Value, widgets::plot::Bar};
use egui::widgets::plot::Bar;
use meval::Expr; use meval::Expr;
// Struct that stores and manages the output of a function // Struct that stores and manages the output of a function
@@ -109,7 +108,7 @@ impl Function {
#[inline] #[inline]
fn run_func(&self, x: f64) -> f64 { (self.function)(x) } fn run_func(&self, x: f64) -> f64 { (self.function)(x) }
#[inline] #[inline(always)]
pub fn update( pub fn update(
&mut self, func_str: String, integral: bool, integral_min_x: Option<f64>, &mut self, func_str: String, integral: bool, integral_min_x: Option<f64>,
integral_max_x: Option<f64>, integral_num: Option<usize>, integral_max_x: Option<f64>, integral_num: Option<usize>,
@@ -160,6 +159,7 @@ impl Function {
} }
} }
#[inline(always)]
pub fn update_bounds(&mut self, min_x: f64, max_x: f64, pixel_width: usize) { pub fn update_bounds(&mut self, min_x: f64, max_x: f64, pixel_width: usize) {
if pixel_width != self.pixel_width { if pixel_width != self.pixel_width {
self.back_cache = None; self.back_cache = None;

View File

@@ -21,15 +21,25 @@ extern "C" {
fn log(s: &str); 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")] #[cfg(target_arch = "wasm32")]
#[wasm_bindgen] #[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
log("Initializing..."); log("Initializing...");
// See performance in browser profiler! // See performance in browser profiler!
log("Initializing tracing_wasm..."); init_tracing_wasm();
tracing_wasm::set_as_global_default();
log("Initialized tracing_wasm!");
// Used in order to hook into `panic!()` to log in the browser's console // Used in order to hook into `panic!()` to log in the browser's console
log("Initializing console_error_panic_hook..."); log("Initializing console_error_panic_hook...");

View File

@@ -1,5 +1,4 @@
mod egui_app; mod egui_app;
mod function; mod function;
mod misc; mod misc;

View File

@@ -1,6 +1,17 @@
#!/bin/bash #!/bin/bash
set -e 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/ basic-http-server tmp/