Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/windy/platforms/emscripten/emdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ proc emscripten_sleep*(ms: cuint) {.importc.}
#include <GLES2/gl2.h>

EM_JS(int, get_window_width, (), {
var canvas = (typeof Module !== 'undefined' && Module.canvas)
? Module.canvas
: document.getElementById('canvas');
if (canvas && canvas.clientWidth > 0) {
return canvas.clientWidth;
}
return window.innerWidth;
});

EM_JS(int, get_window_height, (), {
var canvas = (typeof Module !== 'undefined' && Module.canvas)
? Module.canvas
: document.getElementById('canvas');
if (canvas && canvas.clientHeight > 0) {
return canvas.clientHeight;
}
return window.innerHeight;
});

Expand All @@ -42,6 +54,15 @@ EM_JS(void, setup_windy_runtime, (), {
Module.canvas.windyContextHandlerAdded = true;
}

if (Module.canvas && !Module.canvas.windyResizeObserverAdded &&
typeof ResizeObserver !== 'undefined') {
var observer = new ResizeObserver(function() {
window.dispatchEvent(new Event('resize'));
});
observer.observe(Module.canvas);
Module.canvas.windyResizeObserverAdded = true;
}

if (!window.windyErrorHandlerAdded) {
window.addEventListener("error", function() {
console.info("Exception thrown, see JavaScript console");
Expand Down
Loading