Search Unity

Question How do I auto size TMP input field text so it fits vertically but overflows horizontally

Discussion in 'UGUI & TextMesh Pro' started by ETGgames, Nov 22, 2022.

  1. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    I'm trying to get my input field's text to expand and fit to the full height of the input field. But I don't want it to become smaller if it overflows off the side. Auto size will reduce the size to try and fit both horizontal and vertical, but I just want vertical fit.
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    A content size fitter not working for you?
     
  3. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    Nope. If I put the content size fitter on the textmeshpro UI child component of the input field gameobject, it doesn't actually shrink or grow the vertical text size. And I don't want to put it on the the input field gameobject itself, because its size is determined by it's parent.
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    I don't think this is a feature as you are talking about two competing features:

    * AutoSize, changes the font size based on the physical size of the text box, to make the text "fit"
    * Overflow moves words to new lines within the available space of the text field.

    Better you focus on using a content size fitter to maximise the space the text field can use, along with a layout element to control the min and max values. Autosize is only really useful to set a min / max size to fit the area

    Hope that helps, but it sounds like you need to design the areas rather than rely on features TextMeshPro provides.
     
  5. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    hmm, as i suspected.

    it's annoying coz i want responsive layout that depends on the parent size without having to code a manual system that updates the size.

    I feel like this is a big enough use case that it should be built in.
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    You can have a responsive layout that responds to size/orientation, it just takes a lot of work with layout components and anchors to "get right"

    But AutoSize is a very different feature exclusive to TextMesh Pro to work with a fixed sized area and ensure the text always fits in a single line.
    As a tip, also check the "advanced" settings in the TextMeshPro inspector and also search up other TextMeshPro examples, since Unity bought this feature rather than build it themselves.