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. Dismiss Notice

Multi Line Input Field with Scrollbar

Discussion in 'UGUI & TextMesh Pro' started by DTo, Apr 8, 2016.

  1. DTo

    DTo

    Joined:
    Sep 2, 2014
    Posts:
    3
    In the old unity before the new UI the textbox have a scrollbar for users to scroll up and down on it.

    There doesn't seem to be any for the new UI and the user have to move up and down with the keyboard or using the mouse highlight select.

    Any way to add it?

    These answers does not have the desired results

    http://answers.unity3d.com/questions/962275/add-scrollbar-to-multiline-input-field.html

    http://answers.unity3d.com/questions/798599/how-to-create-a-scrollable-inputfield.html

    http://answers.unity3d.com/questions/1107640/how-to-create-a-scrollable-inputfield-using-new-ui.html

    http://answers.unity3d.com/questions/932607/putting-a-multiline-inputfield-in-a-scroll-rect.html
     
  2. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
  3. DTo

    DTo

    Joined:
    Sep 2, 2014
    Posts:
    3
    Last edited: Apr 11, 2016
  4. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    No, you can't. Can't find the post, but I recalled a Unity employee said the InputField was not designed to let the developers get and set the caret position, and show the current line selected. It's very likely there will be no support for these behaviors.

    Please correct me if I'm wrong, because if I'm wrong, then that means they will have some support in the future, and I want them to do so.
     
  5. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just in case anyone is still looking for this type of functionality, I had a few users request the ability to use a Vertical Scrollbar with the TextMesh Pro Text Input Field which works with the Canvas system.

    This new feature is still work-in-progress but as seen below, the Scrollbar size and position, reflects the size of the text and caret position.



    This uses a normal UI Scrollbar which is assigned to the TMP Text Input Field.

    upload_2016-10-25_3-28-15.png
     
    Last edited: Oct 25, 2016
    cxode, sj631, ConorArup and 2 others like this.
  6. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    This pretty much validates that Unity Technologies will not be implementing a native solution for scalable, scrollable text field UI objects.
     
  7. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    My addition of this new feature to the TextMesh Pro Input Field certainly doesn't mean that Unity won't be adding it as well.

    Who knows perhaps by the fact I added it to TextMesh Pro, it will provide further motivation for Unity to do so as well in their Input Field component :)
     
  8. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The ability to use a vertical scrollbar with the TextMesh Pro Text Input Field is pretty much ready as seen in this updated video. This new feature will be available in the next release which will be available shortly after Unite in Los Angeles next week.



    P.S. Also note the ability to use Rich Text in the text input field as well.

    P.S.S. Not sure why some GIF don't display in posts. So just in case you can't see it, here is a link http://i.imgur.com/Rm3qqlT.gif
     
    DizzyWascal and HakJak like this.
  9. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    I bought TextMesh Pro because of this feature and it works great, but how do I get it to work with a scroll bar too?
     
  10. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Do you mean an horizontal scrollbar? If so, I have not added support for that yet but that is certainly something possible.
     
  11. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    No just a vertical scroll bar, as seen in the GIF.

    I searched the docs, but maybe I missed something?
     
  12. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The ability to add a vertical scrollbar was added in the latest release of TMP which is available on the TMP user forum.

    If you haven't done so already, make sure you register to the TMP user forum to get access to these releases.
     
    Last edited: Jan 31, 2017
  13. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Well I called it. Unity Technologies isn't going to work on it, and instead, your creation is well enough to be integrated natively into Unity. Congratulations!

    Blog announcement
     
  14. mirick

    mirick

    Joined:
    May 5, 2017
    Posts:
    1
    if you got problems with a caret position, just set
    Text - RectTransform - Pivot x = 0, y = 1.
    Placeholder object - add Layout Element - Ignore Layout.
     
  15. Anemor2000

    Anemor2000

    Joined:
    Jun 12, 2015
    Posts:
    39
    Great asset and feature, we have some problems with the input field tough :
    1) Scroll is visible even when text is really short
    2) even with no scroll, scrolling with the mouse will move the text (and that even if there's just one line and it shouldnt scroll)

    Thanks for your help!
     
  16. bkachmar

    bkachmar

    Joined:
    Mar 15, 2013
    Posts:
    41
    This is my setup to make a scalable input field:
    Regular UI Text field with ContentSizeFitter vertical set to Preferred size and unchecked Raycast target.
    As a child I add Input Field as Multi Line with with RectTransform "stretch" alignment, so that it takes the full size of it's parent.
    The Text child of Input Field has the color set to invisible, so that it is not displayed at all.
    And on Input Field Value Changed I set it's value to my parent Text.

    With this setup when I type something inside the input field it is copied to it's parent "visible" text that is scalable.

    The same way you can have a scroll view with a scroll bar and an Input Field taking up all the space (except of a few pixels on the right where the scroll bar is). And the text from InputField will be assigned to Scroll view.
     
    SimRuJ, airespt and Diansh1 like this.
  17. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    Thanks for the idea, I was looking for a way to do it without adding TextMesh Pro for a single InputField.
    Unfortunately, while the expanding works well, there are still two problems with that:

    1. You shouldn't use a LayoutGroup on the text's parent (the Content Size Fitter then also messes with the size) but if you're making some kind of form, there's really no way around that (afaik) - unless you only support a single resolution and can justify hardcoding the sizes of everything.

    And 2., which is much more important, the parent text field is rendered behind the InputField as parents usually are. I'm using Unity 2017.3.1f1 and not sure if that changed anything but it looks like it doesn't just work the way @bkachmar suggested. In the end you'll have to do one of these things:
    • Set the background color of the InputField to invisible
    • If you want a white background: -"- AND add some panel (but it won't look the same as a default InputField)
    • Use an extra shader on the text and the InputField and change the rendering order
     
  18. ConorArup

    ConorArup

    Joined:
    Feb 15, 2018
    Posts:
    17
    Hi Stephan. I can't seem to make this work at all? Is this something which has been implemented as of Unity 2018.3/TextMeshPro v1.30?

    Can you point me in the right direction for resources/a guide?
     
  19. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Take a look at example 20 - Input Field with Scrollbar included in the TMP Examples & Extras.
     
    ThePilgrim and rcFMS like this.
  20. Robert_Luminous

    Robert_Luminous

    Joined:
    May 21, 2019
    Posts:
    5
    How could I go about having the scrollbar auto hide like in the Scroll Rect component?
     
    cxode likes this.
  21. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Did you ever figure out a way to do this?
     
  22. OreoSplitter

    OreoSplitter

    Joined:
    Oct 21, 2017
    Posts:
    33
    Anyone know how to auto hide the scrollbar if it's not needed? Scrollbar visibility is set to auto hide yet it is always shown.
     
    Last edited: Jul 30, 2019
    iileychen and menderbug like this.
  23. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    130
    I just wasted two hours trying to program a class that does EXACTLY THIS with a normal textbox but it just wasn't quite right. Then i found this. fml
    At least i have a nice looking scrolling itputfield now :D
     
  24. Fayalita

    Fayalita

    Joined:
    Sep 10, 2014
    Posts:
    1
    1) Add a CanvasGroup to the scrollbar with alpha 0
    2) Add a "OnValueChanged" on the scrollbar and call a method that will check the size of the scrollbar. If it's less than 1, it means the content has grown, so you should make the scrollbar visible.

    Code (CSharp):
    1. public void OnValueChanged()
    2. {
    3.     scrollbarCanvasGroup.alpha = scrollbar.size < 1f ? 1f : 0f;
    4. }
     
    OreoSplitter and Robert_Luminous like this.
  25. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    @Fayalita, thank you so much for sharing your solution!