Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to use flex wrap with text field of Node?

Discussion in 'UI Toolkit' started by gooby429, Dec 2, 2023.

  1. gooby429

    gooby429

    Joined:
    Aug 13, 2019
    Posts:
    128
    Hey all, I figured the graphView stuff is pretty similar to UIToolkit so thats why im asking in this forum. Im also quite new to this kind of stuff.

    basically I have a text field that im adding to the extensionContainer of a Node as such:
    Code (CSharp):
    1.  
    2.                     TextField field = new TextField(item.Name);
    3.                     field.SetValueWithoutNotify(value);
    4.                     field.name = item.Name;
    5.                     field.style.flexWrap = Wrap.Wrap;
    6.  
    7.                     extensionContainer.Add(field);
    However, it does not wrap the text and looks like one super long line:


    What do I need to set in order for it to start wrapping at a given width like 300? I tried multiline and setting the parent container to a certain width, changing the height of the textField, etc. but cant seem to get it working.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,240
    Try setting a max width to the text field.
     
  3. gooby429

    gooby429

    Joined:
    Aug 13, 2019
    Posts:
    128
    I have, heres what ive been trying:
    Code (CSharp):
    1.  
    2.                     TextField field = new TextField(item.Name);
    3.                     field.SetValueWithoutNotify(value);
    4.                     field.name = item.Name;
    5.  
    6.                     field.style.maxWidth = 300;
    7.                     field.style.minWidth = 150;
    8.                     field.style.whiteSpace = WhiteSpace.Normal;
    9.  
    10.                     field.style.flexWrap = Wrap.Wrap;
    11.                     field.style.flexDirection = FlexDirection.Row;
    12.                     field.style.flexGrow = 1;
    13.  
    14.                     extensionContainer.Add(field);
    Just playing with all the settings even on the extensionContainer at this point