Search Unity

TextMesh Pro Auto size AND ellipsis

Discussion in 'UGUI & TextMesh Pro' started by Jayme65, Feb 23, 2018.

  1. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    Hi,

    We need to display text auto-sized on a character height basis...and with ellipsis!
    In other words (in images actually ;) ), here is what it gives now with auto size:

    ...and what we would like


    The possibility to auto size on 1 line height basis (and why not 2,3,... lines ) WITH ellipsis
    Could it be achieved..and how please?

    Thank you!
     
    Last edited: Feb 23, 2018
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Text Auto-Sizing by design will keep reducing or increasing the size of the text in order to fit all the text in the given space. Ie. it is designed to avoid having to use Ellipsis or having to truncate the text.

    Now if you carefully set the minimum / maximum auto-size range, whenever those ranges are reached then truncating or ellipsis will kick in.
     
  3. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    Thanks for your reply!
    I think that I understand what you're telling me...but this block being subject to resize I don't see how I could achieve what you're talking about with the min/max range.
    A text block with a 20px height vs. 120px height..I really don't see how to manage this!

    Thanks!
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Like I said by design auto-sizing will either reduce or increase the point size to fit the entire text in the given width and height. So with a range like 20 to 120 it will reduce the point size down to the minimum of 20 before it begins to truncate or use Ellipsis.

    The issue here is "What logic do we use to determine what the optimum size is"? We can increase or decrease the point size until everything fits but how do we determine that we should only increase to one line or two lines?

    I think you need to re-evaluate what you are trying to achieve. Can you provide more details on that?

    Also note that auto-sizing does have performance overhead so it is not ideal to use it on all text objects either. The best use case for auto-size is to determine the optimum point size for "the largest" block of text to fit in a given area. Then that point size should be used on all text objects (for design consistency) and then auto-size disabled where you then manually set that optimum point size on all other text objects. This provides for handling different resolution / languages / work lengths while providing best performance.
     
  5. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    I'll follow your advice and achieve this by simply multiplying the font size by a ratio based on text block height!
    Thank you for taking time to reply my question, really!

    I still think that it might be a nice feature for every one to determine that a text block will autosize for 1,2,3,..lines to fit
    ...that would be a user choice, a field where one could choose "off,1,2,3..." Then your algorithm calculates the font-size according to parent size to fit 1,2,3 line in height..or normal behavior if 'off'!?

    PS: thanks for the tip on 'correct' auto-size use by the way!
     
    Last edited: Feb 23, 2018
    Stephan_B likes this.