Skip to content

Commit c3629f0

Browse files
authored
Merge pull request #37 from mdroberts1243/master
Add rotation logic to text() method
2 parents 9113290 + e821086 commit c3629f0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_framebuf.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
403403
404404
Does not break on line going off screen.
405405
"""
406+
# determine our effective width/height, taking rotation into account
407+
frame_width = self.width
408+
frame_height = self.height
409+
if self.rotation == 1 or self.rotation == 3:
410+
frame_width, frame_height = frame_height, frame_width
411+
406412
for chunk in string.split("\n"):
407413
if not self._font or self._font.font_name != font_name:
408414
# load the font!
@@ -413,9 +419,9 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
413419
char_x = x + (i * (width + 1)) * size
414420
if (
415421
char_x + (width * size) > 0
416-
and char_x < self.width
422+
and char_x < frame_width
417423
and y + (height * size) > 0
418-
and y < self.height
424+
and y < frame_height
419425
):
420426
self._font.draw_char(char, char_x, y, self, color, size=size)
421427
y += height * size

0 commit comments

Comments
 (0)