From 7f6a1dfd56b0ff8f98b1077ed2a6dfcbd6f75283 Mon Sep 17 00:00:00 2001 From: Mathieu Laprise Date: Sat, 27 Dec 2014 15:10:39 -0500 Subject: [PATCH] Handle spinner custom text differently differently to fix issue #1837 problem with activation/deactivation and updategfxSlider --- src/guiengine/widgets/spinner_widget.cpp | 21 ++++++++++++++++++--- src/guiengine/widgets/spinner_widget.hpp | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/guiengine/widgets/spinner_widget.cpp b/src/guiengine/widgets/spinner_widget.cpp index 50bbc56ce..ea85906fc 100644 --- a/src/guiengine/widgets/spinner_widget.cpp +++ b/src/guiengine/widgets/spinner_widget.cpp @@ -326,6 +326,7 @@ void SpinnerWidget::addLabel(stringw label) void SpinnerWidget::setValue(const int new_value) { m_value = new_value; + m_customText = ""; if (m_graphical) { @@ -397,7 +398,14 @@ void SpinnerWidget::setActivated() Widget::setActivated(); setText(L""); - setValue( getValue() ); // Update the display + if (m_customText.empty()) + { + setValue(getValue()); // Update the display + } + else + { + setCustomText(m_customText); + } } // ----------------------------------------------------------------------------- @@ -406,14 +414,21 @@ void SpinnerWidget::setDeactivated() { Widget::setDeactivated(); + // Save it temporarary because setValue(which is uses for update in this case) overwrite it + core::stringw customText = customText; setText(L"-"); - setValue( getValue() ); // Update the display + setValue(getValue()); // Update the display + m_customText = customText; } // ----------------------------------------------------------------------------- void SpinnerWidget::setCustomText(const core::stringw& text) { - m_children[1].m_element->setText(text.c_str()); + m_customText = text; + if (m_children.size() > 0) + { + m_children[1].m_element->setText(text.c_str()); + } } diff --git a/src/guiengine/widgets/spinner_widget.hpp b/src/guiengine/widgets/spinner_widget.hpp index 09e5ea594..02a908788 100644 --- a/src/guiengine/widgets/spinner_widget.hpp +++ b/src/guiengine/widgets/spinner_widget.hpp @@ -75,6 +75,11 @@ namespace GUIEngine /** \brief Whether to wrap back to the first value when going "beyond" the last value */ bool m_wrap_around; + + /** \brief Keeps track of the custom text in spinner (a text which isn't related to a value) + * to remember it and set it back (example : when we deactivate the widget) + */ + core::stringw m_customText; /** \brief implementing method from base class Widget */ virtual EventPropagation transmitEvent(Widget* w,