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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Getting the auto-scaled size of a textfield

Discussion in 'UGUI & TextMesh Pro' started by Ruadhan, Feb 5, 2015.

  1. Ruadhan

    Ruadhan

    Joined:
    May 8, 2013
    Posts:
    7
    I have a Panel with a textfield in it. it's using ContentSizeFitter and a VerticalLayoutGroup to scale the height of the panel to fit the textfield, this allows me to add as much or little text to the textfield and the panel scales with it.
    That's all fine.

    The problem is that this is meant for a Chat system, and the panel constitutes a single message. I need to know the vertical height of the resized panel (or textbox) in order to offset the positions in the line of messages.
    The sizeDelta returns the correct X value as I'm not changing that, but the Y value returns as 0. looking in the inspector it's greyed out but shows 120 pixels as the height.

    I need that data, is there anything I can do to get it?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    If it's a chat system, then I'd put each text message in a new text field as a child of the Vertical layout group.
    That way they would just keep flowing, rather than just filling a single text box (if I've read that right)
    I'd also surround it with a ScrollRect with a scrollbar to the side for when it overflows.

    Hope that helps.
     
  3. Ruadhan

    Ruadhan

    Joined:
    May 8, 2013
    Posts:
    7
    Sounds more or less like what I'm doing.
    What I'm doing is instantiating a panel containing a textfield for each message entry (there's a few other items like timestamp and name on there too)
    and then using the contentsizefitter and such to ensure the outer Panel remains big enough to wrap the textfield.

    The tricky bit is that I can't seem to get the Height value on the Panel afterwards. it greys it out and denies me access to the data (presumably for reasons of read-only, but without actually letting me read it either)
    I need the height so I can place the next Panel down the list without overlapping and without a huge gap between one-line messages.
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    I'll have a tinker around. Coult be the Content Size fitter is taking over and that's where you might get your values from.
     
  5. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    Running into this issue as well. Has there been any headway?