Repository navigation
Conversation
dpi_scale was read once at startup, while gl.js sized the canvas and placed the pointer by the live ratio. Once the ratio changed, by zooming the page or moving its window to another display, the app's screen size in points and its mouse and touch positions were off by the change. The wasm side's resize now reads dpi_scale again. gl.js calls it when only the ratio changes, which zooming can do while keeping the canvas's size in pixels, and listens for the ratio changing without the window resizing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the web,
dpi_scalewas read once at startup, while gl.js sizes the canvas and places the mouse and touches by the livewindow.devicePixelRatio. Once the ratio changes in a running page, by zooming it or moving its window to a display with another scale, the two disagree:screen_width()andscreen_height()in points, andmouse_position()and touch positions, are off by the change. A board laid out fromscreen_width()is drawn bigger and off-centre, and clicks land elsewhere.resizeon the wasm side readsdpi_scale()again, so every resize brings the scale up to date.resizereports a change of ratio even when the canvas keeps its size in pixels, as zooming to 200% does when the canvas fills the window: half the CSS pixels at twice the ratio.(resolution: …dppx)media query, re-armed on each change.Checked with
cargo check --target wasm32-unknown-unknown. In headless Chromium, with an app that fits a board toscreen_width()andscreen_height()and reports where it put it: zooming a running page to 125% and 200% (chrome.tabs.setZoom) now puts the board exactly where a page loaded at that zoom puts it, and a click at a cell's middle reaches that cell. Before, at 125%, the board was 57% bigger and its left edge 68 CSS pixels further right. The same holds when Chrome DevTools' device emulation changes the ratio together with the page's size.