arcade icon indicating copy to clipboard operation
arcade copied to clipboard

AssertionError: When the parameters 'multiline' and 'wrap_lines' are True, the parameter 'width' must be a number

Open alderven opened this issue 3 years ago • 6 comments

Run this code:

import arcade

arcade.open_window(800, 600, 'Hello')
arcade.draw_text(text='Привет!', start_x=400, start_y=300, font_size=36, align='center')
arcade.run()

Getting error:

Traceback (most recent call last):
  File "C:/draw_text.py", line 4, in <module>
    arcade.draw_text(text='Привет!', start_x=400, start_y=300, font_size=36, align='center')
  File "C:\Program Files\Python38\lib\site-packages\arcade\text_pyglet.py", line 138, in draw_text
    label = pyglet.text.Label(
  File "C:\Program Files\Python38\lib\site-packages\pyglet\text\__init__.py", line 447, in __init__
    super(Label, self).__init__(document, x, y, width, height,
  File "C:\Program Files\Python38\lib\site-packages\pyglet\text\__init__.py", line 268, in __init__
    super(DocumentLabel, self).__init__(document,
  File "C:\Program Files\Python38\lib\site-packages\pyglet\text\layout.py", line 889, in __init__
    self._wrap_lines_invariant()
  File "C:\Program Files\Python38\lib\site-packages\pyglet\text\layout.py", line 1155, in _wrap_lines_invariant
    assert not self._wrap_lines or self._width, \
AssertionError: When the parameters 'multiline' and 'wrap_lines' are True, the parameter 'width' must be a number.

Process finished with exit code 1

Note: Works OK on Arcade 2.5.7 or if I remove align='center'

Python: 3.8 Arcade: 2.6.0 OS: Win 10

alderven avatar Aug 31 '21 19:08 alderven

To align something, you need to add a width to align it against.

In this case an anchor is probably more in line with what you were wanting. Try adding anchor_x='center'.

caffeinepills avatar Aug 31 '21 19:08 caffeinepills

Hmm. Not sure if it's possible to make that compatible between versions.

einarf avatar Aug 31 '21 19:08 einarf

The 2.5.7 API can get the width of the text and auto-center it based on that field width. The new 2.6 API does not have that ability. The width has to be specified.

I don't think there's an ability to get the width of the field?

pvcraven avatar Sep 01 '21 13:09 pvcraven

There is label.content_width for pyglet labels, but again, align and anchor are two different things here. Align is for aligning based on the width of the document (which is set with the width keyword argument), while anchor is changing where the x, y is based on the width of the label. Changing his code to anchor_x anchors the text properly in the middle of the screen. If it was the reverse in the previous versions of Arcade, probably just need to change the align argument to go into the anchor_x parameter and vise versa.

caffeinepills avatar Sep 01 '21 14:09 caffeinepills

With 3.0 breaking backward compatibility and arcade.draw_text being discouraged. Should this issue be reviewed?

DragonMoffon avatar Aug 04 '23 07:08 DragonMoffon

This is still a problem in 3.0. Caching this error dislaying something that makes more sense for an arcade user would be great.

einarf avatar Jan 16 '24 18:01 einarf

The PR #2000 removes the interference of align with multiline. In this case it would no longer raise an Error.

It also checks if multiline is true and no width is given and gives a more clear error message.

eruvanos avatar Feb 27 '24 16:02 eruvanos