-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Sometimes automatic line breaks start at the wrong x-position #474
Comments
I remember also having issues with text rendering in java in one of my own projects. I had to render the text using a GlyphVector to calculate bounds and stuff because it would just be wrong very often, however I've never seen it wrong by that much. Just from a visual glance, it looks like the text's x-coordinate is being set to |
Hi LITIENGINE community, Can I make my first contribution by working on this issue? I discovered the same cause that was already mentioned in a bug description: negative If these lines are removed:
position gets clamped: However, two tests fail: AlignTests > getLocation_InPoint(): expected: <-1.5> but was: <0.0>
AlignTests > getLocation_OffPoint(): expected: <0.45> but was: <0.0> Test code:
litiengine/litiengine/src/test/java/de/gurkenlabs/litiengine/AlignTests.java Lines 25 to 41 in 84d617a
Both alignment enums are used not only in Either way an expected location behavior should be determined for all alignment values. |
Hi @hedfol , thank you for your detailed assessment! We welcome your contribution in this regard. I would neither create separate classes nor methods for this, but an overload to the getLocation method with an additional boolean parameter that lets the user decide which behaviour to choose. Since the current logic seems to be assuming the entity case, we should leave the uses of getLocation in entities untouched and only replace the uses in text scenarios with the new overload. |
Add getLocation method overload to Align and Valign enums. Implement an option to prevent the values that are out of bounds.
Make getLocation calls in text scenarios use preventOverflow option. Do not alter the default uses of getLocation for entities.
Add basic tests for Align.getLocation with preventOverflow:true. Create similar tests for Valign.getLocation: default and no-overflow.
Thanks @nightm4re94 , that's an easy solution! I've created a PR with suggested changes. |
Make getLocation calls in text scenarios use preventOverflow option. Do not alter the default uses of getLocation for entities.
Add basic tests for Align.getLocation with preventOverflow:true. Create similar tests for Valign.getLocation: default and no-overflow.
Describe the bug
Sometimes automatic line breaks start at the wrong x-position. For example, if I set the text of a GuiComponent to be "This is a much longer test to test text box wrapping for the NPC text boxes." it looks like this:
Clearly not what it's supposed to look like. However, if I change nothing other than the string, it works. For example, if I replace the 'g' in "wrapping" to a period, it looks fine:
So, I'm guessing that first line just happened to be juuuust the right width to break something.
In Align.getLocation, the objectWidth > width for the bad string, but < width for the good string.
Because of this, location is negative but doesn't get clamped. I'm guessing that's the issue. Or at least roughly in that area.
To Reproduce
Steps to reproduce the behavior:
Your System:
The text was updated successfully, but these errors were encountered: