Skip to content
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

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,8 @@ p5.Element.prototype.size = function (w, h) {
let aW = w;
let aH = h;
const AUTO = p5.prototype.AUTO;
let styleWidth= null;
let styleHeight = null;
if (aW !== AUTO || aH !== AUTO) {
if (aW === AUTO) {
aW = h * this.width / this.height;
Expand All @@ -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;
Copy link
Contributor

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.

this.elt.style.height = styleHeight;
this._pInst.scale(this._pInst._pixelDensity, this._pInst._pixelDensity);
for (prop in j) {
this.elt.getContext('2d')[prop] = j[prop];
}
} else {
styleWidth = aW + 'px';
styleHeight = aH + 'px';
this.elt.style.width = aW + 'px';
this.elt.style.height = aH + 'px';
this.elt.width = aW;
this.elt.height = aH;
}

this.width = this.elt.offsetWidth;
this.height = this.elt.offsetHeight;
this.elt.width = styleWidth; // Set elt.width to the recorded value
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

this.elt.height = styleHeight; // Set elt.height to the recorded value


this.width = aW;
this.height = aH;

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', aW);
this._pInst._setProperty('height', aH);
}
}
}
Expand Down