Просмотр исходного кода

When word wrapping text with word break, use only word break if word wrap is not possible

Marko Pintera 10 лет назад
Родитель
Сommit
3c85332fe8
2 измененных файлов с 31 добавлено и 10 удалено
  1. 31 6
      BansheeCore/Source/BsTextData.cpp
  2. 0 4
      MBansheeEditor/ProjectWindow.cs

+ 31 - 6
BansheeCore/Source/BsTextData.cpp

@@ -405,7 +405,11 @@ namespace BansheeEngine
 
 					if (!atWordBoundary) // Need to break word into multiple pieces, or move it to next line
 					{
-						if (wordBreak)
+						UINT32 lastWordIdx = curLine->removeLastWord();
+						TextWord& lastWord = WordBuffer[lastWordIdx];
+
+						bool wordFits = lastWord.calcWidthWithChar(charDesc) <= width;
+						if (wordFits)
 						{
 							curLine->finalize(false);
 
@@ -413,14 +417,14 @@ namespace BansheeEngine
 							curLine = &LineBuffer[curLineIdx];
 
 							curHeight += mFontData->fontDesc.lineHeight;
+
+							curLine->addWord(lastWordIdx, lastWord);
 						}
 						else
 						{
-							UINT32 lastWordIdx = curLine->removeLastWord();
-							TextWord& lastWord = WordBuffer[lastWordIdx];
-
-							if (lastWord.calcWidthWithChar(charDesc) <= width) // If the word fits, attempt to add it to a new line
+							if (wordBreak)
 							{
+								curLine->addWord(lastWordIdx, lastWord);
 								curLine->finalize(false);
 
 								curLineIdx = allocLine(this);
@@ -428,10 +432,31 @@ namespace BansheeEngine
 
 								curHeight += mFontData->fontDesc.lineHeight;
 							}
+							else
+							{
+								if (!curLine->isEmpty()) // Add new line unless current line is empty (to avoid constantly moving the word to new lines)
+								{
+									curLine->finalize(false);
 
-							curLine->addWord(lastWordIdx, lastWord);
+									curLineIdx = allocLine(this);
+									curLine = &LineBuffer[curLineIdx];
+
+									curHeight += mFontData->fontDesc.lineHeight;
+								}
+
+								curLine->addWord(lastWordIdx, lastWord);
+							}
 						}
 					}
+					else
+					{
+						curLine->finalize(false);
+
+						curLineIdx = allocLine(this);
+						curLine = &LineBuffer[curLineIdx];
+
+						curHeight += mFontData->fontDesc.lineHeight;
+					}
 				}
 			}
 

+ 0 - 4
MBansheeEditor/ProjectWindow.cs

@@ -384,7 +384,6 @@ namespace BansheeEditor
             overlayBtn.OnDoubleClick += () => OnEntryDoubleClicked(entry.Path);
 
             overlayPanel.AddElement(overlayBtn);
-            Debug.Log("OVERLAY BTN: " + entryButtonBounds + " - " + overlayBtn.Bounds);
 
             if (cutPaths.Contains(entry.Path))
             {
@@ -411,7 +410,6 @@ namespace BansheeEditor
 
         private void OnEntryClicked(string path)
         {
-            Debug.Log("ENTRY CLICKED");
             Select(new List<string> { path });
 
             Selection.resourcePaths = new string[] {path};
@@ -428,8 +426,6 @@ namespace BansheeEditor
 
         private void OnCatchAllClicked()
         {
-            Debug.Log("CATCH ALL CLICKED");
-
             Select(new List<string> { });
 
             Selection.resourcePaths = new string[] { };