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
18 changes: 8 additions & 10 deletions src/windy/platforms/emscripten/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 =
Expand Down
Loading