From b1367403b7557502ec11e43b43b6419720e16d9a Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 11 Sep 2024 18:40:17 +0900 Subject: [PATCH] Fix badge width when invisble (#132) --- src/LGraphBadge.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/LGraphBadge.ts b/src/LGraphBadge.ts index 69cf337839..0d0c3b0a30 100644 --- a/src/LGraphBadge.ts +++ b/src/LGraphBadge.ts @@ -40,7 +40,13 @@ export class LGraphBadge { this.cornerRadius = cornerRadius; } + get visible() { + return this.text.length > 0; + } + getWidth(ctx: CanvasRenderingContext2D) { + if (!this.visible) return 0; + ctx.save(); ctx.font = `${this.fontSize}px sans-serif`; const textWidth = ctx.measureText(this.text).width; @@ -53,7 +59,7 @@ export class LGraphBadge { x: number, y: number, ): void { - if (!this.text) return; + if (!this.visible) return; ctx.save(); ctx.font = `${this.fontSize}px sans-serif`;