Search Unity

Question Label size doesn't match text size

Discussion in 'UI Toolkit' started by PiotrSamborowski, Jan 27, 2023.

  1. PiotrSamborowski

    PiotrSamborowski

    Joined:
    Sep 15, 2021
    Posts:
    2
    So I'm working on some in-game tutorials and tooltips and there's a problem I can't seem to solve.

    I have a label element in my UI Document that contains description text for a skill. I want the same UI document to be used for different skill tooltips in all the languages we'll localize the game into, and that means different lengths of text - so I would like to have my tooltip window to match the size of the text.

    I'm able to match the size of the window to the size of the label element, but the text in that label itself doesn't match the set size of the label. Any way to make the label size match the text size?

    Here's how it looks in UI Builder. upload_2023-1-27_17-21-58.png
     
  2. t2g4

    t2g4

    Joined:
    Nov 13, 2018
    Posts:
    46
    Hi,

    Try to use this
    Code (Css):
    1. {
    2.     flex-wrap: wrap;
    3. }
    or with UI:

    upload_2023-1-28_15-9-1.png

    If it is not working, make sure the wrap is applied:

    upload_2023-1-28_15-9-39.png
     

    Attached Files:

    Last edited: Jan 28, 2023
  3. PiotrSamborowski

    PiotrSamborowski

    Joined:
    Sep 15, 2021
    Posts:
    2
    Wrapping the text wasn't the problem. Anyway, I figured it out - turns out you cannot use Position to position the Label (i.e. making it not stick to the border of the box that contains it), you have to use Margin for that. Margin adds space around the text, while Position moves the text from the origin point of the Label without moving or resizing the Label itself.
     
    t2g4 likes this.