-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: Dom Container on scaled canvas #11400
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
Conversation
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.
Pull Request Overview
This PR fixes the incorrect positioning of DOM elements on a scaled canvas by incorporating a scale factor into the transform.
- Updated the transform style to combine translation and scaling
- Calculated the scale factor based on canvas CSS height, actual height, and renderer resolution
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
src/dom/DOMPipe.ts
Outdated
const scale = (parseFloat(canvas.style.height) / canvas.height) * this._renderer.resolution; | ||
|
||
// scale according to the canvas scale and translate | ||
this._domElement.style.transform = `translate(${canvas.offsetLeft}px, ${canvas.offsetTop}px) scale(${scale})`; |
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.
Do we not need to also check the width here?
const scaleX = (parseFloat(canvas.style.width) / canvas.width) * this._renderer.resolution;
const scaleY = (parseFloat(canvas.style.height) / canvas.height) * this._renderer.resolution;
// scale according to the canvas scale and translate
this._domElement.style.transform = `translate(${canvas.offsetLeft}px, ${canvas.offsetTop}px) scale(${scaleX}, ${scaleY})`;
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.
we 100% should !
Could we have a test for this? |
…ixijs into fix/dom-container-scale
…nvas scaling transformation
yes! test added 👍 |
It would be great if the Right now it's hardcoded to Suggested improvement: Current workaround: const domContainer = document.querySelector('div[style*="z-index: 1000"]');
if (domContainer) {
(domContainer as HTMLElement).style.zIndex = '10';
}
|
Description of change
This change fixes an issue in
DOMPipe
whereDOMContainer
elements would not be positioned correctly if the parent canvas element was scaled using CSS properties likewidth
orheight
.Previously, the container
div
for DOM elements was only translated based on the canvasoffsetLeft
andoffsetTop
. This fix introduces scaling to the containerdiv
's transform. The scale factor is calculated based on the ratio of the canvas's CSSstyle.height
to itscanvas.height
, multiplied by the renderer's resolution. This ensures that the DOM elements align correctly with the PixiJS scene, even when the canvas itself is scaled via CSS.Pre-Merge Checklist
npm run lint
)npm run test
)