Fix potential issue with translations : I was changing the label in a button. In english it so happened that the second label was shorter than the first so it fit; but this is not the case in all translations. So when changing the button label, make sure the button is large enough to display the new string

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7592 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-02-03 00:52:42 +00:00
parent 9b7fdf3b5b
commit 7f7cce4186
3 changed files with 46 additions and 25 deletions

View File

@ -204,16 +204,7 @@ namespace GUIEngine
/** Whether to reserve an ID in 'm_reserved_id' when widget is added */
bool m_reserve_id;
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 0; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 0; }
/** Type of this widget */
WidgetType m_type;
@ -369,6 +360,15 @@ namespace GUIEngine
*/
irr::gui::IGUIElement* getIrrlichtElement() { return m_element; }
void moveIrrlichtElement()
{
if (m_element != NULL)
{
m_element->setRelativePosition( irr::core::recti(irr::core::position2di(m_x, m_y),
irr::core::dimension2di(m_w, m_h) ) );
}
}
bool isSameIrrlichtWidgetAs(const Widget* ref) const { return m_element == ref->m_element; }
/**
@ -534,6 +534,14 @@ namespace GUIEngine
bool searchInsideMe() const { return m_check_inside_me; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 0; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 0; }
/**
* \}
*/

View File

@ -37,14 +37,6 @@ namespace GUIEngine
*/
class ButtonWidget : public Widget
{
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 35; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 4; }
public:
ButtonWidget();
virtual ~ButtonWidget() {}
@ -53,6 +45,14 @@ namespace GUIEngine
/** Change the label on the button */
void setLabel(const irr::core::stringw &label);
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getWidthNeededAroundLabel() const { return 35; }
/** When inferring widget size from its label length, this method will be called to
* if/how much space must be added to the raw label's size for the widget to be large enough */
virtual int getHeightNeededAroundLabel() const { return 4; }
};
}

View File

@ -19,6 +19,7 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/CGUISpriteBank.h"
#include "guiengine/scalable_font.hpp"
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "guiengine/widgets/button_widget.hpp"
@ -68,13 +69,17 @@ void OptionsScreenInput2::init()
ButtonWidget* deleteBtn = this->getWidget<ButtonWidget>("delete");
if (m_config->getType() != DEVICE_CONFIG_TYPE_KEYBOARD)
{
//I18N: button to disable a gamepad configuration
if (m_config->isEnabled()) deleteBtn->setLabel(_("Disable Device"));
//I18N: button to enable a gamepad configuration
else deleteBtn->setLabel(_("Enable Device"));
//deleteBtn->setDeactivated();
core::stringw label = (m_config->isEnabled() ? //I18N: button to disable a gamepad configuration
_("Disable Device")
: //I18N: button to enable a gamepad configuration
_("Enable Device"));
// Make sure button is wide enough as the text is being changed away from the original value
core::dimension2d<u32> size = GUIEngine::getFont()->getDimension(label.c_str());
const int needed = size.Width + deleteBtn->getWidthNeededAroundLabel();
if (deleteBtn->m_w < needed) deleteBtn->m_w = needed;
deleteBtn->setLabel(label);
}
else
{
@ -91,6 +96,14 @@ void OptionsScreenInput2::init()
}
}
// Make the two buttons the same length, not strictly needed but will look nicer...
ButtonWidget* backBtn = this->getWidget<ButtonWidget>("back_to_device_list");
if (backBtn->m_w < deleteBtn->m_w) backBtn->m_w = deleteBtn->m_w;
else deleteBtn->m_w = backBtn->m_w;
backBtn->moveIrrlichtElement();
deleteBtn->moveIrrlichtElement();
LabelWidget* label = this->getWidget<LabelWidget>("title");
label->setText( m_config->getName().c_str() );