Browse Source

Improved caret placement so it can be placed before the character

Marko Pintera 12 years ago
parent
commit
239daf2a6a
2 changed files with 10 additions and 3 deletions
  1. 10 1
      BansheeEngine/Source/BsGUIInputBox.cpp
  2. 0 2
      TODO.txt

+ 10 - 1
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -307,7 +307,16 @@ namespace BansheeEngine
 			mImageDesc.texture = mStyle->active.texture;
 
 			if(mText.size() > 0)
-				showCaret(mTextSprite->getCharIdxAtPos(ev.getPosition()) +  1);
+			{
+				UINT32 charIdx = mTextSprite->getCharIdxAtPos(ev.getPosition());
+				Rect charRect = mTextSprite->getCharRect(charIdx);
+
+				float xCenter = charRect.x + charRect.width * 0.5f;
+				if(ev.getPosition().x <= xCenter)
+					showCaret(charIdx);
+				else
+					showCaret(charIdx + 1);
+			}
 			else
 				showCaret(0);
 

+ 0 - 2
TODO.txt

@@ -26,8 +26,6 @@ IMMEDIATE:
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 TextBox needed elements:
- - Space doesn't register as a character which means I won't be able to place input caret if the last character is a space
-   - Make spaces inivisble characters?
  - Clicking to the left of a letter should move the cursor to position BEFORE the letter, 
    and clicking to the right should move it to the position AFTER the letter. Right now 
    it is always moved after which makes it impossible to move the cursor before the first letter.