Commit 4929d08
UIWrappedText: Fix single-character strings not being rendered (#142)
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.
Co-authored-by: Sychic <[email protected]>1 parent 1b5dde2 commit 4929d08
File tree
2 files changed
+1
-7
lines changed- src/main/kotlin/gg/essential/elementa
- components
- utils
2 files changed
+1
-7
lines changedLines changed: 0 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 150 | | |
157 | 151 | | |
158 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
0 commit comments