Search Unity

TextMesh Pro Why there is no setting for TextMesh Pro UGUI to count whitespace at the end?

Discussion in 'UGUI & TextMesh Pro' started by trolling-char, May 12, 2019.

  1. trolling-char

    trolling-char

    Joined:
    May 12, 2019
    Posts:
    6
    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?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    White space(s) at the end of a line is normally not counted / considered for alignment / line length purposes.

    Tab \u0009, Non-Breaking space \u00A0 and Figure Space \u2007 do contribute to end of line / line length.

    You can also use a combination of the <space=x.xx> tag with Non-Breaking space.

    I'll try taking a look at this tomorrow.
     
    trolling-char likes this.
  3. trolling-char

    trolling-char

    Joined:
    May 12, 2019
    Posts:
    6
    Thanks. I've tested non-breaking space and it works. However, "test<nobr> </nobr>" doesn't.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    <nobr></nobr> is not the same as \u00A0 Non-Breaking space character.
     
  5. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    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.
     
  6. neo-jam3

    neo-jam3

    Joined:
    Jul 7, 2017
    Posts:
    2
    Using TMP@3.0.1 now, only Tab (\u0009) works for me, neither of Non-Breaking Space (\u00A0) nor Figure Space (\u2007) worked for me...
     
    DankalApps likes this.
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
  8. Wes_VirBELA_Dev

    Wes_VirBELA_Dev

    Joined:
    Nov 11, 2018
    Posts:
    3
    +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 <mspace> tag I'm able to indent things nicely without issues.
     
    Last edited: Oct 24, 2020
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I just made a first pass at adding support for controlling how whitespaces are treated at the end of a line.

    As such, I replaced the existing Wrapping option by a new "Text Wrapping Mode" drop down as follows:

    upload_2020-11-12_1-32-48.png

    - Normal is the same as the previous Enabled.
    - No Wrap is the same as the previous Disabled.
    - 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.
     
  10. Andy608

    Andy608

    Joined:
    Jun 17, 2017
    Posts:
    17
    Is this going to make it in the next version of Unity?
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
    ElSproilex, cfazilleau and iwai_unity like this.
  12. cfazilleau

    cfazilleau

    Joined:
    Apr 10, 2019
    Posts:
    6
    I am using Unity 2019.4.0f1 and I came across the problem, I see this update is still not available, when can we expect it to be released ?
     
  13. Bramverhoeven2

    Bramverhoeven2

    Joined:
    Dec 5, 2017
    Posts:
    6
    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?
     
  14. zephybite0

    zephybite0

    Joined:
    Apr 25, 2018
    Posts:
    29
    I'm interested in this too :cool:
     
  15. ElSproilex

    ElSproilex

    Joined:
    Apr 4, 2019
    Posts:
    1
    I also require this feature for my project, any chance we can have it soon @Stephan_B ?
     
  16. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am currently working on this next preview release as most of the core changes have landed in their respective versions of Unity.

    I will try to get the first new preview release with the above new feature out within the next 15 - 30 days.
     
    zephybite0 likes this.
  17. Anvarito

    Anvarito

    Joined:
    Sep 13, 2017
    Posts:
    8
    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.
    1. If you put one space after the last letter, then the space will not be visible! since the cursor is in place
    2. 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
     
  18. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    305
    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.
     
  19. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    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.
     
  20. IceTrooper

    IceTrooper

    Joined:
    Jul 19, 2015
    Posts:
    36
    This doesn't work when using custom fonts :/ Only LiberationSans (default font asset) works for me, which is not acceptable.
    upload_2022-10-15_12-34-22.png

    On version 4.0.0-pre.1 all font assets were missing script.

    UPDATED
    --> When upgrading TMP version, just don't forget to Import TMP Essentials again <--

    I don't know what happend. Version 3.2.0-pre.2 worked for me, but the steps were:
    1. Change version in manifest.json
    2. Bug with rectangles
    3. Removed TextMesh Pro folder in Project.
    4. No text displayed.
    5. Import Text Mesh Pro Essentials.
    6. Then it works.

    I also did additional steps after that:
    1. Discarded all changed in git (all previous changes).
    2. Everything works as on previous TMP version.
    3. Updated version again to 3.2.0-pre.2
    4. Now it works with just version changing. Probably some cache.
    5. Restart Unity
    6. The same bug with rectangles.
    7. Removed TMP Settings file to enable button "Import Essentials" in settings.
    8. Import TMP Essentials
    9. Works again.

    I did that to understand what was happening.

    BTW It's a shame that last official version [3.0.6] was upgraded in 2021 and last available version [4.0.0-pre.1] - 2021-10-27 is still in preview...
     
    Last edited: Oct 15, 2022
    BeginnerPolymath likes this.
  21. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    Why would you lump this option together with another unrelated option? A separate bool value would have worked just as well, without breaking things.

    At our company we are using a framework that is included in virtually all our projects and that contains wrapper classes for all UGUI object, so they can be properly created and modified via code. I now upgraded a single project to the pre-production package for TMP so I can use this functionality, and it works, but it breaks something else: I do some calculations, but only if
    enableWordWrapping
    is false. But when I use "Preserve Whitespace No Wrap", apparently that (depracated) bool is still true.

    If I want to use this feature, I'd have to change something 5 subclasses deep in our framework, breaking every single project that doesn't use the pre-production package, because the enum doesn't exist yet, or duplicate a whole subtree of classes that all depend on that one subclass.
     
  22. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    These options are related in the sense they control word wrapping including how white spaces are treated at the end of a line. In hindsight, I could have added a new property but this would have meant users having to set two distinct properties instead of just one.

    With respect to the deprecated "enableWordWrapping" property, I could internally continue to set it based on the Text Wrapping Mode. This should ensure your code continues to behave correctly until you have a chance to update it.

    Let me know if that would work for you?
     
  23. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    As long as both "No Wrap" options mean that enableWordWrapping is false, it is usable.
     
  24. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Making the following change will ensure the "enableWordWrapping" property returns the correct value.

    upload_2022-11-24_12-20-24.png

    This change will be included in the next preview release.