diff --git a/src/scene/text/Text.ts b/src/scene/text/Text.ts index 0e302758ad..795f1a708a 100644 --- a/src/scene/text/Text.ts +++ b/src/scene/text/Text.ts @@ -64,8 +64,8 @@ export class Text const { width, height } = canvasMeasurement; bounds.minX = (-anchor._x * width) - padding; - bounds.maxX = bounds.minX + width; + bounds.maxX = bounds.minX + width + (padding * 2); bounds.minY = (-anchor._y * height) - padding; - bounds.maxY = bounds.minY + height; + bounds.maxY = bounds.minY + height + (padding * 2); } } diff --git a/tests/renderering/text/Text.tests.ts b/tests/renderering/text/Text.tests.ts index dc7be61123..c7b2260fd4 100644 --- a/tests/renderering/text/Text.tests.ts +++ b/tests/renderering/text/Text.tests.ts @@ -251,4 +251,16 @@ describe('Text', () => expect(text.height).toEqual(100); }); }); + + it('should measure bounds of text correctly when padding is set', () => + { + const textNoPadding = new Text({ text: 'HI', style: { padding: 0 } }); + const text = new Text({ text: 'HI', style: { padding: 10 } }); + + const boundsNoPadding = textNoPadding.getBounds(); + const bounds = text.getBounds(); + + expect(boundsNoPadding.width).toBeLessThan(bounds.width + 20); + expect(boundsNoPadding.height).toBeLessThan(bounds.height + 20); + }); });