Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

TextMesh Pro Vertical Alignment in TextMeshPro stylesheet

Discussion in 'UGUI & TextMesh Pro' started by Buzzrick_Runaway, Oct 30, 2022.

  1. Buzzrick_Runaway

    Buzzrick_Runaway

    Joined:
    Jan 7, 2018
    Posts:
    14
    It seems like we can only set the horizontal alignment in a TextMeshPro stylesheet. Is there a stylesheet tag for vertical alignment?
    I've tried all of the following, but none work:

    Code (CSharp):
    1. <align=bottom>
    2. <valign=bottom>
    3. <verticalalign=bottom>
     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    382
    I doubt that TMP currently supports that. The tags in stylesheet definition are the same as you can use in the middle of TMP text directly and potentially apply different formatting to each word or sentence. It doesn't make much sense to have multiple different vertical alignments in single block of text. What should happen if first half text is aligned to bottom and second half aligned to top? Swap places? Overlap?

    I don't mean that having full styling control in stylesheet makes no sense, but it would require a somewhat different model of what stylesheets are how they work. But i might be wrong, maybe TMPro internals could deal with that and it's just the interface prevents changing it dynamically because with exception of few very specific cases it would make a mess.
     
    Buzzrick_Runaway likes this.
  3. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    382
    You might also want to take a look at the new unity UI toolkit instead of UGUI+TMPro. It's design is closer to how HTML layout and styling works. Since it deals with whole UI layout and styling not just text formatting, it might be better equipped to deal with such stuff.
     
    Buzzrick_Runaway likes this.
  4. Buzzrick_Runaway

    Buzzrick_Runaway

    Joined:
    Jan 7, 2018
    Posts:
    14
    Thanks for the feedback. That makes sense about the styles needing to apply to single words/sentences.
    I was also looking to see if I could set the default vertical alignment to middle in the TMPro settings, which would be useful, but there doesn't seem to be much control there.
    I'd love to switch to the new UI Toolkit, but the current work I'm doing is supporting a legacy product.

    That's all good though. I was hoping to be able to standardise the alignment in the stylesheets, but we'll just have to ensure we set them manually for each instance.