Skip to content

Commit

Permalink
fix: fixed restoring canvas when not generated after full screen set, c…
Browse files Browse the repository at this point in the history
…loses #4291
  • Loading branch information
matteobruni committed Jun 29, 2022
1 parent a51c6dd commit 28acc87
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions engine/src/Core/Canvas.ts
Expand Up @@ -85,6 +85,8 @@ export class Canvas {
destroy(): void {
if (this.generatedCanvas) {
this.element?.remove();
} else {
this.resetOriginalStyle();
}

this.draw((ctx) => {
Expand Down Expand Up @@ -390,8 +392,6 @@ export class Canvas {
return;
}

const originalStyle = this.originalStyle;

if (options.fullScreen.enable) {
this.originalStyle = deepExtend({}, element.style) as CSSStyleDeclaration;

Expand All @@ -401,13 +401,8 @@ export class Canvas {
element.style.setProperty("left", "0", "important");
element.style.setProperty("width", "100%", "important");
element.style.setProperty("height", "100%", "important");
} else if (originalStyle) {
element.style.position = originalStyle.position;
element.style.zIndex = originalStyle.zIndex;
element.style.top = originalStyle.top;
element.style.left = originalStyle.left;
element.style.width = originalStyle.width;
element.style.height = originalStyle.height;
} else {
this.resetOriginalStyle();
}

for (const key in options.style) {
Expand Down Expand Up @@ -447,4 +442,18 @@ export class Canvas {
paintBase(ctx, this.size, baseColor);
});
}

private resetOriginalStyle(): void {
const element = this.element,
originalStyle = this.originalStyle;

if (element && originalStyle) {
element.style.position = originalStyle.position;
element.style.zIndex = originalStyle.zIndex;
element.style.top = originalStyle.top;
element.style.left = originalStyle.left;
element.style.width = originalStyle.width;
element.style.height = originalStyle.height;
}
}
}

0 comments on commit 28acc87

Please sign in to comment.