Allow word wrapping to wrap on capital letters and underscores.

This commit is contained in:
Chandler Cox
2023-04-14 15:00:50 -05:00
parent 4bdeb26e74
commit e8aa2f922b

View File

@@ -122,6 +122,12 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
float lastWhitespaceX = 0;
bool lastMoveLine = false;
int32 lastUpperIndex = INVALID_INDEX;
float lastUpperX = 0;
int32 lastUnderscoreIndex = INVALID_INDEX;
float lastUnderscoreX = 0;
// Process each character to split text into single lines
for (int32 currentIndex = 0; currentIndex < textLength;)
{
@@ -141,6 +147,21 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
lastWhitespaceX = cursorX;
}
// Check if character is an upper case letter
const bool isUpper = StringUtils::IsUpper(currentChar);
if (isUpper && currentIndex != 0)
{
lastUpperIndex = currentIndex;
lastUpperX = cursorX;
}
const bool isUnderscore = currentChar == '_';
if (isUnderscore)
{
lastUnderscoreIndex = currentIndex;
lastUnderscoreX = cursorX;
}
// Check if it's a newline character
if (currentChar == '\n')
{
@@ -185,6 +206,20 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
currentIndex = lastWhitespaceIndex + 1;
nextCharIndex = currentIndex;
}
else if (lastUpperIndex != INVALID_INDEX)
{
cursorX = lastUpperX;
tmpLine.LastCharIndex = lastUpperIndex - 1;
currentIndex = lastUpperIndex;
nextCharIndex = currentIndex;
}
else if (lastUnderscoreIndex != INVALID_INDEX)
{
cursorX = lastUnderscoreX;
tmpLine.LastCharIndex = lastUnderscoreIndex;
currentIndex = lastUnderscoreIndex + 1;
nextCharIndex = currentIndex;
}
else
{
nextCharIndex = currentIndex;
@@ -224,6 +259,12 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
lastWhitespaceIndex = INVALID_INDEX;
lastWhitespaceX = 0;
lastUpperIndex = INVALID_INDEX;
lastUpperX = 0;
lastUnderscoreIndex = INVALID_INDEX;
lastUnderscoreX = 0;
previous.IsValid = false;
}