If you type text into regular Unity UI Text, it will take into account whitespace at the end when calculating position of the aligned text and preferred width of the element.
But TextMesh Pro UGUI never does. It seems that white space at the end of string is completely ignored. The only thing I could do is adding “<size=0>.” at the end. This is ugly and my Input Fields no longer work properly.
Also there is a strange Input Field behavior that I think is related to this. When setting text alignment to right, and typing some spaces into Input Field, text shifts to the left. But when erasing them, text does NOT shift back to the right! Also the area with that spaces, that area doesn’t catch raycasts, if I click there with no raycast target on Input Field root object, it will be deselected.
If I want to implement said feature, I guess I should inherit from TMP_Text or TextMeshProUGUI. Which one to choose and what to override?
This needs to be fixed/added. I use TMP to build my own Input fields which are right aligned (I cannot use Unity’s inbuilt InputFields because of other constraints). Having spaces not move the Text until you add another character makes this unusable. Non-breaking spaces are not a solution, since I don’t want to disable automatic line breaks. It doesn’t have to be the default behavior, but I need an option to count trailing spaces for alignment.
As per a previous post in another thread, I will be exploring adding support to control whether or not white spaces are ignored or not at the end of a line.
I certainly agree that in the context of an input field, not having the text scroll on white spaces at the end of a line is not ideal.
+1 for allowing user to select whether or not whitespace/non-breaking whitespace is considered in alignment. I’m currently trying to ‘indent’ text for alignment and having a rough time since TMP eats leading space. My $0.02 is that non-breaking space should always be included in alignment calculations. Why else would the developer have specifically put a non-breaking space?
Of course when looking for the solution I see that the author himself has spoken about the issue a day ago, lol!
Thanks for the continued support, Stephen–TMP is the backbone of so many apps/games! We love you!
EDIT: ‘Figure space,’ \u2007, appears to work just fine for ‘leading’ whitespace. Using the monospacing tag I’m able to indent things nicely without issues.
Preserve Whitespace will consider whitespaces at the end of a line for the purpose of alignment and preferred width.
Preserve Whitespace No Wrap is the same as above but without wrapping.
The previous “enableWordWrapping” property will be remapped to this new “textWrappingMode” property.
Could you all please submit a few text strings that you are currently using to achieve special alignment / formatting? This will help ensure I don’t overlook any special cases.
This will be in the next preview release of the TMP package which I am hoping to release within the next 10 - 14 days. There will be a release for Unity 2018.4, 2019.4 and 2020.x or newer.
Note: Packages have their own release cycles which is not tied to Unity’s recycle.
It’s great to hear to be able to control the behaviour of whitespaces. As I am working on a rich text editor I also need this option. @Stephan_B Do you already have an idea when we can expect this update?
I made myself an impromptu cursor (here it is red in the screenshot), its position is determined by the center of the line and the edge of the last letter.
If you put one space after the last letter, then the space will not be visible! since the cursor is in place
If, after the first press on the space, press again, then the space will be set and further pressings will also create spaces further, and the cursor will move.
The same applies to letters, if you put a space first, then we will not see it (the cursor does not mo ve), but if after that you write a letter, then it will appear taking into account the space
how to deal with it? what can you advise?
only please do not suggest the space \ u00A0 it does not help, but on the contrary created more problems
I’m also running into an issue that didn’t seem to be there before. I have two labels side by side. One is right aligned and the other is left aligned, so I can’t have the text in a single label. However, I need to be able to control the line spacing so that auto-sizing is same for both labels. One label may have more text than the other, so I need to insert empty lines at the end of the shorter one so the autosizing is the same. However, this no longer works.
I’m using TMPro version 3.0.4 but still don’t see this option in Text Wrapping.
[edit] I just tried adding a tab to the empty lines, and that does get recognized, so I’ll do that for now.
Perhaps someone else needs. In the project folder Packages/manifest.json change “com.unity.textmeshpro”: “3.0.6” to “com.unity.textmeshpro”: “3.2.0-pre.2” and you will have Text Wrapping. Spaces will be displayed correctly.