2D Toolkit Forum

2D Toolkit => Support => Topic started by: zblack on July 21, 2015, 04:49:53 pm

Title: tk2dUITextInput SetCursorPosition() with scaled objects
Post by: zblack 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);
Title: Re: tk2dUITextInput SetCursorPosition() with scaled objects
Post by: unikronsoftware on July 22, 2015, 05:42:52 pm
Hi, thanks for that. IT'll be in the next version.
Title: Re: tk2dUITextInput SetCursorPosition() with scaled objects
Post by: unikronsoftware 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;
        }