Skip to content

Commit 3ce025a

Browse files
authored
Add .rect to Text (#2759)
* add .rect to Text * added comment from @pushfoo
1 parent 61248f2 commit 3ce025a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arcade/text.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from arcade.resources import resolve
1414
from arcade.texture_atlas import TextureAtlasBase
1515
from arcade.types import Color, Point, RGBOrA255
16+
from arcade.types.rect import LRBT, Rect
1617

1718
__all__ = ["load_font", "Text", "create_text_sprite", "draw_text"]
1819

@@ -578,6 +579,18 @@ def bottom(self) -> float:
578579
"""Pixel location of the bottom content border."""
579580
return self.label.bottom
580581

582+
@property
583+
def rect(self) -> Rect:
584+
"""Rect representing the bounds of the text.
585+
586+
.. tip:: Don't worry about `width` being `None`.
587+
588+
Although a label can be created with a `width=None`:
589+
* The underlying :py:mod:`pyglet` label will have bounding dimensions
590+
* This rect is for on-screen click and layout purposes, not maximum possible width
591+
"""
592+
return LRBT(self.left, self.right, self.bottom, self.top)
593+
581594
@property
582595
def content_size(self) -> tuple[int, int]:
583596
"""Get the pixel width and height of the text contents."""

0 commit comments

Comments
 (0)