fix rare text wrapping bug in the chat box
also removed unnecessary leftover variables from when text wrapping used to always create a StringList
This commit is contained in:
parent
662f12da96
commit
be676518f4
@ -177,7 +177,7 @@ void Chat::addMessages(List<ChatReceivedMessage> const& messages, bool showPane)
|
|||||||
for (auto const& message : messages) {
|
for (auto const& message : messages) {
|
||||||
Maybe<unsigned> wrapWidth;
|
Maybe<unsigned> wrapWidth;
|
||||||
if (message.portrait.empty())
|
if (message.portrait.empty())
|
||||||
wrapWidth = m_chatLog->size()[0];
|
wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0];
|
||||||
|
|
||||||
guiContext.setFont(m_font);
|
guiContext.setFont(m_font);
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
|
@ -127,13 +127,12 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
|
|||||||
auto it = text.begin();
|
auto it = text.begin();
|
||||||
auto end = text.end();
|
auto end = text.end();
|
||||||
|
|
||||||
unsigned lineStart = 0; // Where does this line start ?
|
|
||||||
unsigned linePixelWidth = 0; // How wide is this line so far
|
unsigned linePixelWidth = 0; // How wide is this line so far
|
||||||
unsigned lineCharSize = 0; // how many characters in this line ?
|
unsigned lineCharSize = 0; // how many characters in this line ?
|
||||||
|
|
||||||
auto escIt = end;
|
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 ?
|
unsigned splitWidth = 0; // How wide was the string there ?
|
||||||
|
|
||||||
auto lineStartIt = it; // Where does this line start ?
|
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++))
|
if (!textFunc(slice(lineStartIt, it), lines++))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
lineStart += lineCharSize;
|
|
||||||
lineStartIt = it;
|
lineStartIt = it;
|
||||||
++lineStartIt;
|
++lineStartIt;
|
||||||
|
// next line starts after the CR with no characters in it and no known splits.
|
||||||
lineCharSize = linePixelWidth = splitPos = 0; // ...with no characters in it and no known splits.
|
lineCharSize = linePixelWidth = 0;
|
||||||
|
splitting = false;
|
||||||
} else {
|
} else {
|
||||||
int charWidth = glyphWidth(character);
|
int charWidth = glyphWidth(character);
|
||||||
|
|
||||||
// is it a place where we might want to split the line ?
|
// is it a place where we might want to split the line ?
|
||||||
if (character == ' ' || character == '\t') {
|
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
|
splitWidth = linePixelWidth + charWidth; // the width of the string at
|
||||||
splitIt = it;
|
splitIt = it;
|
||||||
++splitIt;
|
++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 ?
|
// would the line be too long if we render this next character ?
|
||||||
if (wrapWidth && (linePixelWidth + charWidth) > *wrapWidth) {
|
if (wrapWidth && (linePixelWidth + charWidth) > *wrapWidth) {
|
||||||
// did we find somewhere to split the line ?
|
// did we find somewhere to split the line ?
|
||||||
if (splitPos) {
|
if (splitting) {
|
||||||
if (!textFunc(slice(lineStartIt, splitIt), lines++))
|
if (!textFunc(slice(lineStartIt, splitIt), lines++))
|
||||||
return false;
|
return false;
|
||||||
|
unsigned stringWidth = linePixelWidth - splitWidth;
|
||||||
unsigned stringEnd = lineStart + lineCharSize;
|
|
||||||
lineCharSize = stringEnd - splitPos; // next line has the characters after the space.
|
|
||||||
|
|
||||||
unsigned stringWidth = (linePixelWidth - splitWidth);
|
|
||||||
linePixelWidth = stringWidth + charWidth; // and is as wide as the bit after the space.
|
linePixelWidth = stringWidth + charWidth; // and is as wide as the bit after the space.
|
||||||
|
|
||||||
lineStart = splitPos;
|
|
||||||
lineStartIt = splitIt;
|
lineStartIt = splitIt;
|
||||||
|
splitting = false;
|
||||||
splitPos = 0;
|
|
||||||
} else {
|
} else {
|
||||||
if (!textFunc(slice(lineStartIt, it), lines++))
|
if (!textFunc(slice(lineStartIt, it), lines++))
|
||||||
return false;
|
return false;
|
||||||
|
lineStartIt = it; // include that character on the next line.
|
||||||
lineStart += lineCharSize - 1;
|
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
|
linePixelWidth = charWidth; // and is as wide as that character
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user