Author Topic: Scrollable Text Area  (Read 7123 times)

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Scrollable Text Area
« on: August 27, 2014, 06:49:53 AM »
Need to create text area in a window, where users can add/edit text, which has a scroll bar which scrolls as it changes size (rather than shrinks). A basic text editor.

Found a couple of references on possibilities re to do this:
http://www.tasharen.com/forum/index.php?topic=8967.0
http://answers.unity3d.com/questions/370208/ngui-text-vertical-scrollbar.html

Have also gone through the release notes to see if there is anything relevant, but wanted to check if there is a relevant update or better way ? ....before embarking on this

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable Text Area
« Reply #1 on: August 28, 2014, 08:21:14 PM »
Put a resizable label within a scroll view, and make sure the label's pivot is top-left, along with the scroll view's content origin. It should work as expected, although you may need to invalidate the scroll view's bounds in the input field's OnChange notifications (UIScrollView.UpdateScrollbars(true))

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Scrollable Text Area
« Reply #2 on: August 29, 2014, 07:54:13 AM »
Thanks, have got this partially working but having a couple of problems.

Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
EventDelegate:Execute(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:623)
UIProgressBar:set_value(Single) (at Assets/Plugins/Interaction/UIProgressBar.cs:138)
UIScrollView:UpdateScrollbars(UIProgressBar, Single, Single, Single, Single, Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:540)
UIScrollView:UpdateScrollbars(Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:504)
UIScrollView:UpdateScrollbars() (at Assets/Plugins/Interaction/UIScrollView.cs:437)
UIPanel:UpdateSelf() (at Assets/Plugins/UI/UIPanel.cs:1214)
UIPanel:LateUpdate() (at Assets/Plugins/UI/UIPanel.cs:1146)

Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
EventDelegate:Execute(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:623)
UIScrollBar:set_barSize(Single) (at Assets/Plugins/Interaction/UIScrollBar.cs:58)
UIScrollView:UpdateScrollbars(UIProgressBar, Single, Single, Single, Single, Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:552)
UIScrollView:UpdateScrollbars(Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:504)
UIScrollView:UpdateScrollbars() (at Assets/Plugins/Interaction/UIScrollView.cs:437)
UIPanel:UpdateSelf() (at Assets/Plugins/UI/UIPanel.cs:1214)
UIPanel:LateUpdate() (at Assets/Plugins/UI/UIPanel.cs:1146)

and

Could not find method 'UpdateScrollbars' on UIScrollView
UnityEngine.Debug:LogError(Object, Object)
EventDelegate:Cache() (at Assets/Plugins/Internal/EventDelegate.cs:402)
EventDelegate:get_isValid() (at Assets/Plugins/Internal/EventDelegate.cs:207)
EventDelegate:IsValid(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:651)
UIInput:ExecuteOnChange() (at Assets/Plugins/UI/UIInput.cs:1431)
UIInput:set_value(String) (at Assets/Plugins/UI/UIInput.cs:289)
NotesWindowHandler:OnNotesLoaded(String) (at Assets/ViewCode/Menu/NotesWindowHandler.cs:48)
Controller:communicateExternally(ExternalMessageType, String) (at Assets/ViewCode/Controller.cs:724)
NotesWindowHandler:OpenClose() (at Assets/ViewCode/Menu/NotesWindowHandler.cs:41)
EventDelegate:Execute() (at Assets/Plugins/Internal/EventDelegate.cs:473)
EventDelegate:Execute(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:618)
UITweener:Update() (at Assets/Plugins/Tweening/UITweener.cs:224)

The window with the text area on it has a tween which scales and enables and disables the window and am wondering if is due to that, as it starts disabled.

Images of the set up are attached.

Thanks in advance for any insights.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable Text Area
« Reply #3 on: August 30, 2014, 09:08:49 AM »
You can't reference the UpdateScrollbars() function directly in the OnChange as it has a parameter. You need to use a delegate instead.
  1. EventDelegate.Set(input.onChange, delegate () { scrollView.UpdateScrollbars(true); });

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Scrollable Text Area
« Reply #4 on: September 01, 2014, 03:57:18 AM »
Thanks, that fixed "Could not find method 'UpdateScrollbars' on UIScrollView" but the other run time errors still happen. Have run this in debug but have not been able to work out what the problem is:

Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
EventDelegate:Execute(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:623)
UIProgressBar:set_value(Single) (at Assets/Plugins/Interaction/UIProgressBar.cs:138)
UIScrollView:UpdateScrollbars(UIProgressBar, Single, Single, Single, Single, Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:540)
UIScrollView:UpdateScrollbars(Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:504)
UIScrollView:UpdateScrollbars() (at Assets/Plugins/Interaction/UIScrollView.cs:437)
UIPanel:UpdateSelf() (at Assets/Plugins/UI/UIPanel.cs:1214)
UIPanel:LateUpdate() (at Assets/Plugins/UI/UIPanel.cs:1146)

Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
EventDelegate:Execute(List`1) (at Assets/Plugins/Internal/EventDelegate.cs:623)
UIScrollBar:set_barSize(Single) (at Assets/Plugins/Interaction/UIScrollBar.cs:58)
UIScrollView:UpdateScrollbars(UIProgressBar, Single, Single, Single, Single, Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:552)
UIScrollView:UpdateScrollbars(Boolean) (at Assets/Plugins/Interaction/UIScrollView.cs:504)
UIScrollView:UpdateScrollbars() (at Assets/Plugins/Interaction/UIScrollView.cs:437)
UIPanel:UpdateSelf() (at Assets/Plugins/UI/UIPanel.cs:1214)
UIPanel:LateUpdate() (at Assets/Plugins/UI/UIPanel.cs:1146)


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable Text Area
« Reply #5 on: September 01, 2014, 02:08:30 PM »
Well did you actually set the scroll view parameter? Object reference not set tells you that you didn't set something.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Scrollable Text Area
« Reply #6 on: September 03, 2014, 04:24:34 AM »
This error was caused by having a call to UIScrollView/Drag in the OnValueChange in the UIScrollBar script, which had been put in place to try and keep the text in view as you type more stuff at the bottom of the clipped area of the Scrollview. The scroll bar updates and the text is written to the input, but you can't see it, so you have to keep stopping and moving the scroll bar to the bottom. As the scrollbar size matches the exact size of the text you can't move it so there is a load of space at the bottom, that you could then type into. So this means you have to stop and move the scrollbar for every line of text, which is a pretty naff user experience.

Any suggestions on a way around this ?

Thanks
KeithT

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable Text Area
« Reply #7 on: September 03, 2014, 11:49:50 AM »
I'm not quite sure I follow... what does a call to the scroll view's drag have to do with a reference not set exception? Did you actually find the reference that you didn't set? As I mentioned, update scrollbars in OnChange. You can also try to ResetPosition() on the scroll view instead.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Scrollable Text Area
« Reply #8 on: September 04, 2014, 06:31:07 AM »
There were always 2 issues causing errors, both of which are fixed, but we still have a problem with the functionality.

Error Issue 1. Trying to reference the UpdateScrollbars() function directly, which caused the "Could not find method 'UpdateScrollbars' on UIScrollView" error and was fixed by the below:

    void Awake()
    {
        theViewEventHandler = ViewEventHandler.Instance;

        theInputScript = theInputGO.GetComponent<UIInput>();
        theInputUIEventTriggerScript = theInputGO.GetComponent<UIEventTrigger>();

        theScrollView = theScrollViewGO.GetComponent<UIScrollView>();

        //invalidate the scroll view's bounds in the input field's OnChange notifications
        EventDelegate.Set(theInputScript.onChange, OnUIInputChange);
        //listen for the UIInputs selection so other keys processing can be disabled
        EventDelegate.Set(theInputUIEventTriggerScript.onSelect, OnUIInputSelected);
        EventDelegate.Set(theInputUIEventTriggerScript.onDeselect, OnUIInputDeselected);
    }

    private void OnUIInputChange()
    {
        theScrollView.UpdateScrollbars(true);
    }

Error Issue 2. If you add a call to the UIScrollView/Drag method from a UIScrollBar On Value Change you get 4 run time errors. See image. This call has been removed and the errors have gone.

So it's all working apart from: Trying to keep the text in view as you type and it goes off the button of the scrollview.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollable Text Area
« Reply #9 on: September 04, 2014, 11:03:52 AM »
You can't simply choose a function and call it a day. What about the parameter that function expects? Did you not notice that it expects a Vector2 parameter? Where did you even get the idea to use the Drag function? I was talking about ResetPosition or UpdateScrollbars, not Drag.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Scrollable Text Area
« Reply #10 on: September 11, 2014, 11:55:50 AM »
Still trying to work out how to keep the cursor and/or text the user is typing in view.

Wondering if an approach might be to try and tie UIInputs cursor position to the UIScrollView or to the Scrollbars position. Sort of like UICenterOnChild but for the cursor.

Not seen anything anywhere in this area. Does anyone know if anything exists ?