Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro How to implement flexible spacing between words with textmeshpro

Discussion in 'UGUI & TextMesh Pro' started by Rafael_CS, Jun 13, 2019.

  1. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    161
    Hello Stephan,

    I want to know if there is anyway to SEPARATE groups of words to simulate "cells" of a table.
    I experienced a good result using "align=flush" but the "cell" must only have 1 word (so i must replace spaces to another character)

    Any tip to implement this feature? (i just need a "flexible space between words")

    in this case i want to separate the word group "cell1 word1" and the word group"cell2 word1" without convert to
    "cell-word1" and "cell2-word1"

    maybe something like "cell1 word1<flexiblespace>cell2 word1"?
    upload_2019-6-13_3-28-22.png
     
    Last edited: Jun 13, 2019
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Try the following with Flush mode as you have with the text below:

    "Example\u00A0One Example\u00A0Two"

    A few months ago, I made a change to the non-breaking space \u00A0 where it is excluded from consideration with regards to Justified or Flush alignment.
     
    Rafael_CS likes this.
  3. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    161
    Perfect!! thank you very much
     
    HarvesteR likes this.
  4. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    Thanks for the solution Stephan.

    I wanted to ask though, could there be a way to have a single flexible space character? Something like a 'super tab' char? eg
    key column: \T value column


    It would be an immensely useful feature to have.

    Cheers
     
  5. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    Just to follow up, I implemented a 'supertab' parsing method here to create something with the functionality I mentioned. It's a bit janky, but it does work:

    Code (CSharp):
    1. public static string ParseSuperTab(string src, string superTab = "«»")
    2. {
    3.     if (!src.Contains(superTab))
    4.         return src;
    5.  
    6.     string[] lines = src.Split('\n');
    7.     string dst = string.Empty;
    8.     for (int i = 0; i < lines.Length; i++)
    9.     {
    10.      
    11.         if (lines[i].Contains(superTab))
    12.         {
    13.             dst += "<align=flush>" + lines[i].Replace(' ', '\u00A0').Replace(superTab, " ") + "</align>";
    14.         }
    15.         else
    16.         {
    17.             dst += lines[i];
    18.         }
    19.         if (i < lines.Length - 1)
    20.             dst += "\n";
    21.     }
    22.  
    23.  
    24.     return dst;
    25. }
    This will replace normal spaces with non-breaking spaces and set up flush align on any lines that use the "«»" supertab.

    So, something like this:
    Column one:«»Value                                           

    becomes this:
    Column one:                                               Value


    Works well enough for now. :)

    Cheers
     
    Last edited: Jan 9, 2020
    Rafael_CS likes this.