Skip to content
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

UIWrappedText: Fix single-character strings not being rendered #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caoimhebyrne
Copy link
Member

By default, UIWrappedText will set its width to the width of the text string. When it is rendering the text, it'll check if the width of the component is less than or equal to the width of a character (in this case 'x'), this is flawed for a few reasons:

  1. Different characters have different widths
  2. The comment "if we are smaller than a character" doesn't match up with the behavior (less than or equal to)
  3. UGraphics.getCharWidth (used to get the width of 'x') does not take the fontProvider into account, meaning that the width that it calculates for that character could be wrong.

To solve this, the check has been removed, as it is flawed and doesn't seem to have an explicit error, contrary to what the comment in the code said.

The only problem found with this was that getStringSplitToWidth would push an extra line onto the list if the container wasn't long enough to render one character. This has been fixed by adding a isNotEmpty check before pushing the line (that's okay to do in this case, as it's not a newline check).

The only "breaking change" about this, is that if your container is less than "a character" wide, they will still render. If you for some reason want to avoid this, put a ScissorEffect onto your UIWrappedText, but this shouldn't really be necessary.

By default, UIWrappedText will set its width to the width of the text
string. When it is rendering the text, it'll check if the width of the
component is less than or equal to the width of a character (in this
case 'x'), this is flawed for a few reasons:
1. Different characters have different widths
2. The comment "if we are smaller than a character" doesn't match up
   with the behavior (less than or equal to)
3. `UGraphics.getCharWidth` (used to get the width of 'x') does not
   take the `fontProvider` into account, meaning that the width
   that it calculates for that character could be wrong.

To solve this, the check has been removed, as it is flawed and doesn't
seem to have an explicit error, contrary to what the comment in the code
said.

The only problem found with this was that `getStringSplitToWidth`
would push an extra line onto the list if the container wasn't long
enough to render one character. This has been fixed by adding a
`isNotEmpty` check before pushing the line (that's okay to do in this
case, as it's not a newline check).

The only "breaking change" about this, is that if your container
is less than "a character" wide, they will still render. If you for
some reason want to avoid this, put a `ScissorEffect` onto your
`UIWrappedText`, but this shouldn't really be necessary.
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.

2 participants