From b052cb001cf0237aa75629edf137a5fd3c9fafc7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 12 Jan 2026 22:53:51 +0100 Subject: [PATCH] web: Make sure canvas gets resized after the first frame --- main/gui/source/window/platform/web.cpp | 45 +++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/main/gui/source/window/platform/web.cpp b/main/gui/source/window/platform/web.cpp index 5fc4f63ca..03ae02f17 100644 --- a/main/gui/source/window/platform/web.cpp +++ b/main/gui/source/window/platform/web.cpp @@ -135,7 +135,30 @@ namespace hex { } void Window::beginNativeWindowFrame() { - static i32 prevWidth = 0; + + } + + void Window::endNativeWindowFrame() { + static float prevScaleFactor = 0; + + const float currScaleFactor = MAIN_THREAD_EM_ASM_DOUBLE({ + try { + return window.devicePixelRatio; + } catch (e) { + return 1.0; + } + }); + + if (prevScaleFactor != 0 && prevScaleFactor != currScaleFactor) { + EventDPIChanged::post(prevScaleFactor, currScaleFactor); + resizeCanvas(); + + ImHexApi::System::impl::setNativeScale(currScaleFactor); + + ThemeManager::reapplyCurrentTheme(); + } + + static i32 prevWidth = 0; static i32 prevHeight = 0; auto width = canvas_get_width(); @@ -149,26 +172,6 @@ namespace hex { this->resize(width, height); resizeCanvas(); } - } - - void Window::endNativeWindowFrame() { - static float prevScaleFactor = 0; - - const float currScaleFactor = MAIN_THREAD_EM_ASM_DOUBLE({ - try { - return window.devicePixelRatio; - } catch (e) { - return 1.0; - } - }); - if (prevScaleFactor != 0 && prevScaleFactor != currScaleFactor) { - EventDPIChanged::post(prevScaleFactor, currScaleFactor); - resizeCanvas(); - - ImHexApi::System::impl::setNativeScale(currScaleFactor); - - ThemeManager::reapplyCurrentTheme(); - } prevScaleFactor = currScaleFactor; }