Hello Guest

Author Topic: tk2dUITextInput SetCursorPosition() with scaled objects  (Read 5450 times)

zblack

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
tk2dUITextInput SetCursorPosition() with scaled objects
« on: July 21, 2015, 04:49:53 pm »
Noticed that the cursor would not position properly at the end of the entered text when I had the tk2dUITextInput embedded in a slightly scaled down parent object. The fix is to divide the extent of the renderer bounds by the lossyScale of the game object at the end of SetCursorPosition(). I split it into a var with 2 lines just for readability:

Code: [Select]
float renderBoundsRight = inputLabel.GetComponent<Renderer>().bounds.extents.x/gameObject.transform.lossyScale.x;
cursor.transform.localPosition = new Vector3(inputLabel.transform.localPosition.x + (renderBoundsRight + cursorOffset) * multiplier, cursor.transform.localPosition.y, cursor.transform.localPosition.z);

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUITextInput SetCursorPosition() with scaled objects
« Reply #1 on: July 22, 2015, 05:42:52 pm »
Hi, thanks for that. IT'll be in the next version.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUITextInput SetCursorPosition() with scaled objects
« Reply #2 on: July 23, 2015, 10:38:14 am »
Hi,

One more thing needs to be changed to work properly -
in FormatTextForDisplay

Code: [Select]

float localSpaceLabelWidth = inputLabel.GetComponent<Renderer>().bounds.size.x / inputLabel.transform.lossyScale.x;
        while (localSpaceLabelWidth > fieldLength)
        {
            modifiedText=modifiedText.Substring(1, modifiedText.Length - 1);
            inputLabel.text = modifiedText;
            inputLabel.Commit();

localSpaceLabelWidth = inputLabel.GetComponent<Renderer>().bounds.size.x / inputLabel.transform.lossyScale.x;
        }