Browse Source

Insert newline for words longer than width in WordWrapString()

pull/6706/head
staphen 2 years ago committed by Anders Jenbo
parent
commit
99bf0e4e3c
  1. 15
      Source/engine/render/text_render.cpp

15
Source/engine/render/text_render.cpp

@ -620,20 +620,27 @@ std::string WordWrapString(std::string_view text, unsigned width, GameFontTables
lineWidth += (*currentFont.sprite)[frame].width() + spacing;
}
const bool isWhitespace = IsWhitespace(codepoint);
if (isWhitespace || IsBreakAllowed(codepoint, nextCodepoint)) {
if (IsWhitespace(codepoint)) {
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = codepointLen;
lastBreakableKeep = !isWhitespace;
lastBreakableKeep = false;
continue;
}
if (lineWidth - spacing <= width) {
if (IsBreakAllowed(codepoint, nextCodepoint)) {
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = codepointLen;
lastBreakableKeep = true;
}
continue; // String is still within the limit, continue to the next symbol
}
if (lastBreakablePos == std::string_view::npos) { // Single word longer than width
continue;
lastBreakablePos = remaining.data() - begin - codepointLen;
lastBreakableLen = 0;
lastBreakableKeep = false;
}
// Break line and continue to next line

Loading…
Cancel
Save