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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-04 15:09:40 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-04 15:09:40 +1100
commit12a28d5345b621712d3294dca7dc2d296fd04bda (patch)
tree921a71277c5430390e82799c042ea514b1eeeed6
parent6c896c2ef79c1740d7dea6fae95518c768de8931 (diff)
fix: last minor text wrapping bug
-rw-r--r--source/frontend/StarChat.cpp4
-rw-r--r--source/rendering/StarTextPainter.cpp15
2 files changed, 7 insertions, 12 deletions
diff --git a/source/frontend/StarChat.cpp b/source/frontend/StarChat.cpp
index 9c38b9b..688bf4a 100644
--- a/source/frontend/StarChat.cpp
+++ b/source/frontend/StarChat.cpp
@@ -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])};
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp
index 68ab6d3..9891ad6 100644
--- a/source/rendering/StarTextPainter.cpp
+++ b/source/rendering/StarTextPainter.cpp
@@ -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;