fix: last minor text wrapping bug

This commit is contained in:
Kae 2024-04-04 15:09:40 +11:00
parent 6c896c2ef7
commit 12a28d5345
2 changed files with 7 additions and 12 deletions

View File

@ -177,7 +177,7 @@ void Chat::addMessages(List<ChatReceivedMessage> const& messages, bool showPane)
for (auto const& message : messages) {
Maybe<unsigned> wrapWidth;
if (message.portrait.empty())
wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0];
wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0] * 2;
guiContext.setFont(m_font);
guiContext.setFontSize(m_fontSize);
@ -261,7 +261,7 @@ void Chat::renderImpl() {
float messageHeight = 0;
float lineHeightMargin = + ((m_chatLineHeight * m_fontSize) - m_fontSize);
unsigned wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0];
unsigned wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0] * 2;
if (message.portrait != "") {
TextPositioning tp = {Vec2F(chatMin + m_portraitTextOffset), HorizontalAnchor::LeftAnchor, VerticalAnchor::VMidAnchor, (wrapWidth - m_portraitTextOffset[0])};

View File

@ -131,12 +131,10 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
unsigned lineCharSize = 0; // how many characters in this line ?
auto escIt = end;
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 ?
auto splitIt = end;
auto splitIt = end; // != end if we last saw a place to split the string
auto slice = [](StringView::const_iterator a, StringView::const_iterator b) -> StringView {
const char* aPtr = &*a.base();
@ -176,29 +174,26 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
++lineStartIt;
// 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') {
splitting = true;
splitWidth = linePixelWidth + charWidth; // the width of the string at
splitIt = it;
++splitIt;
splitWidth = linePixelWidth + charWidth; // the width of the string at
// the split point, i.e. after the space.
}
// 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 (splitting) {
if (splitIt != end) {
if (!textFunc(slice(lineStartIt, splitIt), lines++))
return false;
unsigned stringWidth = linePixelWidth - splitWidth;
linePixelWidth = stringWidth + charWidth; // and is as wide as the bit after the space.
lineStartIt = splitIt;
splitting = false;
lineStartIt = ++splitIt;
splitIt = end;
} else {
if (!textFunc(slice(lineStartIt, it), lines++))
return false;