Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Expand InputField height with text contained

Discussion in 'UGUI & TextMesh Pro' started by millefoliumink, Jan 15, 2019.

  1. millefoliumink

    millefoliumink

    Joined:
    Aug 28, 2014
    Posts:
    139
    I'm looking for a way to expand the InputField height by the amount of text contained, preferably for TextMeshPro InputField.

    The examples I have found don't work happily within Vertical Layout Groups, the first line disappears when starting a new line.
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    I did exactly that but I used custom components I made from Better UI 2.0 (beta).
    If you are deciding to try Better UI 2.0 Beta out (write me a PM) I can tell you how to achieve this:
    1. Add a
      Better Content Size Fitter
      Component next to the (Better)
      Text Mesh Pro Input Field
      Component.
    2. Set the
      Source
      object of the
      Better Content Size Fitter
      to the
      Text
      lower in the hierarchy (This will tell the content size fitter that it should fit to the size of the Text, not itself).
    3. Set the
      Vertical Fit
      to
      Preferred Size
      .
    4. Select the
      Text
      object and add a
      Size Change Tracker
      component there. Add the parent object which has the (Better)
      Text Mesh Pro Input Field
      to the
      Affected Objects
      List (this will tell the parent all the time when the size changes)
     
    MuntyMcFly and millefoliumink like this.
  3. millefoliumink

    millefoliumink

    Joined:
    Aug 28, 2014
    Posts:
    139
    I'll be sure to check this out!