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 the problem of resetting HtmlCanvas.ClientXXX when call canvas.resizeByClientSize() #1982

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

Demo:

    <style>
      html,
      body,
      canvas {
        width: 100%;
        /* Deliberately not setting the height */
        /* height: 100%; */
        margin: 0;
        overflow: hidden;
        background: black;
        border: none;
      }
    </style>
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
console.log("before size", canvas.width, canvas.height);
console.log("before clientSize", canvas.clientWidth, canvas.clientHeight);
canvas.width = canvas.clientWidth * window.devicePixelRatio;
console.log("after size", canvas.width, canvas.height);
console.log("after clientSize", canvas.clientWidth, canvas.clientHeight);

output
image

@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Jan 22, 2024
@cptbtptpbcptdtptp cptbtptpbcptdtptp added bug Something isn't working medium priority Medium priority issue labels Jan 22, 2024
@cptbtptpbcptdtptp cptbtptpbcptdtptp added this to the 1.2 milestone Jan 22, 2024
const exportWidth = webCanvas.clientWidth * pixelRatio;
const exportHeight = webCanvas.clientHeight * pixelRatio;
this.width = exportWidth;
this.height = exportHeight;
Copy link
Member

Choose a reason for hiding this comment

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

why not just this.width = *

const exportWidth = webCanvas.clientWidth * pixelRatio;
const exportHeight = webCanvas.clientHeight * pixelRatio;
this.width = exportWidth;
this.height = exportHeight;
Copy link
Member

Choose a reason for hiding this comment

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

Write comments

@GuoLei1990 GuoLei1990 merged commit 516d4ae into galacean:dev/1.2 Jan 23, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working medium priority Medium priority issue
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants