Skip to content

Switch to offset_{width,height} when clearing web context#158

Merged
cmyr merged 1 commit intolinebender:masterfrom
elrnv:web-clear-fix
Mar 27, 2020
Merged

Switch to offset_{width,height} when clearing web context#158
cmyr merged 1 commit intolinebender:masterfrom
elrnv:web-clear-fix

Conversation

@elrnv
Copy link
Contributor

@elrnv elrnv commented Mar 27, 2020

This enables proper browser zooming through the dpi/devicePixelRatio mechanism.

For reference this addresses the zooming issue in druid wasm support found in the #759.

This enables proper browser zooming through the dpi/devicePixelRatio mechanism.
@elrnv elrnv changed the title Switch to offset_{width,height} when clearing context Switch to offset_{width,height} when clearing web context Mar 27, 2020
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

I am going to trust you on this one 😉

@cmyr cmyr merged commit 29b41d9 into linebender:master Mar 27, 2020
@elrnv
Copy link
Contributor Author

elrnv commented Mar 27, 2020

Sorry, I should have probably elaborated more. Maybe I can motivate this change for future reference:

  • Zooming in and out in the browser changes the reported devicePixelRatio (zooming in increases it, zooming out decreases it). This ratio is also used to handle screens with different DPI settings (e.g. retina displays have higher pixel ratio).
  • When zoom is changed, width & height on the canvas do not change (because of how we are setting up the context from druid, which follows the example from MDN). OTOH offset_width and offset_height decrease when zoomed in, and increase when zoomed out (these are read only properties so their behaviour should be consistent).
  • Zooming is achieved, by drawing to a smaller (when zoomed in) or larger (when zoomed out) context (with dimensions given by offset_{width,height}) and scaling it to fit the canvas, which is scaled by the device pixel ratio from the reported offset_{width,height}. This way we can change the size of all drawn things inside the context.
  • So to make zooming out work, we should expect the visible part of the context to have the size reported by offset_width and offset_height, which are guaranteed to be increased when the view is zoomed out since they are read-only.

I think this zooming mechanism is an appropriate initial solution. However, I can imagine that it may be preferable that the rendering of some widgets is tied to screen resolution, so probably this approach will be revisited in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants