Skip to content

Commit 03dd20c

Browse files
committed
web: Fix canvas size issues when zooming page
1 parent 712a125 commit 03dd20c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

dist/web/source/wasm-config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ window.addEventListener('resize', js_resizeCanvas, false);
271271
function js_resizeCanvas() {
272272
let canvas = document.getElementById('canvas');
273273

274-
canvas.top = document.documentElement.clientTop;
275-
canvas.left = document.documentElement.clientLeft;
274+
canvas.top = canvas.parentElement.clientTop;
275+
canvas.left = canvas.parentElement.clientLeft;
276276

277-
let width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0);
278-
let height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0);
277+
let width = Math.min(canvas.parentElement.clientWidth, window.innerWidth || 0);
278+
let height = Math.min(canvas.parentElement.clientHeight, window.innerHeight || 0);
279279

280280
canvas.style.width = width + "px";
281281
canvas.style.height = height + "px";

main/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if (EMSCRIPTEN)
4545
target_link_options(main PRIVATE -sEXPORTED_RUNTIME_METHODS=ccall)
4646
target_link_options(main PRIVATE -sFETCH)
4747
target_link_options(main PRIVATE -sASSERTIONS)
48+
target_link_options(main PRIVATE -sNO_DISABLE_EXCEPTION_CATCHING)
4849
target_link_options(main PRIVATE -sWASM_BIGINT)
4950
target_link_options(main PRIVATE -O2)
5051
target_link_options(main PRIVATE -fsanitize=null)

main/gui/source/window/platform/web.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ namespace hex {
147147
prevWidth = width;
148148
prevHeight = height;
149149
this->resize(width, height);
150+
resizeCanvas();
150151
}
151152
}
152153

@@ -167,7 +168,7 @@ namespace hex {
167168
ImHexApi::System::impl::setNativeScale(currScaleFactor);
168169

169170
ThemeManager::reapplyCurrentTheme();
170-
ImGui::GetStyle().ScaleAllSizes(currScaleFactor);
171+
ImGui::GetStyle().ScaleAllSizes(currScaleFactor / prevScaleFactor);
171172
}
172173

173174
prevScaleFactor = currScaleFactor;

0 commit comments

Comments
 (0)