Browse Source

Some fixes with caret positioning so the text doesn't scroll if just the caret is out of bounds

Marko Pintera 12 years ago
parent
commit
53331c8848
3 changed files with 14 additions and 6 deletions
  1. 11 1
      BansheeEngine/Source/BsGUIInputBox.cpp
  2. 2 2
      BansheeEngine/Source/BsGUIInputCaret.cpp
  3. 1 3
      TODO.txt

+ 11 - 1
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -340,6 +340,14 @@ namespace BansheeEngine
 		}
 		else if(ev.getType() == GUIMouseEventType::MouseDrag)
 		{
+			if(mText.size() > 0)
+				mInputCaret->moveCaretToPos(ev.getPosition());
+			else
+				mInputCaret->moveCaretToStart();
+
+			scrollTextToCaret();
+
+
 			// TODO - Update selection
 			//  - If mouse is over control, place selection marker there (make sure start < end)
 			//  - Else move the selection by a certain amount of pixels depending on drag amount
@@ -657,7 +665,9 @@ namespace BansheeEngine
 		INT32 caretBottom = caretPos.y + (INT32)caretHeight;
 
 		INT32 left = textDesc.offset.x - mTextOffset.x;
-		INT32 right = left + (INT32)textDesc.width;
+		// Include caret width here because we don't want to scroll if just the caret is outside the bounds
+		// (Possible if the text width is exactly the maximum width)
+		INT32 right = left + (INT32)textDesc.width + caretWidth; 
 		INT32 top = textDesc.offset.y - mTextOffset.y;
 		INT32 bottom = top + (INT32)textDesc.height;
 

+ 2 - 2
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -38,7 +38,7 @@ namespace BansheeEngine
 		mCaretDesc.width = 1;
 		mCaretDesc.height = getCaretHeight();
 		mCaretDesc.clipRect = Rect(-mCaretDesc.offset.x + mTextDesc.offset.x - offset.x, -mCaretDesc.offset.y + mTextDesc.offset.y - offset.y, 
-			mTextDesc.width, mTextDesc.height);
+			mTextDesc.width + 1, mTextDesc.height); // Increase clip size by 1, so we can fit the caret in case it is fully at the end of the text
 		mCaretDesc.texture = GUIManager::instance().getCaretTexture();
 
 		mCaretSprite->update(mCaretDesc);
@@ -265,7 +265,7 @@ namespace BansheeEngine
 			UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
 			UINT32 yOffset = mTextSprite->getLineDesc(lineIdx).getLineYStart();
 
-			return Int2(charRect.x + charRect.width + 1, yOffset);
+			return Int2(charRect.x + charRect.width, yOffset);
 		}
 		else
 		{

+ 1 - 3
TODO.txt

@@ -23,8 +23,6 @@ IMMEDIATE:
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 TextBox needed elements:
- - IMPORTANT: Word wrap won't work with my current approach. In a lot of places I assume lines 
-    end with a newline char but in word wrap case a lot of them wont.
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)
  - Drag mouse to update selection
  - Input caret positioning ignores kerning which means the caret is sometimes 
@@ -38,7 +36,7 @@ TextBox needed elements:
  - LATER
   - TAB between input elements
   - Context menu with copy/cut/paste
-  - Sprites. Perform clipping when fillbuffer is called? 
+  - Sprites. Perform clipping when fillbuffer is called? (Also deal with offset?)
     This way I can change clip rect without recreating the entire sprite. 
 	Which is important for text, especially when I'll be scrolling it. 
 	Plus its important for all other elements that will be inside scroll areas.