-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Resizing the canvas using js/css now triggers the resize event #479
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,13 +420,14 @@ function _webglGet(name_, p, type) { | |
var Module; | ||
var wasm_exports; | ||
|
||
function resize(canvas, on_resize) { | ||
function resize(canvas, on_resize, force = false) { | ||
var dpr = dpi_scale(); | ||
var displayWidth = canvas.clientWidth * dpr; | ||
var displayHeight = canvas.clientHeight * dpr; | ||
|
||
if (canvas.width != displayWidth || | ||
canvas.height != displayHeight) { | ||
canvas.height != displayHeight || | ||
force) { | ||
canvas.width = displayWidth; | ||
canvas.height = displayHeight; | ||
if (on_resize != undefined) | ||
|
@@ -1263,6 +1264,9 @@ var importObject = { | |
wasm_exports.touch(SAPP_EVENTTYPE_TOUCHES_MOVED, touch.identifier, relative_position.x, relative_position.y); | ||
} | ||
}); | ||
new ResizeObserver(function (_entries) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we use both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes .... especially that simply removing the best solution I found was changing new ResizeObserver(() => {
let dpr = dpi_scale();
let displayWidth = Math.floor(canvas.clientWidth * dpr);
let displayHeight = Math.floor(canvas.clientHeight * dpr);
if (wasm_exports.resize)
wasm_exports.resize(displayWidth, displayHeight);
}).observe(canvas); and removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like yui-915/miniquad@53b457e4 |
||
resize(canvas, wasm_exports.resize, true); | ||
}).observe(canvas); | ||
|
||
window.onresize = function () { | ||
resize(canvas, wasm_exports.resize); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned about this
force
flag. Why do we need to send a resize message if size is still the same?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't looked at the code so I might be wrong
but perhaps it is a way to update the size if the CSS or similar changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am missing something, but I can't see how any sort of resize can be meaningful if canvas.width/height is still the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as my tests went
when forcing the canvas to be "fullscreen"
resizing the browser window will change
canvas.clientWidth
, but notcanvas.width
but when removing
width: 100%
andheight: 100%
from the canvas cssmanually updating the canvas width using js (for example by doing
canvas.width += 10;
)will change both
canvas.width
andcanvas.clientWidth
so the condition evaluates to false, and on_resize method doesn't get called
same applies for height