Skip to content

Commit

Permalink
Attach p5.Element methods to WebGL canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
limzykenneth committed Feb 19, 2025
1 parent 7d77c13 commit 622d227
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ class RendererGL extends Renderer {
this.elt.id = "defaultCanvas0";
this.elt.classList.add("p5Canvas");

// Set and return p5.Element
this.wrappedElt = new Element(this.elt, this._pInst);

// Extend renderer with methods of p5.Element with getters
for (const p of Object.getOwnPropertyNames(Element.prototype)) {
if (p !== 'constructor' && p[0] !== '_') {
Object.defineProperty(this, p, {
get() {
return this.wrappedElt[p];
}
})
}
}

const dimensions = this._adjustDimensions(w, h);
w = dimensions.adjustedWidth;
h = dimensions.adjustedHeight;
Expand Down

0 comments on commit 622d227

Please sign in to comment.