-
Notifications
You must be signed in to change notification settings - Fork 363
Broke up create_text_sprite into 2 functions [WIP][HELP] #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was some challenges related to implementing these changes I can't remember at the moment. Will have to look closer at this one. Also: Seems your unit tests are failing. Did you run them locally before pushing? |
|
I had to add create_text_texture to all. |
normal width and height is bugged on the label, have to use content_width and content_height
Add/Change comments on functions
|
I think you guys can review. @einarf |
|
@einarf I think you can merge this. Is there any problem with it? |
|
I will look at it when back from hospital unless someone else beats me to it. It might linger here for a while, |
|
I'm wondering if we should try delay this feature after 3.0.0 when other related systems are in better shape. When I tested this last time there was some text getting cutt off as well in certain enviroments. Either afer 3.0.0 or closer to release. |
|
@einarf It doesn't really deal with any of the lower level stuff. All it is suppose to do is allow you to get the texture in certain use cases like issue #1410. If the text was cut off, it is either a problem with the existing code, or something I changed here. I do not think the other systems are relevant in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not missing something, it looks like multiline doesn't work. Either something is wrong, or it's a limitation the doc needs to be clear about.
import arcade
class UsageAttempt(arcade.Window):
def __init__(self, width: int = 320, height: int = 240):
super().__init__(width=width, height=height)
self.sprites = arcade.SpriteList()
text_sprite = arcade.create_text_sprite(
"First line\nsecond line",
multiline=True,
width=200,
)
text_sprite.position = self.width // 2, self.height // 2
self.sprites.append(text_sprite)
def on_draw(self):
self.clear()
self.sprites.draw()
if __name__ == "__main__":
w = UsageAttempt()
arcade.run()
Working to fix it. Don't review yet. I don't know what the problem is. |
|
To me, the |
Please try swapping the 255 for a 0 if you have time. I need to look at some other PRs right now, and your help would be appreciated. If replacing it works, the following steps would probably work improve the clarity of the code in addition to fixing the issue:
|
|
|
| import arcade, pyglet | ||
|
|
||
| def _attempt_font_name_resolution(font_name): | ||
| """ | ||
| Attempt to resolve a tuple of font names. | ||
| Preserves the original logic of this section, even though it | ||
| doesn't seem to make sense entirely. Comments are an attempt | ||
| to make sense of the original code. | ||
| If it can't resolve a definite path, it will return the original | ||
| argument for pyglet to attempt to resolve. This is consistent with | ||
| the original behavior of this code before it was encapsulated. | ||
| :param Union[str, Tuple[str, ...]] font_name: | ||
| :return: Either a resolved path or the original tuple | ||
| """ | ||
| if font_name: | ||
|
|
||
| # ensure | ||
| if isinstance(font_name, str): | ||
| font_list: Tuple[str, ...] = (font_name,) | ||
| elif isinstance(font_name, tuple): | ||
| font_list = font_name | ||
| else: | ||
| raise TypeError("font_name parameter must be a string, or a tuple of strings that specify a font name.") | ||
|
|
||
| for font in font_list: | ||
| try: | ||
| path = resolve(font) | ||
| # print(f"Font path: {path=}") | ||
|
|
||
| # found a font successfully! | ||
| return path.name | ||
|
|
||
| except FileNotFoundError: | ||
| pass | ||
|
|
||
| # failed to find it ourselves, hope pyglet can make sense of it | ||
| return font_name | ||
|
|
||
|
|
||
| class UsageAttempt(arcade.Window): | ||
|
|
||
| def __init__(self, width: int = 320, height: int = 240): | ||
| super().__init__(width=width, height=height) | ||
|
|
||
| self.sprites = arcade.SpriteList() | ||
| text_sprite = arcade.create_text_sprite( | ||
| "First line\nsecond line", | ||
| multiline=True, | ||
| width=200, | ||
| ) | ||
| text_sprite.position = self.width // 2, self.height // 2 | ||
| self.sprites.append(text_sprite) | ||
|
|
||
| self._label = pyglet.text.Label( | ||
| text="First line\nsecond line\nTHIRD NIGER", | ||
| x = 200, | ||
| y = 200, | ||
| font_name="Arial", | ||
| font_size=12, | ||
| anchor_x="left", | ||
| width=100, | ||
| align="baseline", | ||
| bold=True, | ||
| italic=True, | ||
| multiline=True, | ||
| ) | ||
|
|
||
| def on_draw(self): | ||
| self.clear() | ||
| self.sprites.draw() | ||
|
|
||
| window = arcade.get_window() | ||
| with window.ctx.pyglet_rendering(): | ||
| self._label.draw() | ||
|
|
||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| w = UsageAttempt() | ||
| arcade.run() No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should definitely not be in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only really allow test scripts in places like arcade/experimental and that's mainly things not in the root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already know. It is a test file to test the dev version. I will remove the file right before it is merged. Before that happens, the multiline must be fixed. I do not know the problem still.
|
Thanks again for the PR. Since it contains |

Fixed #1410
Help me fix multiline issue(everything but multiline works).