-
Notifications
You must be signed in to change notification settings - Fork 362
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
64590d1
Broke Up create_text_sprite
626d6e0
Changed test
a75b059
Had to add create_text_texture to __all__
5988ef5
Fixed width and height bug.
b53e527
Small change
b062676
warning was breaking
fba6f40
Warning should be fixed
7e6b3ba
Update text.py
gran4 84428d5
Fix @eschan145 's review
b435284
Fix whitespaces in text
86fe78f
create_text_sprite
d973a41
//
f852ca5
..
1461dc5
hi
497ead5
changes as sugested
d37c3c6
..
eeb5f3d
small fixes
ae75931
.
gran4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,3 @@ def new_text(*args, **kwargs) -> None: | |
|
|
||
| window.flip() | ||
|
|
||
|
|
||
| # def test_create_text_sprite(window): | ||
| # pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import pytest | ||
| import arcade | ||
|
|
||
| def test_text_texture(window): | ||
| texture = arcade.create_text_texture("Hello World") | ||
| assert isinstance(texture, arcade.Texture) | ||
| assert texture.width == pytest.approx(80, rel=10) | ||
| assert texture.height == pytest.approx(20, rel=5) | ||
|
|
||
| def test_create(window): | ||
| def test_text_sprite(window): | ||
| sprite = arcade.create_text_sprite("Hello World") | ||
| assert isinstance(sprite, arcade.Sprite) | ||
| assert sprite.width == pytest.approx(75, rel=10) | ||
| assert sprite.width == pytest.approx(80, rel=10) | ||
| assert sprite.height == pytest.approx(20, rel=5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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/experimentaland that's mainly things not in the root.Uh oh!
There was an error while loading. Please reload this page.
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.