Search Unity

Dynamic Text, Text Fields, Scroll Views (4.6 GUI)

Discussion in 'Immediate Mode GUI (IMGUI)' started by Nikovich, Sep 23, 2014.

  1. Nikovich

    Nikovich

    Joined:
    Jul 10, 2010
    Posts:
    69
    Maybe I'm not using the new 4.6 GUI right, but when connecting a gameObject with a text component as a child to a scroll view, the scrolling seems to be dependent on the size of the field and not the text inside it. Naturally, this causes unintended behavior unless I'm manually sizing the text field to be exactly the same length as its text. If my text field is 200 units tall, it will scroll to a max of 200 units regardless of whether there is a word in the text field or 20 paragraphs.

    So since I'm adding text dynamically, is there a way to autosize the text field to match the text inside it? I'm using a text field to display found bluetooth enabled devices within a proximity and to display their stats, so I need for the text field to not be scrollable when not enough are found to fill the mask, and for it to be scrollable to the last line when they are. I'm also having trouble getting the mask to occupy the same area when it's exported, but that's a different issue and more related to still not being sure exactly how anchors work.
     
  2. yingpar

    yingpar

    Joined:
    Sep 25, 2014
    Posts:
    10
    I'm trying something similar at the moment. The only thing I can think of is maybe adding the font's line height to the text box every time an input is made (though I'm not sure how to get to that information, honestly) - or perhaps setting the initial size of the text box to exactly contain one line of text, saving that height, and then adding it to the total with each new line.

    It does seem like it ought to be just a standard overflow option, though - but maybe I'm missing something obvious. :)

    EDIT: Ignore all that, read this: http://docs.unity3d.com/460/Documentation/Manual/UIAutoLayout.html
     
    Last edited: Sep 25, 2014
  3. Nikovich

    Nikovich

    Joined:
    Jul 10, 2010
    Posts:
    69
    Thank you, was what I was looking for.
     
    J_P_ likes this.
  4. Nodrap

    Nodrap

    Joined:
    Nov 4, 2011
    Posts:
    83
    Had the same problem and found this page to be the most useful:
    http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html

    My problem came about because as you make the window larger the font size increments seem to be point based and so snap up less frequently than the screen scale. This showed up in a long text field getting larger and smaller depending on different resolutions on mobile devices. It can be seen by just changing the vertical in the editor and you see the text re-wrapping itself by different amounts. This is not with best fit by the way.