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 1 commit
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
10 changes: 6 additions & 4 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 originalWidth = aW;
let originalHeight = aH;
if (aW !== AUTO || aH !== AUTO) {
if (aW === AUTO) {
aW = h * this.width / this.height;
Expand Down Expand Up @@ -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;
Copy link
Contributor

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?

Copy link
Contributor Author

@diyaayay diyaayay Nov 26, 2023

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.

Copy link
Contributor

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?

originalHeight = 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', originalWidth);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

this._pInst._setProperty('height', originalHeight);
}
}
}
Expand Down