Skip to content

Conversation

@gran4
Copy link
Contributor

@gran4 gran4 commented Apr 3, 2023

Fixed #1410

Help me fix multiline issue(everything but multiline works).

@einarf
Copy link
Member

einarf commented Apr 3, 2023

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?

@gran4
Copy link
Contributor Author

gran4 commented Apr 3, 2023

I had to add create_text_texture to all.

Grant Hur and others added 6 commits April 3, 2023 16:39
normal width and height is bugged on the label, have to use content_width and content_height
Add/Change comments on functions
@gran4
Copy link
Contributor Author

gran4 commented Apr 5, 2023

I think you guys can review. @einarf

@gran4
Copy link
Contributor Author

gran4 commented Apr 29, 2023

@einarf I think you can merge this. Is there any problem with it?

@einarf
Copy link
Member

einarf commented Apr 29, 2023

I will look at it when back from hospital unless someone else beats me to it. It might linger here for a while,

@einarf einarf added this to the Future milestone May 18, 2023
@einarf
Copy link
Member

einarf commented May 18, 2023

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.

@gran4
Copy link
Contributor Author

gran4 commented May 23, 2023

@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.

Copy link
Member

@pushfoo pushfoo left a 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.

image

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()

@gran4
Copy link
Contributor Author

gran4 commented May 26, 2023

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.

Working to fix it. Don't review yet. I don't know what the problem is.

@bunny-therapist
Copy link

To me, the fbo.clear((0, 0, 0, 255)) is causing the text to have a black box behind it. Should that really be there?

@pushfoo
Copy link
Member

pushfoo commented May 28, 2023

To me, the fbo.clear((0, 0, 0, 255)) is causing the text to have a black box behind it. Should that really be there?

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:

  1. add from arcade.color import TRANSPARENT_BLACK to the imports
  2. replace the tuple literal with TRANSPARENT_BLACK for clarity

@bunny-therapist
Copy link

fbo.clear((0,0,0,0)) works. I mean, it does not seem (to me) to make a difference adding it since the texture is already empty, so clearing it makes no difference, but it does not add a black box around the text.

@einarf einarf self-requested a review June 9, 2023 00:22
Comment on lines 1 to 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() No newline at end of file
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@gran4 gran4 Jun 10, 2023

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.

@gran4 gran4 changed the title Broke up create_text_sprite into 2 functions Broke up create_text_sprite into 2 functions [WIP] Jul 6, 2023
@gran4 gran4 changed the title Broke up create_text_sprite into 2 functions [WIP] Broke up create_text_sprite into 2 functions [WIP][HELP] Jul 13, 2023
@einarf
Copy link
Member

einarf commented Feb 18, 2024

Thanks again for the PR. Since it contains Hi.py and liely need some more tweaks I will close this for now and see what I can salvage from it.

@einarf einarf closed this Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Break up arcade.create_text_sprite into several useful functions

5 participants