summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-05 20:30:26 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-05 20:30:26 +0300
commit322aea1d69a47e8080bcd0552473a5a5d66c5e1a (patch)
tree10065fb47c0ee488e3e04da3bb86b3ddaa110e2a /src/gui/widgets
parent8fda16c465f8ea9ad6c748d4a5a097ff360fe960 (diff)
downloadplus-322aea1d69a47e8080bcd0552473a5a5d66c5e1a.tar.gz
plus-322aea1d69a47e8080bcd0552473a5a5d66c5e1a.tar.bz2
plus-322aea1d69a47e8080bcd0552473a5a5d66c5e1a.tar.xz
plus-322aea1d69a47e8080bcd0552473a5a5d66c5e1a.zip
add dynamic labels string cutting.
using it in char creation dialog.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/label.cpp34
-rw-r--r--src/gui/widgets/label.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 29bd39af9..d57268bdd 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -127,3 +127,37 @@ void Label::setForegroundColorAll(const gcn::Color &color1,
mForegroundColor = color1;
mForegroundColor2 = color2;
}
+
+void Label::resizeTo(const int sz)
+{
+ const gcn::Font *const font = getFont();
+ const int pad2 = 2 * mPadding;
+ setHeight(font->getHeight() + pad2);
+
+ if (font->getWidth(mCaption) + pad2 > sz)
+ {
+ const int dots = font->getWidth("...");
+ if (dots > sz)
+ {
+ setWidth(sz);
+ return;
+ }
+ const size_t szChars = mCaption.size();
+ for (size_t f = 1; f < szChars - 1; f ++)
+ {
+ const std::string text = mCaption.substr(0, szChars - f);
+ const int width = font->getWidth(text) + dots + pad2;
+ if (width <= sz)
+ {
+ setCaption(text + "...");
+ setWidth(width);
+ return;
+ }
+ }
+ setWidth(sz);
+ }
+ else
+ {
+ setWidth(font->getWidth(mCaption) + pad2);
+ }
+}
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
index 31d75b6ff..42f07d1c2 100644
--- a/src/gui/widgets/label.h
+++ b/src/gui/widgets/label.h
@@ -68,6 +68,8 @@ class Label final : public gcn::Label, public Widget2
void setForegroundColorAll(const gcn::Color &color1,
const gcn::Color &color2);
+ void resizeTo(const int sz);
+
static Skin *mSkin;
static int mInstances;