Author Topic: UIInput: Use the current label value as Starting Value  (Read 3852 times)

JasonABentley

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
UIInput: Use the current label value as Starting Value
« on: November 20, 2014, 03:15:51 PM »
My label represents a length value and changes as the user moves the end points.

The user clicks on the Collider for the UIInput and because the StartingValue is empty, it makes the label.text empty.

I had hoped to that it was as simple as creating a new class that inherits from UIInput and overrides the OnSelect or OnPress and assigns the mDefaultText to label.text before the UpdateLabel but that doesn't work.

Anyone attempted something like this before and have any suggestions?


  1. public class UIInput_LengthIndicator : UIInput {
  2.         protected override void OnPress (bool isPressed)
  3.         {
  4.                
  5.                
  6.                 mDefaultText = label.text;
  7.  
  8.                 if (isPressed && isSelected && label != null && UICamera.currentScheme == UICamera.ControlScheme.Mouse)
  9.                 {
  10.                         mSelectionEnd = GetCharUnderMouse();
  11.                         if (!Input.GetKey(KeyCode.LeftShift) &&
  12.                             !Input.GetKey(KeyCode.RightShift)) mSelectionStart = mSelectionEnd;
  13.  
  14.                         UpdateLabel();
  15.                 }
  16.         }
  17. }

JasonABentley

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIInput: Use the current label value as Starting Value
« Reply #1 on: November 24, 2014, 01:02:47 PM »
Ok, no responses.

Does that mean that people find it odd to want to do this or that they consider the question incredibly easy to solve?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput: Use the current label value as Starting Value
« Reply #2 on: November 25, 2014, 01:27:06 AM »
I don't understand your question. If you want the input field to start with some value, then give it a value.

input.value = "Some text";

JasonABentley

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: UIInput: Use the current label value as Starting Value
« Reply #3 on: November 25, 2014, 11:19:46 AM »
Got it.

I was attempting to change the "DefaultText" rather than just setting the value directly.

Thank you.

« Last Edit: November 25, 2014, 11:28:40 AM by JasonABentley »