Absulit / Absulit/points

Support for high density monitors with devicePixelRatio

未关闭
#306 0 条评论 0 个 reaction 已指派 1 人 已被 @Absulit 认领 在 GitHub 查看
enhancement
主要语言
JavaScript
星标
56
派生
5
平均合并
2 分钟
30 天内合并 PR
1

描述

This is related to #299

Required for high density monitors and the HTML in Canvas to not look blurry, it needs to support the device pixel ratio

```js

const observer = new ResizeObserver(this.#resizeCanvasToFitWindow);

const supportsDevicePixelContentBox =
typeof ResizeObserverEntry !== 'undefined' &&
'devicePixelContentBoxSize' in ResizeObserverEntry.prototype;
const options = supportsDevicePixelContentBox ? { box: 'device-pixel-content-box', signal } : { signal };
observer.observe(this.#canvas, options);

#resizeCanvasToFitWindow = (entries) => {
// there are some calls of this function that do not have entries
// because of this, clientWidth and clientHeight values are used
const entry = entries?.[0];

this.#screenResized = true;
if (this.#fitWindow) {
const width = entry?.contentRect?.width || this.#canvas.clientWidth;
const height = entry?.contentRect?.height || this.#canvas.clientHeight;
const dpc = entry?.devicePixelContentBoxSize;
this.#canvas.width = dpc ? dpc[0].inlineSize : Math.round(width * window.devicePixelRatio);
this.#canvas.height = dpc ? dpc[0].blockSize : Math.round(height * window.devicePixelRatio);
this.#setScreenSize();
this.#frame()
}
}
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。