-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Changes from 2 commits
bd23a1e
4591002
fc90900
5b8914b
affe0be
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
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 | ||
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. I think this is setting the width/height to null in some cases. I think we can probably just use 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. @davepagurek I have made changes by removing |
||
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); | ||
} | ||
} | ||
} | ||
|
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
andstyleHeight
yet.