Skip to content

Commit 35c168f

Browse files
committed
ENH: added bounding box property to extract the w,h of rendered text
NB: Currently only works in pixels
1 parent 02571d0 commit 35c168f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

psychopy/visual/text.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,18 @@ def wrapWidth(self, wrapWidth):
522522
self.__dict__['wrapWidth'] = wrapWidth
523523
self._wrapWidthPix = convertToPix(pos = numpy.array([0, 0]), vertices=numpy.array([self.wrapWidth, 0]), units=self.units, win=self.win)[0]
524524
self._needSetText = True
525-
525+
526+
@property
527+
def boundingBox(self):
528+
"""(read only) attribute representing the bounding box of the text (w,h).
529+
This differs from `width` in that the width represents the width of the
530+
margins, which might differ from the width of the text within them
531+
532+
NOTE: currently always returns the size in pixels
533+
(this will change to return in stimulus units)
534+
"""
535+
return (self._pygletTextObj._layout.content_width, self._pygletTextObj._layout.content_height)
536+
526537
@property
527538
def posPix(self):
528539
"""This determines the coordinates in pixels of the position for the

0 commit comments

Comments
 (0)