-
Notifications
You must be signed in to change notification settings - Fork 10
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
Spaces cause wrapping to create an extra line for each space #13
Comments
Note: I was playing around with the code above and doing some experiments. I noticed that if you replace |
I know markup() is an option, unfortunately it is quite a bit slower (and allocates more) than regenerateLayout() if it is run every frame. I think this bug is fairly old -- I have projects that depend on specific versions in the
like this. I'll see what I can do to fix this when I'm changing word wrap to match libGDX behavior (related to #11 ). |
The bug causes each word to wrap onto its own line, somehow -- it looks like https://i.imgur.com/gN3LsoU.png .
I have at least the non-space case fixed, where words would take up an entire line regardless of width: https://i.imgur.com/QVL9bU0.png . I'll try out the repro case in issue 13 next.
This can be seen as a temporary fix, since I need to rewrite large parts of the word wrap API to match libGDX behavior, but it does make it so multiple spaces are kept (except for the last one on a line, which becomes a newline and can be turned back into a space by repeated wrap changes).
This should be mostly fixed by 0f821d7, but it would be nice to know if it is fixed in your app's/game's case, @lucas-kakele . Can you try a JitPack dependency on the latest commit? https://jitpack.io/#tommyettinger/textratypist/0f821d7390 I'm not entirely sure the multiple-space logic is going to be how people want it, but now it definitely doesn't add a newline after every space. As normal, it converts one trailing space (the last one on a line) to a newline ( |
Thank you Tommy for promptly working on a fix! I'm traveling this week and will be able to test it next week. I will keep you posted. Regards. |
Hi Tommy. I tested your latest commit both in my game and in the example above. It looks like text bounds are not working properly now. Gradle:
Demo code with |
It still seems to be working when making proper use of scene2d.ui's "preferred size" inside a Table cell or Container.
Ugh, the sizing logic for anything involving scene2d.ui is just maddening. I tried this in Issue13Test in this commit: 513c6b8 and it measures the width and height correctly there, for either TextraLabel or TypingLabel. I am guessing something is different with your example, but I'm not sure what. Wrap could be turned off, which would be strange because it is wrapping... The label might not be in a Table cell or Container, which would make its preferred size not necessarily match its actual size. Something might need to be pack()-ed or invalidate()-ed; I can never tell when scene2d.ui needs that, though I don't need it in the linked test. |
I'm not sure what are the color differences (red/green) when enabling scene2d.ui debug, but for the Issue13Test code, the height is still wrong if you print the label height. If you remove TypingLabel is working correctly for me. |
I'll take a look again... I was pretty sure debugAll() just set the debug mode on everything in the stage. It's also possible that the height starts incorrect and becomes correct by the time it's displayed, which would explain the print but not the red outline. EDIT: Yeah, the height starts at one line (20 pixels) even though the preferred height is the correct 4 lines (80 pixels). Calling table.pack() will make the preferred size calculate properly for everything in the table, and after that a TextraLabel's getHeight() will be correct. I think TypingLabel may do some of what pack() does, internally. I can't possibly claim to understand all of scene2d.ui, but I know calling pack() is often an answer to some problems. |
Now a TextraLabel will show the correct debug bounds even without calling pack(), which is the same behavior as TypingLabel. It shows the correct actual height in the println() call once pack() has been called.
Thank you for your work so far in this issue! I was testing the changes, for the following versions: libGDX: 1.12.2-SNAPSHOT And the following code:
Will result in this: You can see the top of the label gets cut out. Uncommenting the line at the TextraLabel layout method ( |
Hi!
When rendering a wrapped
TextraLabel
that has a lot of spaces, each space will result in an extra line.Example:
Code:
In the code above, there will be a whole line with spaces only. When it reaches the size of the table row preferred width, each extra space (defined by
extraLines
in the code) will create a new line.Let me know if you need more information!
Regards.
The text was updated successfully, but these errors were encountered: