Browse Source

Fixed an issue where input box caret was causing the text to flicker up and down by one pixel on any input

BearishSun 10 years ago
parent
commit
7edbbf4ef2
1 changed files with 5 additions and 2 deletions
  1. 5 2
      BansheeEngine/Source/BsGUIInputBox.cpp

+ 5 - 2
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -956,8 +956,6 @@ namespace BansheeEngine
 		Vector2I caretPos = gGUIManager().getInputCaretTool()->getCaretPosition(textOffset);
 		Vector2I caretPos = gGUIManager().getInputCaretTool()->getCaretPosition(textOffset);
 		UINT32 caretHeight = gGUIManager().getInputCaretTool()->getCaretHeight();
 		UINT32 caretHeight = gGUIManager().getInputCaretTool()->getCaretHeight();
 		UINT32 caretWidth = 1;
 		UINT32 caretWidth = 1;
-		INT32 caretRight = caretPos.x + (INT32)caretWidth;
-		INT32 caretBottom = caretPos.y + (INT32)caretHeight;
 
 
 		INT32 left = textOffset.x - mTextOffset.x;
 		INT32 left = textOffset.x - mTextOffset.x;
 		// Include caret width here because we don't want to scroll if just the caret is outside the bounds
 		// Include caret width here because we don't want to scroll if just the caret is outside the bounds
@@ -966,6 +964,11 @@ namespace BansheeEngine
 		INT32 top = textOffset.y - mTextOffset.y;
 		INT32 top = textOffset.y - mTextOffset.y;
 		INT32 bottom = top + (INT32)textDesc.height;
 		INT32 bottom = top + (INT32)textDesc.height;
 
 
+		// If caret is too high to display we don't want the offset to keep adjusting itself
+		caretHeight = std::min(caretHeight, (UINT32)(bottom - top));
+		INT32 caretRight = caretPos.x + (INT32)caretWidth;
+		INT32 caretBottom = caretPos.y + (INT32)caretHeight;
+
 		Vector2I offset;
 		Vector2I offset;
 		if(caretPos.x < left)
 		if(caretPos.x < left)
 		{
 		{