File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,14 @@ def __init__(
87
87
size_hint_max = None ,
88
88
** kwargs ,
89
89
):
90
+ # If multiline is enabled and no width is given, we need to fit the
91
+ # size to the text. This is done by setting the width to a very
92
+ # large value and then fitting the size.
93
+ adaptive_multiline = False
94
+ if multiline and not width :
95
+ width = 999999
96
+ adaptive_multiline = True
97
+
90
98
# Use Arcade Text wrapper of pyglet.Label for text rendering
91
99
self .label = arcade .Text (
92
100
start_x = 0 ,
@@ -99,10 +107,13 @@ def __init__(
99
107
bold = bold ,
100
108
italic = italic ,
101
109
align = align ,
102
- anchor_y = "bottom" , # Position text bottom left to fit into scissor
103
- multiline = multiline , # area
110
+ anchor_y = "bottom" , # Position text bottom left to fit into scissor area
111
+ multiline = multiline ,
104
112
** kwargs ,
105
113
)
114
+ if adaptive_multiline :
115
+ # +1 is required to prevent line wrap
116
+ width = self .label .content_width + 1
106
117
107
118
super ().__init__ (
108
119
x = x ,
Original file line number Diff line number Diff line change @@ -56,3 +56,12 @@ def test_uilabel_fixes_internal_text_to_pos_0_0(window):
56
56
assert label .label .position == (0 , 0 )
57
57
assert label .position == (10 , 10 )
58
58
59
+ def test_adaptive_width_support_for_multiline_text (window ):
60
+ """
61
+ This test is a bit tricky. Enabling multiline without a width
62
+ should fit the size to the text. This is not natively supported by either arcade.Text or pyglet.Label.
63
+ Because text length variates between different os, we can only test boundaries, which indicate a proper implementation.
64
+ """
65
+ label = UILabel (text = "Multiline\n text\n which\n " , multiline = True )
66
+ assert label .width < 100
67
+ assert label .height > 20
You can’t perform that action at this time.
0 commit comments