- Home /
TextField moves/jumps when focused
So I've got a text field that uses a style defined like this:
GUIStyle fieldTextStyle = new GUIStyle();
fieldTextStyle.fontSize = 12;
fieldTextStyle.normal.textColor = Color.white;
fieldTextStyle.wordWrap = true;
fieldTextStyle.alignment = TextAnchor.MiddleCenter;
And called like this, inside a larger OnGUI function:
GUI.skin.settings.cursorColor = textStyle.normal.textColor;
text = GUI.TextField(rect, text, textStyle);
(textStyle is where fieldTextStyle gets stored in this particular class.)
And whenever I click on the TextField to start editing the text, the text jumps visibly, by maybe a pixel or two. When I click elsewhere to remove focus, it goes back down to its original position. If I add a texture to the background of the style, that also jumps - and since this field is meant to line up with other elements below it, there's a big black line that appears and disappears as focus changes.
The default TextField style doesn't exactly do this, but it does change the color of the text and the border around the field, and the change in the border color makes the bottom row of pixels appear black instead of dark grey as well.
What's causing this? I would think that creating a new style and applying it would wipe out weird artifacts from the default style.
Your answer
Follow this Question
Related Questions
Changing variables in real time. 2 Answers
How to use GUIStyles in OnInspectorGUI? 1 Answer
Setting up GUIStyles, best practice. 1 Answer
GUI custom textfield cursor rendering 2 Answers
Textfield Not Bound To Rect 1 Answer