mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-06 04:33:49 +01:00
UI: Fix text wrap when kerning adjusts spaces.
This was happening for some setting info messages. The sum of the word lengths didn't actually match the line length, because more space was added between some words.
This commit is contained in:
1 parent
4e49992e5c
commit
977f75ce1e
2 files changed
+16
-7
No files matched your search
@@ -82,6 +82,7 @@ void WordWrapper::WrapBeforeWord() {
|
||||
out_[out_.size() - 1] = '-';
|
||||
}
|
||||
out_ += "\n";
|
||||
lastLineStart_ = (int)out_.size();
|
||||
x_ = 0.0f;
|
||||
forceEarlyWrap_ = false;
|
||||
}
|
||||
@@ -93,6 +94,13 @@ void WordWrapper::AppendWord(int endIndex, bool addNewline) {
|
||||
out_ += std::string(str_ + lastIndex_, endIndex - lastIndex_);
|
||||
if (addNewline) {
|
||||
out_ += "\n";
|
||||
lastLineStart_ = (int)out_.size();
|
||||
} else {
|
||||
// We may have appended a newline - check.
|
||||
size_t pos = out_.find_last_of("\n", lastLineStart_);
|
||||
if (pos != out_.npos) {
|
||||
lastLineStart_ = (int)pos;
|
||||
}
|
||||
}
|
||||
lastIndex_ = endIndex;
|
||||
}
|
||||
@@ -135,9 +143,8 @@ void WordWrapper::Wrap() {
|
||||
// Is this the end of a word (space)?
|
||||
if (wordWidth_ > 0.0f && IsSpace(c)) {
|
||||
AppendWord(afterIndex, false);
|
||||
// We include the space in the x increase.
|
||||
// If the space takes it over, we'll wrap on the next word.
|
||||
x_ += newWordWidth;
|
||||
// To account for kerning around spaces, we recalculate the entire line width.
|
||||
x_ = MeasureWidth(out_.c_str() + lastLineStart_, out_.size() - lastLineStart_);
|
||||
wordWidth_ = 0.0f;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
class WordWrapper {
|
||||
public:
|
||||
WordWrapper(const char *str, float maxW)
|
||||
: str_(str), maxW_(maxW), lastIndex_(0), x_(0.0f), forceEarlyWrap_(false) {
|
||||
: str_(str), maxW_(maxW) {
|
||||
}
|
||||
|
||||
std::string Wrapped();
|
||||
@@ -25,11 +25,13 @@ protected:
|
||||
const float maxW_;
|
||||
std::string out_;
|
||||
// Index of last output / start of current word.
|
||||
int lastIndex_;
|
||||
int lastIndex_ = 0;
|
||||
// Index of last line start.
|
||||
int lastLineStart_ = 0;
|
||||
// Position the current word starts at.
|
||||
float x_;
|
||||
float x_ = 0.0f;
|
||||
// Most recent width of word since last index.
|
||||
float wordWidth_;
|
||||
// Force the next word to cut partially and wrap.
|
||||
bool forceEarlyWrap_;
|
||||
bool forceEarlyWrap_ = false;
|
||||
};
|
||||
Reference in new issue
Block a user