summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-02-16 17:04:13 -0500
committerLLLL Colonq <llll@colonq>2025-02-16 17:04:13 -0500
commitf7062b9a2cae6db9345d9f9d7ceebf5b441ddd3a (patch)
treebed9acea1f8760375544b0837af70a3140878245 /src
parent4603528c337edfa7821dbb31ade4d8dd63f9efb4 (diff)
Fix helpers.js handling
Diffstat (limited to 'src')
-rw-r--r--src/context.rs11
-rw-r--r--src/helpers.js13
2 files changed, 19 insertions, 5 deletions
diff --git a/src/context.rs b/src/context.rs
index 05d6990..502bbdb 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -1,10 +1,13 @@
use glow::HasContext;
#[cfg(target_arch = "wasm32")]
+use wasm_bindgen::prelude::*;
+
+#[cfg(target_arch = "wasm32")]
use winit::platform::web::WindowExtWebSys;
#[cfg(target_arch = "wasm32")]
-#[link(wasm_import_module = "./helpers.js")]
+#[wasm_bindgen(module = "/src/helpers.js")]
extern {
fn js_track_resized_setup();
fn js_poll_resized() -> bool;
@@ -69,7 +72,7 @@ impl Context {
};
#[cfg(target_arch = "wasm32")]
- unsafe { js_track_resized_setup(); }
+ js_track_resized_setup();
let ret = Self {
render_width, render_height,
@@ -126,9 +129,7 @@ impl Context {
#[cfg(target_arch = "wasm32")]
pub fn resize_necessary(&self) -> bool {
- unsafe {
- js_poll_resized()
- }
+ js_poll_resized()
}
#[cfg(not(target_arch = "wasm32"))]
diff --git a/src/helpers.js b/src/helpers.js
new file mode 100644
index 0000000..aaaafa1
--- /dev/null
+++ b/src/helpers.js
@@ -0,0 +1,13 @@
+let resized = false;
+
+export async function js_track_resized_setup() {
+ window.addEventListener("resize", () => {
+ resized = true;
+ });
+}
+
+export function js_poll_resized() {
+ let ret = resized;
+ resized = false;
+ return ret;
+}