From 92d13cc05b1f841d2e404cbfa781bbeb021ced32 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 25 Sep 2021 09:41:11 -0700 Subject: [PATCH] UI: Cleanup double ellipsis issues. We mostly only use FLAG_ELLIPSIZE_TEXT in PPGe, but it wasn't behaving well in some cases. --- Common/Data/Text/WrapText.cpp | 10 ++++++---- Common/Data/Text/WrapText.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Common/Data/Text/WrapText.cpp b/Common/Data/Text/WrapText.cpp index abae02352d..13b84fd85e 100644 --- a/Common/Data/Text/WrapText.cpp +++ b/Common/Data/Text/WrapText.cpp @@ -91,14 +91,16 @@ bool WordWrapper::WrapBeforeWord() { } } if (flags_ & FLAG_ELLIPSIZE_TEXT) { - if (x_ + wordWidth_ > maxW_) { + const bool hasEllipsis = out_.size() > 3 && out_.substr(out_.size() - 3) == "..."; + if (x_ + wordWidth_ > maxW_ && !hasEllipsis) { if (!out_.empty() && IsSpace(out_[out_.size() - 1])) { out_[out_.size() - 1] = '.'; out_ += ".."; } else { out_ += "..."; } - x_ = maxW_; + x_ += ellipsisWidth_; + skipNextWord_ = true; } } return false; @@ -119,7 +121,7 @@ void WordWrapper::AppendWord(int endIndex, bool addNewline) { } // This will include the newline. - if (x_ <= maxW_) { + if (x_ <= maxW_ && !skipNextWord_) { out_.append(str_ + lastWordStartIndex, str_ + endIndex); } else { scanForNewline_ = true; @@ -222,7 +224,7 @@ void WordWrapper::Wrap() { } if ((flags_ & FLAG_ELLIPSIZE_TEXT) && wordWidth_ > 0.0f && x_ + newWordWidth + ellipsisWidth_ > maxW_) { - if ((flags_ & FLAG_WRAP_TEXT) == 0) { + if ((flags_ & FLAG_WRAP_TEXT) == 0 && x_ + wordWidth_ + ellipsisWidth_ <= maxW_) { // Now, add the word so far (without this latest character) and show the ellipsis. AppendWord(beforeIndex, true); if (lastLineStart_ != out_.size()) { diff --git a/Common/Data/Text/WrapText.h b/Common/Data/Text/WrapText.h index 554210e3cf..dbb233ab7a 100644 --- a/Common/Data/Text/WrapText.h +++ b/Common/Data/Text/WrapText.h @@ -40,4 +40,6 @@ protected: bool forceEarlyWrap_ = false; // Skip all characters until the next newline. bool scanForNewline_ = false; + // Skip the next word, replaced with ellipsis. + bool skipNextWord_ = false; };