Skip to content

Commit 622d227

Browse files
committed
Attach p5.Element methods to WebGL canvas
1 parent 7d77c13 commit 622d227

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ class RendererGL extends Renderer {
138138
this.elt.id = "defaultCanvas0";
139139
this.elt.classList.add("p5Canvas");
140140

141+
// Set and return p5.Element
142+
this.wrappedElt = new Element(this.elt, this._pInst);
143+
144+
// Extend renderer with methods of p5.Element with getters
145+
for (const p of Object.getOwnPropertyNames(Element.prototype)) {
146+
if (p !== 'constructor' && p[0] !== '_') {
147+
Object.defineProperty(this, p, {
148+
get() {
149+
return this.wrappedElt[p];
150+
}
151+
})
152+
}
153+
}
154+
141155
const dimensions = this._adjustDimensions(w, h);
142156
w = dimensions.adjustedWidth;
143157
h = dimensions.adjustedHeight;

0 commit comments

Comments
 (0)