Skip to content

Make default sketch canvas ID autoincrement #7836

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

Open
wants to merge 1 commit into
base: dev-2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ class p5 {
// This is a pointer to our global mode p5 instance, if we're in
// global mode.
static instance = null;
static sketchCount = 0;
static lifecycleHooks = {
presetup: [],
postsetup: [],
6 changes: 3 additions & 3 deletions src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ import FilterRenderer2D from '../image/filterRenderer2D';
import { Matrix } from '../math/p5.Matrix';
import { PrimitiveToPath2DConverter } from '../shape/custom_shapes';


const styleEmpty = 'rgba(0,0,0,0)';
// const alphaThreshold = 0.00125; // minimum visible

class Renderer2D extends Renderer {
constructor(pInst, w, h, isMainCanvas, elt, attributes = {}) {
@@ -29,7 +27,9 @@ class Renderer2D extends Renderer {
this.canvas.style.display = 'none';
}

this.elt.id = 'defaultCanvas0';
if(!this.elt.id){
this.elt.id = `defaultCanvas${p5.sketchCount++}`;
}
this.elt.classList.add('p5Canvas');

// Extend renderer with methods of p5.Element with getters
5 changes: 4 additions & 1 deletion src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
@@ -136,7 +136,10 @@ class RendererGL extends Renderer {
// hide if offscreen buffer by default
this.canvas.style.display = "none";
}
this.elt.id = "defaultCanvas0";

if(!this.elt.id){
this.elt.id = `defaultCanvas${p5.sketchCount++}`;
}
this.elt.classList.add("p5Canvas");

// Set and return p5.Element
Loading
Oops, something went wrong.