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

Fix: Preserve canvas position when calling noSmooth() in WEBGL #7568

Open
wants to merge 6 commits into
base: dev-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ class RendererGL extends Renderer {
pg.canvas = document.createElement("canvas");
const node = pg._pInst._userNode || document.body;
node.appendChild(pg.canvas);
p5.Element.call(pg, pg.canvas, pg._pInst);
Element.call(pg, pg.canvas, pg._pInst);
pg.width = w;
pg.height = h;
} else {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/webgl/test_noSmoothCanvasPosition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, it, expect } from 'vitest';

// Importing p5
import '../../../lib/p5.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this import is giving it trouble because lib is only built on release or when manually built.

Other test files tend to import p5 differently (see for example test/unit/webgl/RendererGL.js.) It might be easier (and maybe more organized too) to actually just put this test case into the existing RendererGL test file, as then you can just use the myp5 variable it has already imported and created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll move the test into p5.RendererGL.js and reuse the existing myp5 instance. Thanks for the suggestion!


describe('noSmooth() should preserve canvas position in WEBGL', () => {
it('should maintain the canvas position after calling noSmooth()', () => {

let myP5 = new window.p5((p) => {
p.setup = function () {
let cnv = p.createCanvas(300, 300, p.WEBGL);
cnv.position(150, 50);

const originalTop = cnv.elt.style.top;
const originalLeft = cnv.elt.style.left;

// Call noSmooth()
p.noSmooth();

// Checking if position remains or not
expect(cnv.elt.style.top).toBe(originalTop);
expect(cnv.elt.style.left).toBe(originalLeft);
};
});
});
});
Loading