Skip to content

Commit 62b3e82

Browse files
committed
gui: improve font change detection in text rendering
1 parent 911ccc1 commit 62b3e82

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

arcade/gui/widgets/text.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def __init__(
109109
width = self.ADAPTIVE_MULTILINE_WIDTH
110110
adaptive_multiline = True
111111

112+
# arcade.Text resolves the requested font name(s) to the concrete
113+
# loaded font, so the requested value has to be kept separately for
114+
# change detection in update_font
115+
self._requested_font_name = font_name
116+
112117
# Use Arcade Text wrapper of pyglet.Label for text rendering
113118
self._label = arcade.Text(
114119
x=0,
@@ -274,7 +279,7 @@ def update_font(
274279
(converts to ``"regular"``).
275280
italic: If enabled, the label's text will be in an *italic*
276281
"""
277-
font_name = font_name or self._label.font_name
282+
font_name = font_name or self._requested_font_name
278283
font_size = font_size or self._label.font_size
279284
font_color = font_color or self._label.color
280285
font_bold = bold if bold is not None else self._label.bold
@@ -283,8 +288,12 @@ def update_font(
283288
# ensure type of font_color, label will allways be a color
284289
font_color = Color.from_iterable(font_color)
285290

286-
# Check if values actually changed, if then update and trigger render
287-
font_name_changed = self._label.font_name != font_name
291+
# Check if values actually changed, if then update and trigger render.
292+
# The label holds the resolved font name (e.g. "arial" for
293+
# ("Kenney Future", "arial")), so the requested name has to be
294+
# compared against the previously requested one, otherwise this
295+
# would report a change on every call.
296+
font_name_changed = self._requested_font_name != font_name
288297
font_size_changed = self._label.font_size != font_size
289298
font_color_changed = self._label.color != font_color
290299
font_bold_changed = self._label.bold != font_bold
@@ -296,6 +305,7 @@ def update_font(
296305
or font_bold_changed
297306
or font_italic_changed
298307
):
308+
self._requested_font_name = font_name
299309
with self._label:
300310
self._label.font_name = font_name
301311
self._label.font_size = font_size

0 commit comments

Comments
 (0)