From 3a149c5a786ffaac19680de2412a15fa090e3722 Mon Sep 17 00:00:00 2001 From: auria Date: Thu, 9 Dec 2010 02:06:44 +0000 Subject: [PATCH] Reduce font size for long GP names to avoid clipping (long translations can still cause clipping though) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6912 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/widgets/icon_button_widget.cpp | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/guiengine/widgets/icon_button_widget.cpp b/src/guiengine/widgets/icon_button_widget.cpp index 4a85ad12b..58dee07c6 100644 --- a/src/guiengine/widgets/icon_button_widget.cpp +++ b/src/guiengine/widgets/icon_button_widget.cpp @@ -17,6 +17,7 @@ #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" +#include "guiengine/scalable_font.hpp" #include "guiengine/widgets/icon_button_widget.hpp" #include "io/file_manager.hpp" @@ -127,6 +128,13 @@ void IconButtonWidget::add() m_label->setTextAlignment(EGUIA_CENTER, EGUIA_UPPERLEFT); m_label->setTabStop(false); m_label->setNotClipped(true); + + const int max_w = m_label->getAbsolutePosition().getWidth(); + if (!word_wrap && + (int)GUIEngine::getFont()->getDimension(message.c_str()).Width > max_w + 4) // arbitrarily allow for 4 pixels + { + m_label->setOverrideFont( GUIEngine::getSmallFont() ); + } } // ---- IDs @@ -193,4 +201,17 @@ void IconButtonWidget::setLabel(stringw new_label) if (m_label == NULL) return; m_label->setText( new_label.c_str() ); + + const bool word_wrap = (m_properties[PROP_WORD_WRAP] == "true"); + const int max_w = m_label->getAbsolutePosition().getWidth(); + + if (!word_wrap && + (int)GUIEngine::getFont()->getDimension(new_label.c_str()).Width > max_w + 4) // arbitrarily allow for 4 pixels + { + m_label->setOverrideFont( GUIEngine::getSmallFont() ); + } + else + { + m_label->setOverrideFont( NULL ); + } }