arcade
arcade copied to clipboard
Text alignment issue in arcade 3
Bug Report
System Info
Arcade 3.0.0.dev24
------------------
vendor: Intel
renderer: Intel(R) UHD Graphics
version: (3, 3)
python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
platform: win32
pyglet version: 2.0.8
PIL version: 9.4.0
Actual behavior:
arcade.Text objects with align="center" are not center aligned (the multiline kwarg seems to also influence this; at least sometimes the text becomes aligned by setting multiline=True). It looks fine in arcade 2.6.17 but not in 3.0.0.dev24.
Expected behavior:
Text that was center aligned in 2.6.17 should still be in the same position when upgrading to arcade 3.0.0.
Steps to reproduce/example code:
Run this code with arcade==2.6.17 - the text is in the middle of the window. Run this code with arcade==3.0.0.dev24 - the text is off to the right.
import arcade
class IssueDemonstrationWindow(arcade.Window):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.text = arcade.Text(
text="MIDDLE",
start_x=400,
start_y=300,
font_size=72,
width=800,
anchor_x="center",
align="center",
)
self.set_viewport(
left=0,
right=800,
bottom=0,
top=600,
)
def on_draw(self):
self.text.draw_debug()
window = IssueDemonstrationWindow()
arcade.run()
It seems like the problem disappears if you remove the "width" argument.
The text fits into the box if you comment out anchor_x="center",
But, the box is not in the middle if you do that.
I think I found the issue. If you increase the width, it moves the text even more:
This is because line 1411 in layout.py in pyglet return self._x - width // 2
layout.TextLayout
inside DocumentLabel
inside pyglet.text.Label
P.S: I will make an issue in pyglet.
According to caffinepills, it is not a bug, it is intended.
Why did it change in arcade between 2.6.17 and 3? If this is due to a change in pyglet version, does that mean that pyglet intended for this to change?
I just tried arcade 2.6.17 with both pyglet 2.0.dev23 (which 2.6.17 uses) and 2.0.9 (which arcade 3 uses) and the text alignment problem does not occur.
It seems like arcade 2.6.17 had two lines in arcade.Text which set multiline=True if align != "left". These were removed, causing the issue.
This PR deleted those lines: https://github.com/pythonarcade/arcade/pull/1631/files#diff-9140ff68bfb252a17ae75c25ab36187e2b25beae54a64cfe4030d4e960ada6f9
Merge commit: https://github.com/pythonarcade/arcade/commit/e143b671398e22d5c8d981abb49c17b4776412cd#diff-9140ff68bfb252a17ae75c25ab36187e2b25beae54a64cfe4030d4e960ada6f9L193
Since the PR which deleted the lines was UI-related, does adding the lines back break anything UI-related?
Since the PR which deleted the lines was UI-related, does adding the lines back break anything UI-related?
It seems to have been related to this commit, look at the title of it: cc5b1b9fec138099dc190d69135bd853f024c5da
If the intention is to make arcade.Text have the same interface as pyglet text functionality, without any special multiline modification, I am fine with it as long as it happens as part of the major version bump to arcade 3. (I am a bit concerned about the fact that there seems to be little awareness of this change having happened.)
as long as it happens as part of the major version bump to arcade 3
As far as I understand, 2.6.X isn't expected to have any further updates.
Yeah, so whether to put those two lines back or not should be decided upon before the release of arcade 3.
Hi, I would like to revive this discussion and come to a fix.
From my point of view, from the UI I need to be able to have align="center" and multiline=False. (At least what I know right now, based on the fact, that a width is often given during the do_layout phase of the UI, but not during creation).
But I think I can use some workaround for that on the GUI side.
Which would lead to the question, if a dev sets multiline=False and align="center" does it make sense to just overwrite the multiline?
From the pyglet docs:
align: Horizontal alignment of text on a line, only applies if a width is supplied. One of `"left"`, `"center"` or `"right"`.
Which basically says that it would be fine to not set width and align!="left", it just has no effect until a width is set.
We changed the arcade.text code for 3.X. #2000 removes the mixed behaviour to:
align does not interfere with multiline (which was the case before)