fix: last minor text wrapping bug
This commit is contained in:
parent
6c896c2ef7
commit
12a28d5345
@ -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] - m_chatLogPadding[0];
|
wrapWidth = m_chatLog->size()[0] - m_chatLogPadding[0] * 2;
|
||||||
|
|
||||||
guiContext.setFont(m_font);
|
guiContext.setFont(m_font);
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
@ -261,7 +261,7 @@ void Chat::renderImpl() {
|
|||||||
|
|
||||||
float messageHeight = 0;
|
float messageHeight = 0;
|
||||||
float lineHeightMargin = + ((m_chatLineHeight * m_fontSize) - m_fontSize);
|
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 != "") {
|
if (message.portrait != "") {
|
||||||
TextPositioning tp = {Vec2F(chatMin + m_portraitTextOffset), HorizontalAnchor::LeftAnchor, VerticalAnchor::VMidAnchor, (wrapWidth - m_portraitTextOffset[0])};
|
TextPositioning tp = {Vec2F(chatMin + m_portraitTextOffset), HorizontalAnchor::LeftAnchor, VerticalAnchor::VMidAnchor, (wrapWidth - m_portraitTextOffset[0])};
|
||||||
|
@ -131,12 +131,10 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
|
|||||||
unsigned lineCharSize = 0; // how many characters in this line ?
|
unsigned lineCharSize = 0; // how many characters in this line ?
|
||||||
|
|
||||||
auto escIt = end;
|
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 ?
|
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 ?
|
||||||
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 {
|
auto slice = [](StringView::const_iterator a, StringView::const_iterator b) -> StringView {
|
||||||
const char* aPtr = &*a.base();
|
const char* aPtr = &*a.base();
|
||||||
@ -176,29 +174,26 @@ bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapText
|
|||||||
++lineStartIt;
|
++lineStartIt;
|
||||||
// next line starts after the CR 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;
|
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') {
|
||||||
splitting = true;
|
|
||||||
splitWidth = linePixelWidth + charWidth; // the width of the string at
|
|
||||||
splitIt = it;
|
splitIt = it;
|
||||||
++splitIt;
|
splitWidth = linePixelWidth + charWidth; // the width of the string at
|
||||||
// the split point, i.e. after the space.
|
// the split point, i.e. after the space.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (splitting) {
|
if (splitIt != end) {
|
||||||
if (!textFunc(slice(lineStartIt, splitIt), lines++))
|
if (!textFunc(slice(lineStartIt, splitIt), lines++))
|
||||||
return false;
|
return false;
|
||||||
unsigned stringWidth = linePixelWidth - splitWidth;
|
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.
|
||||||
lineStartIt = splitIt;
|
lineStartIt = ++splitIt;
|
||||||
splitting = false;
|
splitIt = end;
|
||||||
} else {
|
} else {
|
||||||
if (!textFunc(slice(lineStartIt, it), lines++))
|
if (!textFunc(slice(lineStartIt, it), lines++))
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user