Skip to content

Commit 3b2acb1

Browse files
authored
Merge pull request #2703 from pythonarcade/gui/fix-label-multiline-kerning-issues
fix label cut off text caused by multiline and kerning
2 parents 8a92d05 + db2c0e6 commit 3b2acb1

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
77

88
- Fixed an issue causing a crash when closing the window
99
- Added `Window.close` (bool) attribute indicating if the window is closed
10+
- GUI
11+
- Fix `UILabel` with enabled multiline sometimes cut off text
1012

1113
## Version 3.2
1214

arcade/gui/widgets/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def __init__(
126126
self._strong_background = True
127127

128128
if adaptive_multiline:
129-
# +1 is required to prevent line wrap
130-
width = self._label.content_width + 1
129+
# +1 is required to prevent line wrap, +1 is required to prevent issues with kerning
130+
width = self._label.content_width + 2
131131

132132
super().__init__(
133133
x=x,
@@ -242,7 +242,8 @@ def _update_label(self):
242242

243243
def _update_size_hint_min(self):
244244
"""Update the minimum size hint based on the label content size."""
245-
min_width = self._label.content_width + 1 # +1 required to prevent line wrap
245+
# +1 is required to prevent line wrap, +1 is required to prevent issues with kerning
246+
min_width = self._label.content_width + 2
246247
min_width += self._padding_left + self._padding_right + 2 * self._border_width
247248

248249
min_height = self._label.content_height

tests/unit/gui/test_uilabel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest.mock import Mock
22

3-
import pytest
43
from pyglet.math import Vec2
54

65
from arcade.gui import UILabel
@@ -192,7 +191,7 @@ def test_integration_with_layout_fit_to_content(ui):
192191
ui.execute_layout()
193192

194193
# auto size should fit the text
195-
assert label.rect.width == 44
194+
assert label.rect.width == 45
196195
assert label.rect.height == 12
197196

198197
# even when text changed
@@ -221,7 +220,7 @@ def test_fit_content_overrides_width(ui):
221220

222221
label.fit_content()
223222

224-
assert label.rect.width == 44
223+
assert label.rect.width == 45
225224
assert label.rect.height == 12
226225

227226

0 commit comments

Comments
 (0)