summaryrefslogtreecommitdiff
path: root/wasp/draw565.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-12-28 14:29:09 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-12-29 08:59:48 (GMT)
commit314947278d88f2aae184bfd6f8e89a723ed4580b (patch)
treef9be63c6ddc68379e5bcaa52b6ad794dc9b3fc8a /wasp/draw565.py
parent01a7ad4d788bd7b26060081e896cb921e9b2689d (diff)
draw565: Allow strings to be right justified
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/draw565.py')
-rw-r--r--wasp/draw565.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/wasp/draw565.py b/wasp/draw565.py
index 842b533..111b2dc 100644
--- a/wasp/draw565.py
+++ b/wasp/draw565.py
@@ -279,7 +279,7 @@ class Draw565(object):
"""
self._font = font
- def string(self, s, x, y, width=None):
+ def string(self, s, x, y, width=None, right=False):
"""Draw a string at the supplied position.
:param s: String to render
@@ -291,6 +291,8 @@ class Draw565(object):
be filled with the background colour (to ensure that if
we update one string with a narrower one there is no
need to "undraw" it)
+ :param right: If True (and width is set) then right justify rather than
+ centre the text
"""
display = self._display
bgfg = self._bgfg
@@ -299,8 +301,12 @@ class Draw565(object):
if width:
(w, h) = _bounding_box(s, font)
- leftpad = (width - w) // 2
- rightpad = width - w - leftpad
+ if right:
+ leftpad = width - w
+ rightpad = 0
+ else:
+ leftpad = (width - w) // 2
+ rightpad = width - w - leftpad
self.fill(bg, x, y, leftpad, h)
x += leftpad