From 60b81e714b51d310cb9e725bad9ea5a22d32d1d6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 1 Jul 2024 20:09:16 +0200 Subject: [PATCH] impr: Prevent canvas flickering in web build --- dist/web/source/wasm-config.js | 12 ++++-------- main/gui/source/window/web_window.cpp | 1 + main/gui/source/window/window.cpp | 3 ++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dist/web/source/wasm-config.js b/dist/web/source/wasm-config.js index 8da1a88e0..f57d9f5dc 100644 --- a/dist/web/source/wasm-config.js +++ b/dist/web/source/wasm-config.js @@ -144,14 +144,10 @@ if (urlParams.has("lang")) { window.addEventListener('resize', js_resizeCanvas, false); function js_resizeCanvas() { let canvas = document.getElementById('canvas'); + + + canvas.top = document.documentElement.clientTop; + canvas.left = document.documentElement.clientLeft; canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0); canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0); - - canvas.classList.add("canvas_full_screen") - - if (GLFW.active && GLFW.active.windowPosFunc) { - getWasmTableEntry(GLFW.active.windowPosFunc)(GLFW.active.id, GLFW.active.x, GLFW.active.y); - } - - GLFW.onWindowSizeChanged(); } \ No newline at end of file diff --git a/main/gui/source/window/web_window.cpp b/main/gui/source/window/web_window.cpp index 2dfa36ab3..ed16bc02b 100644 --- a/main/gui/source/window/web_window.cpp +++ b/main/gui/source/window/web_window.cpp @@ -87,6 +87,7 @@ namespace hex { glfwSetWindowRefreshCallback(m_window, [](GLFWwindow *window) { auto win = static_cast(glfwGetWindowUserPointer(window)); + resizeCanvas(); win->fullFrame(); }); diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 252d21d2e..f15247291 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -844,7 +844,8 @@ namespace hex { if (macosIsWindowBeingResizedByUser(window)) { ImGui::GetIO().MousePos = ImVec2(); } - #else + #elif defined(OS_WEB) + win->fullFrame(); #endif });