diff --git a/src/windy/platforms/emscripten/platform.nim b/src/windy/platforms/emscripten/platform.nim index 0e09c4c..af72ed7 100644 --- a/src/windy/platforms/emscripten/platform.nim +++ b/src/windy/platforms/emscripten/platform.nim @@ -110,9 +110,10 @@ proc pollEvents*() = emscripten_sleep(0) proc size*(window: Window): IVec2 = - # Get the size of the canvas. - result.x = get_window_width() * get_device_pixel_ratio().int32 - result.y = get_window_height() * get_device_pixel_ratio().int32 + # Get the size of the canvas in physical pixels (CSS size × DPR). + let dpr = get_device_pixel_ratio() + result.x = (get_window_width().float32 * dpr).int32 + result.y = (get_window_height().float32 * dpr).int32 proc `size=`*(window: Window, size: IVec2) = ## Size cannot be set on emscripten windows. @@ -193,14 +194,11 @@ proc `focused=`*(window: Window, focused: bool) = discard # Focus is controlled by browser proc updateCanvasSize(window: Window) = - let - width = get_window_width().int32 - height = get_window_height().int32 - contentScale = get_device_pixel_ratio().float32 - size = ivec2(width, height) + ## Update canvas size to match window dimensions scaled by device pixel ratio. + let dpr = get_device_pixel_ratio() set_canvas_size( - (size.x.float32 * contentScale).int32, - (size.y.float32 * contentScale).int32 + (get_window_width().float32 * dpr).round().int32, + (get_window_height().float32 * dpr).round().int32 ) proc contentScale*(window: Window): float32 =