Skip to content

Fix HiDPI vs. set_cursor_icon for web #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2020

Conversation

michaelkirk
Copy link
Contributor

@michaelkirk michaelkirk commented Aug 14, 2020

PhysicalSize is recorded as canvas.size, whereas LogicalSize is stored
as canvas.style.size.

The previous cursor behavior on stdweb clobbered all style - thus losing
the LogicalSize.

  • Tested on all platforms changed (tested with stdweb and web_sys example here: https://github.com/michaelkirk/winit_example)
  • Compilation warnings were addressed (removed some "unused import" warning that predate my change)
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • [] Created or updated an example program if it would help users understand this functionality
  • [] Updated feature matrix, if new features were added or implemented

Here are some before/after screencasts from the app where I encountered this bug. It's hard to make sense of looping GIFs - the video starts when my cursor is on the right DOM-inspector pane, then the canvas is made much larger as my mouse enters the canvas because our app sets the cursor icon (to "auto" so it's an invisible cursor change, but enough to trigger the bug).

You can see that as soon as we edit the cursor, we lose the style info for the canvas, thus lose it's "logical" sizing, relying on the "physical" sizing.

before
before mov

after
after mov

PhysicalSize is recorded as canvas.size, whereas LogicalSize is stored
as canvas.style.size.

The previous cursor behavior on stdweb clobbered all style - thus losing
the LogicalSize.
@michaelkirk michaelkirk changed the title Fix HiDPI vs. set_cursor_icon Fix HiDPI vs. set_cursor_icon for web Aug 14, 2020
@@ -165,8 +165,7 @@ impl Window {
CursorIcon::RowResize => "row-resize",
};
*self.previous_pointer.borrow_mut() = text;
self.canvas
.set_attribute("style", &format!("cursor: {}", text));
backend::set_canvas_style_property(self.canvas.raw(), "cursor", text);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the bug - clobbering everything in style.

Copy link
Contributor

@ryanisaacg ryanisaacg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@ryanisaacg ryanisaacg merged commit 9c72cc2 into rust-windowing:master Aug 17, 2020
michaelkirk added a commit to michaelkirk/abstreet that referenced this pull request Sep 6, 2020
Bug fixes we want merged since 0.22.2:
  - web: DPI vs. custom cursor icon: rust-windowing/winit#1652
  - web: v-scroll inverted rust-windowing/winit#1665
  - mac: h-scroll inverted rust-windowing/winit#1696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants