Fix badge width when invisble (#132)

This commit is contained in:
Chenlei Hu
2024-09-11 18:40:17 +09:00
committed by GitHub
parent 87ec5cc104
commit b1367403b7

View File

@@ -40,7 +40,13 @@ export class LGraphBadge {
this.cornerRadius = cornerRadius; this.cornerRadius = cornerRadius;
} }
get visible() {
return this.text.length > 0;
}
getWidth(ctx: CanvasRenderingContext2D) { getWidth(ctx: CanvasRenderingContext2D) {
if (!this.visible) return 0;
ctx.save(); ctx.save();
ctx.font = `${this.fontSize}px sans-serif`; ctx.font = `${this.fontSize}px sans-serif`;
const textWidth = ctx.measureText(this.text).width; const textWidth = ctx.measureText(this.text).width;
@@ -53,7 +59,7 @@ export class LGraphBadge {
x: number, x: number,
y: number, y: number,
): void { ): void {
if (!this.text) return; if (!this.visible) return;
ctx.save(); ctx.save();
ctx.font = `${this.fontSize}px sans-serif`; ctx.font = `${this.fontSize}px sans-serif`;