simplify a bunch of code
This commit is contained in:
parent
45f86d2c2d
commit
ba01a06359
@ -42,3 +42,4 @@ instant = { version = "0.1.12", features = ["wasm-bindgen"] }
|
|||||||
console_error_panic_hook = "0.1.7"
|
console_error_panic_hook = "0.1.7"
|
||||||
wee_alloc = "0.4.5"
|
wee_alloc = "0.4.5"
|
||||||
wasm-bindgen = { version = "0.2.79", default-features = false, features = ["std"] }
|
wasm-bindgen = { version = "0.2.79", default-features = false, features = ["std"] }
|
||||||
|
web-sys = "0.3.56"
|
||||||
@ -98,6 +98,17 @@ lazy_static::lazy_static! {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
|
use wasm_bindgen::JsCast;
|
||||||
|
fn stop_loading() {
|
||||||
|
let document = web_sys::window().unwrap().document().unwrap();
|
||||||
|
let loading_element = document.get_element_by_id("loading").unwrap().dyn_into::<web_sys::HtmlElement>().unwrap();
|
||||||
|
loading_element.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Used when displaying supported expressions in the Help window
|
// Used when displaying supported expressions in the Help window
|
||||||
const HELP_EXPR: &str = "- sqrt(x): square root of x
|
const HELP_EXPR: &str = "- sqrt(x): square root of x
|
||||||
- abs(x): absolute value of x
|
- abs(x): absolute value of x
|
||||||
@ -362,7 +373,10 @@ impl epi::App for MathApp {
|
|||||||
fn name(&self) -> &str { "(Yet-to-be-named) Graphing Software" }
|
fn name(&self) -> &str { "(Yet-to-be-named) Graphing Software" }
|
||||||
|
|
||||||
// Called once before the first frame.
|
// Called once before the first frame.
|
||||||
fn setup(&mut self, _ctx: &Context, _frame: &Frame, _storage: Option<&dyn Storage>) {}
|
fn setup(&mut self, _ctx: &Context, _frame: &Frame, _storage: Option<&dyn Storage>) {
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
stop_loading();
|
||||||
|
}
|
||||||
|
|
||||||
// Called each time the UI needs repainting, which may be many times per second.
|
// Called each time the UI needs repainting, which may be many times per second.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
@ -14,8 +14,8 @@ cfg_if::cfg_if! {
|
|||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen(start)]
|
||||||
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
|
pub fn start() -> Result<(), wasm_bindgen::JsValue> {
|
||||||
log_helper("Initializing...");
|
log_helper("Initializing...");
|
||||||
|
|
||||||
// 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
|
||||||
@ -27,7 +27,7 @@ cfg_if::cfg_if! {
|
|||||||
|
|
||||||
log_helper("Starting App...");
|
log_helper("Starting App...");
|
||||||
let app = egui_app::MathApp::default();
|
let app = egui_app::MathApp::default();
|
||||||
eframe::start_web(canvas_id, Box::new(app))
|
eframe::start_web("canvas", Box::new(app))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
await init();
|
await init();
|
||||||
document.getElementById("loading").remove();
|
|
||||||
start("canvas");
|
|
||||||
}
|
}
|
||||||
run();
|
run();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user