diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-28 19:14:41 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-28 19:14:41 -0700 |
commit | 7a99b87f6f5e42072fa268876795289ab75a271e (patch) | |
tree | e82dc07a67d120d76bdab826a20e4c4ab22c6d9e /src/gui/textbox.cpp | |
parent | 129245a8063f09775930b0ffff11f043c219c277 (diff) | |
download | mana-7a99b87f6f5e42072fa268876795289ab75a271e.tar.gz mana-7a99b87f6f5e42072fa268876795289ab75a271e.tar.bz2 mana-7a99b87f6f5e42072fa268876795289ab75a271e.tar.xz mana-7a99b87f6f5e42072fa268876795289ab75a271e.zip |
Finally put in the last missing wrapping case that has been missing from
the textbox class. Should now always choose the most ideal text wrap
possible.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/textbox.cpp')
-rw-r--r-- | src/gui/textbox.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index fb5a39e6..98096112 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -92,9 +92,8 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) else { if (xpos > minWidth) - { minWidth = xpos; - } + // The window wasn't big enough. Resize it and try again. if (minWidth > mMinWidth) { @@ -120,17 +119,37 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) while (spacePos != line.size()); if (text.find("\n", lastNewlinePos) != std::string::npos) - { wrappedStream << "\n"; - } + lastNewlinePos = newlinePos + 1; + + // Is the last line we're trying to text wrap longer than the minimum + // width we're trying to beat in the first place? If so, then rewrap + // using that length. + if (newlinePos == text.size()) + { + spacePos = text.rfind(" ", text.size()); + const std::string word = line.substr(spacePos + 1); + const int length = getFont()->getWidth(word); + + if ((length > xpos || length > minWidth) && mMinWidth != length) + { + mMinWidth = length; + wrappedStream.clear(); + wrappedStream.str(""); + spacePos = 0; + lastNewlinePos = 0; + newlinePos = text.find("\n", lastNewlinePos); + line = text.substr(lastNewlinePos, newlinePos - + lastNewlinePos); + } + } } while (newlinePos != text.size()); if (xpos > minWidth) - { minWidth = xpos; - } + mMinWidth = minWidth; gcn::TextBox::setText(wrappedStream.str()); |