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.
  2. Dismiss Notice

What happened to wordwrap?

Discussion in 'UI Toolkit' started by a436t4ataf, Oct 25, 2020.

  1. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    To my surprise ... UIToolkit's defaults for Label don't wrap text - if there's not enough room horizontally (even if there's infinite space vertically), they simply truncate.

    The 2018.x build of UIToolkit (UIElements) had a property in IStyle that let you set the wordwrap behaviour, but this is now vanished, and searching the docs gives zero hits (Google can only find the deleted item, not any kind of replacement).

    How do we change UIToolkit Labels so they wrap correctly?
     
    jGate99 likes this.
  2. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,845
    There is some CSS property to get it wrap, i dont remember it but i read a post few months ago mentioning it.
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    CSS has flex-wrap, which appears in UIToolkit as "Wrap" - but that's completely separate, and cannot apply to text (it applies to elements within a flex scope).

    CSS has word-wrap, which is what Unity has deleted in 2019.

    I can't find anything that Unity HASN'T deleted which fits this :(
     
    jGate99 likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
  5. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    Perfect! Thanks, Karl.

    Code (CSharp):
    1. var section = rootVisualElement.Q<VisualElement>( "MyDataArea" );
    2. descField = new Label("Some really long text is goinna go here ads fslksdf ldsfj kldsf s" ) { style = { whiteSpace = WhiteSpace.Normal } };
    3. section.add( descField1 );
    Out of interest ... do you know if there is a particular reason why this isn't the default?
     
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    I think it was just a judgement call that in most game UI, the Labels are not large paragraphs and instead serve as actual labels on fields, buttons, title bars, etc. Such use cases typically actively do not want text to wrap at will (think Buttons becoming taller randomly). Using Labels for larger text blocks is a less common use by comparison.
     
    karl_jones likes this.
  7. Dargon_huihui

    Dargon_huihui

    Joined:
    Mar 23, 2016
    Posts:
    4
    a436t4ataf likes this.
  8. crs117

    crs117

    Joined:
    Oct 24, 2016
    Posts:
    4
    Thank you!

    The buttons I designed were large enough for word wrap but I could not find the style for it. I think they need to relabel the descriptor for the style class in the text item in the UI Builder inspector as well.