Author Topic: UIInput for TextArea  (Read 8803 times)

kenshin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 24
    • View Profile
UIInput for TextArea
« on: August 03, 2012, 03:54:57 AM »
Hi,

I need a textarea that allow the user to add many lines of thext in the single text input area.
Is there a way to extend UIInput widget to accept new-line/breack-line character fron the user input?

I am pretty sure that this is a usefull improvement for our beauty NGUI! :)

Thanks
Kenshin

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput for TextArea
« Reply #1 on: August 03, 2012, 05:14:53 PM »
The submit key is specified on the UICamera, you can change it if you want.

kenshin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: UIInput for TextArea
« Reply #2 on: August 04, 2012, 04:18:12 PM »
I have tried replacing "return" in "Submit key 0" but nothing change... if I beat on return key I haven't any new line in the text area.

I am doing something wrong or is just a little bug? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput for TextArea
« Reply #3 on: August 05, 2012, 09:04:48 AM »
I will release 2.1.3 shortly, and it should work there.

kenshin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: UIInput for TextArea
« Reply #4 on: August 05, 2012, 04:48:40 PM »
I have update and is a little bit better: now submit key works but I can't find any way to write some text on multi-line (for example clocking shift+return to break current line).
What I need is a real multiline textarea in which the user can break the line every where.

Any suggestion about this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput for TextArea
« Reply #5 on: August 05, 2012, 04:49:59 PM »
Does Unity actually send new line characters in the Input.inputString?

kenshin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: UIInput for TextArea
« Reply #6 on: August 07, 2012, 04:43:26 AM »
Absolutely yes! :)

I have tested with this piece of code:
  1.        
  2. foreach (char c in Input.inputString) {
  3.    if (c == "\n"[0] || c == "\r"[0])
  4.              Debug.Log("Input string NEW LINE");
  5.            
  6.    if (c == '\n' || c == '\r')
  7.              Debug.Log("Input string NEW LINE2");
  8. }
  9.  

UILabel support '\n' too to add new line inside the text, then I think is easy extend UIInput to support multiline.

Any idea?
« Last Edit: August 07, 2012, 04:47:31 AM by kenshin »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput for TextArea
« Reply #7 on: August 07, 2012, 12:11:46 PM »
Looks like Unity sends \r, not but \n, and the string needs \n. Modify UIInput, line 352:
  1. mText += c;
to:
  1. if (c == '\n' || c == '\r') mText += "\n";
  2. else mText += c;

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput for TextArea
« Reply #8 on: August 07, 2012, 12:17:09 PM »
Better yet, replace that entire section with this:

  1.                                 else if (c == '\r' || c == '\n')
  2.                                 {
  3.                                         if (UICamera.current.submitKey0 == KeyCode.Return || UICamera.current.submitKey1 == KeyCode.Return)
  4.                                         {
  5.                                                 // Not multi-line input, or control isn't held
  6.                                                 if (!label.multiLine || (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightControl)))
  7.                                                 {
  8.                                                         // Enter
  9.                                                         current = this;
  10.                                                         if (onSubmit != null) onSubmit(mText);
  11.                                                         if (eventReceiver == null) eventReceiver = gameObject;
  12.                                                         eventReceiver.SendMessage(functionName, mText, SendMessageOptions.DontRequireReceiver);
  13.                                                         current = null;
  14.                                                         selected = false;
  15.                                                         return;
  16.                                                 }
  17.                                         }
  18.  
  19.                                         // If we have an input validator, validate the input first
  20.                                         if (validator != null) c = validator(mText, c);
  21.  
  22.                                         // If the input is invalid, skip it
  23.                                         if (c == 0) continue;
  24.  
  25.                                         // Append the character
  26.                                         if (c == '\n' || c == '\r')
  27.                                         {
  28.                                                 if (label.multiLine) mText += "\n";
  29.                                         }
  30.                                         else mText += c;
  31.  
  32.                                         // Notify the listeners
  33.                                         SendMessage("OnInputChanged", this, SendMessageOptions.DontRequireReceiver);
  34.                                 }

kenshin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: UIInput for TextArea
« Reply #9 on: August 08, 2012, 07:34:04 AM »
Thanks for add this to the new release!  :)

Kenshin

alph

  • Guest
Re: UIInput for TextArea
« Reply #10 on: August 24, 2012, 08:02:09 AM »
I also need a "HTML TextArea" box and played around with input w/multiple lines activated. The problem is that when the user writes more than there is room for, then things turns ugly.

Some solutions to tackle this problem:

1. Some hacking of UITextList so it would work on an input field. I tried this without success.
2. Some hacking of UIDraggablePanel & UIScrollBar to make some kind of scroll view. I tried something, but quickly found out this was hard.
3. Limit the input to x characters. This is the only solution I found so far. It sux, but at least it doesn't look ugly.

So I guess this is kind of a request, or a cry for help if you see a way for me to make a proper TextArea box.

:)