diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-05 20:26:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-05 20:31:40 +0300 |
commit | 4e6f98cfd788965bd382f1722e2a5d895dda3bc6 (patch) | |
tree | 12b6195bbc66b49389f65d8c4831cd259e3429bc /src/gui/widgets/label.cpp | |
parent | 322aea1d69a47e8080bcd0552473a5a5d66c5e1a (diff) | |
download | ManaVerse-4e6f98cfd788965bd382f1722e2a5d895dda3bc6.tar.gz ManaVerse-4e6f98cfd788965bd382f1722e2a5d895dda3bc6.tar.bz2 ManaVerse-4e6f98cfd788965bd382f1722e2a5d895dda3bc6.tar.xz ManaVerse-4e6f98cfd788965bd382f1722e2a5d895dda3bc6.zip |
Add support for min and max label resize size.
Using it in character selection dialog.
Diffstat (limited to 'src/gui/widgets/label.cpp')
-rw-r--r-- | src/gui/widgets/label.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index d57268bdd..50bd3ad41 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -128,18 +128,18 @@ void Label::setForegroundColorAll(const gcn::Color &color1, mForegroundColor2 = color2; } -void Label::resizeTo(const int sz) +void Label::resizeTo(const int maxSize, const int minSize) { const gcn::Font *const font = getFont(); const int pad2 = 2 * mPadding; setHeight(font->getHeight() + pad2); - if (font->getWidth(mCaption) + pad2 > sz) + if (font->getWidth(mCaption) + pad2 > maxSize) { const int dots = font->getWidth("..."); - if (dots > sz) + if (dots > maxSize) { - setWidth(sz); + setWidth(maxSize); return; } const size_t szChars = mCaption.size(); @@ -147,17 +147,20 @@ void Label::resizeTo(const int sz) { const std::string text = mCaption.substr(0, szChars - f); const int width = font->getWidth(text) + dots + pad2; - if (width <= sz) + if (width <= maxSize) { setCaption(text + "..."); setWidth(width); return; } } - setWidth(sz); + setWidth(maxSize); } else { - setWidth(font->getWidth(mCaption) + pad2); + int sz = font->getWidth(mCaption) + pad2; + if (sz < minSize) + sz = minSize; + setWidth(sz); } } |