Search Unity

Need clarification on TMP_Font asset and tab size/width/multiple.

Discussion in 'UGUI & TextMesh Pro' started by Mixality_KrankyBoy, Sep 8, 2021.

  1. Mixality_KrankyBoy

    Mixality_KrankyBoy

    Joined:
    Mar 27, 2009
    Posts:
    737
    Hi,

    I am having troubles understand the various (3?) properties for font assets related to tabs (\t).

    1. First we have, under the Face Info prop section "Tab Width".
    2. Under Font weights we have "Tab Mutliple".
    3. Thirdly if we programmatically access a TMP_FontAsset object we have a "tabSize" right in that class.

    I can't for the life of me find a good description of these values (other than vague references to the number being a multiple of spaces). How do we use them together? If I set either of the first two to 0 then no tabbing occurs. And the values do not seem to work properly from what my testing can see. Here is a UI with tabbing set to 15 in both #1 and #2 listed above.

    upload_2021-9-8_13-37-38.png

    Any insight would be appreciated.
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The Tab Width is set by whoever designed the font and can be edited in the FaceInfo in the Font Asset inspector.

    The Tab Multiple represents the multiple of the tab width being inserted when a single tab "\t" is used.

    The font asset property "tabSize" is Tab Multiple which will be renamed to tabMultiple in some future release of the TMP package.

    How does this all work?

    If Tab Width is 10 and Tab Multiple is 1 then \t will represent a width of 10 pixels assuming the scale of the text is 1:1. A scale of 1:1 means the text object point size is equal to the sampling point size.

    However, the confusing part is that tabs are in reality tab stops where each stop is equal to this Tab Width * Tab Multiple. So for example, if you have a Tab Width of 10 with Tab Multiple of 1 then you will have a tab stop every 10 pixels.

    Tab stops enables us to tabulate / align the text in columns at those tab stops.

    When you insert a tab "\t" the advance which is where the next character will be inserted will move to the next tab stop position. Tab does not add a fix amount of space but again moves the advance to the next logical tab stop where these are defined by the Tab Width * Tab Multiple.