Skip to content

Commit

Permalink
fix bounds calculation with padding
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed May 1, 2024
1 parent 78824e4 commit e942b14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/scene/text/Text.ts
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions tests/renderering/text/Text.tests.ts
Expand Up @@ -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);
});
});

0 comments on commit e942b14

Please sign in to comment.