-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Stores the width and height values before any adjustments are made, Solves #6581 #6588
Conversation
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.
Thanks for taking this on, this looks like the right approach! I just have a few questions on the implementation.
src/dom/dom.js
Outdated
@@ -3283,14 +3285,14 @@ p5.Element.prototype.size = function (w, h) { | |||
this.elt.height = aH; | |||
} | |||
|
|||
this.width = this.elt.offsetWidth; | |||
this.height = this.elt.offsetHeight; | |||
originalWidth = aW; |
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.
It looks like we don't set this.width
or this.height
any more here, was that on purpose?
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 looked into my approach again and tried changing it to:
this.elt.width = aW;
this.elt.height = aH;
this._pInst._setProperty('width', aW);
this._pInst._setProperty('height', aH);
still doesn't work though, I'm kind of stuck now.
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.
Do you need to also set this.width = aW
and this.height = aH
?
src/dom/dom.js
Outdated
|
||
if (this._pInst && this._pInst._curElement) { | ||
// main canvas associated with p5 instance | ||
if (this._pInst._curElement.elt === this.elt) { | ||
this._pInst._setProperty('width', this.elt.offsetWidth); | ||
this._pInst._setProperty('height', this.elt.offsetHeight); | ||
this._pInst._setProperty('width', originalWidth); |
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.
Is there a reason for having originalWidth/Height
as separate variables, or can we simplify this a bit and just use aW
and aH
here?
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.
Ah yes! I realised it later that aW
and aH
can be used instead of originalWidth/Height
.
src/dom/dom.js
Outdated
@@ -3272,25 +3274,31 @@ p5.Element.prototype.size = function (w, h) { | |||
this.elt.setAttribute('height', aH * this._pInst._pixelDensity); | |||
this.elt.style.width = aW + 'px'; | |||
this.elt.style.height = aH + 'px'; | |||
this.elt.style.width = styleWidth; |
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.
This might be resetting the width/height to null here, since in this branch, nothing has assigned styleWidth
and styleHeight
yet.
src/dom/dom.js
Outdated
} | ||
|
||
this.width = this.elt.offsetWidth; | ||
this.height = this.elt.offsetHeight; | ||
this.elt.width = styleWidth; // Set elt.width to the recorded value |
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 think this is setting the width/height to null in some cases. I think we can probably just use aW
and aH
instead of styleHeight
since that is defined everywhere
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 suspect that's the cause of the error I get when trying it out: https://editor.p5js.org/davepagurek/sketches/UX8Yk9fnr
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.
@davepagurek I have made changes by removing styleWidth
and styleHeight
due to the error, opting to use aW
and aH
instead. While finding the solutions, I came across two potential solutions. The first involves making minor adjustments in the sketch.js file, which isn't the preferred route. The second option is to modify the size function which is what I've been doing. However, I am unsure if I am on the right track with the latter. Am I?
I updated the build in the p5 editor link and it seems to work now, thanks for making the changes! |
Resolves #6581
Changes:
In this modification, I added
originalWidth
andoriginalHeight
variables to store the width and height values before any adjustments are made. Later in the function, when setting the canvas width and height, I use these original values to update the canvas dimensions. This prevents the issue where the width and height are evaluated as 0 when the element is hidden. The snippet works just fine after the change.Snippet:
PR Checklist
npm run lint
passes