-
Notifications
You must be signed in to change notification settings - Fork 396
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
Unexpected Canvas Resize Behavior #41
Comments
If you'd like to see more resize options, please add a 👍 and respond with which behavior from above you're looking for. Hi Jack. Thanks for digging into this and for your careful consideration of the issue. Currently As for the other use cases, yeah, I can see people needing these. But I'd like to hear what they're trying to achieve before I start more features. Dealing with resizing was tricky. |
Thanks for your reply. Yeah, resizing is definitely a tricky thing. Expectations from developers could vary widely. I think I may not be seeing the same thing as you described. In test case 1, the canvas does not change size for me when resizing my browser. It stays at 480px × 280px. I'm attaching a GIF of the behavior I see here just to clarify. Do you get the same behavior? With your description, I would expect to see the canvas element expand to the full width of the browser while retaining a .zdog-canvas {
display: block;
width: 100%;
} I wonder if this might be an issue where the browser needs an extra frame to recalculate the DOM's representation? Kind of like how if you remove a CSS class and then add the CSS class back to the same element within the same frame of execution, you wouldn't see any change. |
Aaaaaah. There's a bug with high pixelRatio screens. Dang. Okay, I'll look into this. Thanks for reporting that. |
Oh ok, great to hear! I think fixing that should solve everything that was going through my head. There's no need to add extra complications since Feel free to close this once fixed, thanks! |
v1.0.2 has been released with fix for this bug Please update! Thanks again for reporting this issue. Closing as fixed. |
When setting
resize: true
on a canvas based illustration, it doesn't behave as I'd expect. For demos 1 and 2 below, I'd expect them to both have the same behavior. The SVG demo resizes proportionally, but the canvas demo stays locked at 480px×240px.Test Cases
1. Canvas Resize: https://codepen.io/desandro/pen/pmdqZv
2. SVG Resize: https://codepen.io/desandro/pen/wbPREZ
3. Fullscreen Canvas Resize: https://codepen.io/desandro/pen/dEJxaV
I realize that SVGs behave differently than canvases, since they retain their intrinsic proportions through their viewbox if explicit width/height is not defined, but that is not the case for canvas.
I'm not sure what the solution is here. I went down a few roads, but then realized that there might be a few different behaviors that people are trying to achieve. Perhaps it's one, or a combination of the following (don't mind the horrible names):
resize: false
Zdog does not attempt to resize the illustration. Currently Working
resize: 'fullscreen'
Zdog will resize the illustration to match the viewport width and height. Currently Working, demo 3 above
resize: 'fill-parent'
Zdog will resize the illustration to match the width and height of the element's parent.
resize: 'fill-parent-proportionally'
Zdog will resize the illustration to match the smallest dimension of the element's parent, while proportionally scaling the opposite axis. This means the initial aspect ratio will be retained, but will try to fill its container. Think
background-size: contain;
from CSS.resize: 'respect-natural-dom-size-and-css'
Zdog will resize the illustration based on the element's natural manifestation in the DOM, including any CSS applied. This would require Zdog to strip any explicit widths and heights from the element, take a natural measurement of the element in the DOM, then reapply those settings explicitly after the fact the keep the rendering working properly.
There may be more options, and maybe I'm looking into this a little too closely, but I think resize solutions like this would cover most use cases. At a minimum, I'd expect
resize: true
to have some effect on the canvas, but that's not currently the case.Any suggestions or guidance here?
P.S. - I'm loving Zdog, Dave, well done!
The text was updated successfully, but these errors were encountered: