diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-26 00:20:51 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-26 00:20:51 +0200 |
commit | eb1004715f9fa6a7700ea5165a1316f377e0b8f6 (patch) | |
tree | c24e504e123b49ff332309fe186f5b7cf3750638 | |
parent | 70985f67295f3ee9e00487621e413b11287a20bf (diff) | |
download | mana-eb1004715f9fa6a7700ea5165a1316f377e0b8f6.tar.gz mana-eb1004715f9fa6a7700ea5165a1316f377e0b8f6.tar.bz2 mana-eb1004715f9fa6a7700ea5165a1316f377e0b8f6.tar.xz mana-eb1004715f9fa6a7700ea5165a1316f377e0b8f6.zip |
Guard against an issue where forced wrapping would never succeed
In some situations, like when wrapping the "]." part after an item link,
the attempt at forced-wrapping the text never succeeded. The additional
guard "end > start" protects against these cases.
Also made some small optimizations. Removed redundant c_str() calls,
noticed by Octalot, and changed " " to ' ' for finding a space.
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index e4f0774b..b1ae5eb7 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -386,7 +386,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) // Auto wrap mode if (mMode == AUTO_WRAP && - (x + font->getWidth(part.c_str()) + 10) > getWidth()) + (x + font->getWidth(part) + 10) > getWidth()) { bool forced = false; char const *hyphen = "~"; @@ -399,14 +399,14 @@ void BrowserBox::draw(gcn::Graphics *graphics) do { if (!forced) - end = row.rfind(" ", end); + end = row.rfind(' ', end); // Check if we have to (stupidly) force-wrap if (end == std::string::npos || end <= start) { forced = true; end = row.size(); - x += hyphenWidth * 2; // Account for the wrap-notifier + x += hyphenWidth; // Account for the wrap-notifier continue; } @@ -416,7 +416,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) end--; // And then to the last byte of the previous one part = row.substr(start, end - start + 1); - } while ((x + font->getWidth(part.c_str()) + 10) > getWidth()); + } while (end > start && (x + font->getWidth(part) + 10) > getWidth()); if (forced) { @@ -432,7 +432,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) wrappedLines++; } font->drawString(graphics, part, x, y); - x += font->getWidth(part.c_str()); + x += font->getWidth(part); } y += font->getHeight(); setHeight((mTextRows.size() + wrappedLines) * font->getHeight()); |