Search Unity

Text Alignment

Discussion in 'UI Toolkit' started by MousePods, Apr 6, 2021.

  1. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    Hi,

    I was wondering if I have to wait for the transform: pivot to be supported before this is possible? Right now the text in a VisualElement only goes below no matter what alignment I have set in UIBuilder.

    This is the effect I am looking for. (This is using TMP text.)




    Thanks!
     
  2. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    273
    I was able to get something close to what you like by using elements with these styles:
    Code (CSharp):
    1. .centered-label-parent {
    2.     height: 332px;
    3.     width: 348px;
    4.     flex-direction: column-reverse;
    5.     align-items: center;
    6. }
    7.  
    8. .centered-label {
    9.     -unity-text-align: upper-center;
    10. }
    11.  
    centered-label.gif

    If you still need a pivot, you can workaround not having transform-origin by adding a empty, 0x0, parent element with overflow: visible.
    Then set its transform.position to the pivot position, then set the child's transform.position to -pivot
     
    Midiphony and MousePods like this.
  4. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    283
    Thanks!
     
unityunity