Skip to content

Commit c3b0269

Browse files
committed
Working. Anchor position still not working. possible related with current issue.
1 parent 54f3729 commit c3b0269

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Label(LabelBase):
7979
tab character
8080
:param str label_direction: string defining the label text orientation. There are 5
8181
configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left
82-
``TTB``-Top-To-Bottom ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``"""
82+
``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``"""
8383

8484
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
8585
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -106,6 +106,10 @@ def __init__(self, font, **kwargs) -> None:
106106

107107
self.color = kwargs.get("color", 0xFFFFFF)
108108
self.background_color = kwargs.get("background_color", None)
109+
self._label_direction = kwargs.get("label_direction", "LTR")
110+
111+
if self._label_direction == "RTL":
112+
self._text = "".join(reversed(self._text))
109113

110114
self.base_alignment = kwargs.get("base_alignment", False)
111115

@@ -127,26 +131,28 @@ def __init__(self, font, **kwargs) -> None:
127131
scale=kwargs.get("scale", 1),
128132
base_alignment=kwargs.get("base_alignment", False),
129133
tab_replacement=kwargs.get("tab_replacement", (4, " ")),
134+
label_direction=kwargs.get("label_direction", "LTR"),
130135
)
131136

132137
def _reset_text(
133-
self,
134-
font=None,
135-
x: int = None,
136-
y: int = None,
137-
text: str = None,
138-
line_spacing: float = None,
139-
background_tight: bool = None,
140-
padding_top: int = None,
141-
padding_bottom: int = None,
142-
padding_left: int = None,
143-
padding_right: int = None,
144-
anchor_point: Tuple[float, float] = None,
145-
anchored_position: Tuple[int, int] = None,
146-
save_text: bool = None,
147-
scale: int = None,
148-
base_alignment: bool = None,
149-
tab_replacement: Tuple[int, str] = None,
138+
self,
139+
font=None,
140+
x: int = None,
141+
y: int = None,
142+
text: str = None,
143+
line_spacing: float = None,
144+
background_tight: bool = None,
145+
padding_top: int = None,
146+
padding_bottom: int = None,
147+
padding_left: int = None,
148+
padding_right: int = None,
149+
anchor_point: Tuple[float, float] = None,
150+
anchored_position: Tuple[int, int] = None,
151+
save_text: bool = None,
152+
scale: int = None,
153+
base_alignment: bool = None,
154+
tab_replacement: Tuple[int, str] = None,
155+
label_direction: str = "LTR",
150156
) -> None:
151157

152158
# Store all the instance variables
@@ -178,13 +184,17 @@ def _reset_text(
178184
self.base_alignment = base_alignment
179185
if tab_replacement is not None:
180186
self._tab_replacement = tab_replacement
187+
if label_direction is not None:
188+
self._label_direction = label_direction
181189

182190
# if text is not provided as a parameter (text is None), use the previous value.
183191
if (text is None) and self._save_text:
184192
text = self._text
185193

186194
if self._save_text: # text string will be saved
187195
self._text = self._tab_text.join(text.split("\t"))
196+
if self._label_direction == "RTL":
197+
self._text = "".join(reversed(self._text))
188198
else:
189199
self._text = None # save a None value since text string is not saved
190200

@@ -266,6 +276,13 @@ def _reset_text(
266276
y=label_position_yoffset - y_offset - self._padding_top,
267277
)
268278

279+
if self._label_direction == "UPR":
280+
self.tilegrid.transpose_xy = True
281+
self.tilegrid.flip_x = True
282+
if self._label_direction == "DWR":
283+
self.tilegrid.transpose_xy = True
284+
self.tilegrid.flip_y = True
285+
269286
# Clear out any items in the local_group Group, in case this is an update to
270287
# the bitmap_label
271288
for _ in self.local_group:

0 commit comments

Comments
 (0)