Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/rendering
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-03 12:19:55 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-03 12:19:55 +1100
commitbe676518f4639250376842db7e48e5aaeaad9424 (patch)
tree66d60af4f426cdc0a6661dfda1b55433d53d50d7 /source/rendering
parent662f12da9624435b1850b424817879f12b7a30b2 (diff)
fix rare text wrapping bug in the chat box
also removed unnecessary leftover variables from when text wrapping used to always create a StringList
Diffstat (limited to 'source/rendering')
-rw-r--r--source/rendering/StarTextPainter.cpp32
1 files changed, 10 insertions, 22 deletions
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp
index 58b5cbc..68ab6d3 100644
--- a/source/rendering/StarTextPainter.cpp
+++ b/source/rendering/StarTextPainter.cpp
@@ -127,13 +127,12 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
auto it = text.begin();
auto end = text.end();
- unsigned lineStart = 0; // Where does this line start ?
unsigned linePixelWidth = 0; // How wide is this line so far
unsigned lineCharSize = 0; // how many characters in this line ?
auto escIt = end;
- unsigned splitPos = 0; // Where did we last see a place to split the string ?
+ bool splitting = false; // Did we last see a place to split the string ?
unsigned splitWidth = 0; // How wide was the string there ?
auto lineStartIt = it; // Where does this line start ?
@@ -173,17 +172,17 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
if (!textFunc(slice(lineStartIt, it), lines++))
return false;
- lineStart += lineCharSize;
lineStartIt = it;
++lineStartIt;
-
- lineCharSize = linePixelWidth = splitPos = 0; // ...with no characters in it and no known splits.
+ // next line starts after the CR with no characters in it and no known splits.
+ lineCharSize = linePixelWidth = 0;
+ splitting = false;
} else {
int charWidth = glyphWidth(character);
// is it a place where we might want to split the line ?
if (character == ' ' || character == '\t') {
- splitPos = lineStart + lineCharSize; // this is the character after the space.
+ splitting = true;
splitWidth = linePixelWidth + charWidth; // the width of the string at
splitIt = it;
++splitIt;
@@ -193,29 +192,18 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
// would the line be too long if we render this next character ?
if (wrapWidth && (linePixelWidth + charWidth) > *wrapWidth) {
// did we find somewhere to split the line ?
- if (splitPos) {
+ if (splitting) {
if (!textFunc(slice(lineStartIt, splitIt), lines++))
return false;
-
- unsigned stringEnd = lineStart + lineCharSize;
- lineCharSize = stringEnd - splitPos; // next line has the characters after the space.
-
- unsigned stringWidth = (linePixelWidth - splitWidth);
+ unsigned stringWidth = linePixelWidth - splitWidth;
linePixelWidth = stringWidth + charWidth; // and is as wide as the bit after the space.
-
- lineStart = splitPos;
lineStartIt = splitIt;
-
- splitPos = 0;
+ splitting = false;
} else {
if (!textFunc(slice(lineStartIt, it), lines++))
return false;
-
- lineStart += lineCharSize - 1;
- lineStartIt = it; // include that character on the next line.
-
-
- lineCharSize = 1; // next line has that character in
+ lineStartIt = it; // include that character on the next line.
+ lineCharSize = 1; // next line has that character in
linePixelWidth = charWidth; // and is as wide as that character
}
} else {