small improvements regarding widget collapsing (#3666)

* small improvements regarding widget collapsing

* moved variables initialization to widget.cpp constructor
This commit is contained in:
Mrxx99 2018-12-31 12:12:08 +01:00 committed by Deve
parent 17b83ac321
commit 8cba880ef9
2 changed files with 16 additions and 4 deletions

View File

@ -76,6 +76,8 @@ Widget::Widget(WidgetType type, bool reserve_id)
m_supports_multiplayer = false; m_supports_multiplayer = false;
m_is_bounding_box_round = false; m_is_bounding_box_round = false;
m_has_tooltip = false; m_has_tooltip = false;
m_uncollapsed_height = 0;
m_is_collapsed = false;
m_absolute_x = m_absolute_y = m_absolute_w = m_absolute_h = -1; m_absolute_x = m_absolute_y = m_absolute_w = m_absolute_h = -1;
m_relative_x = m_relative_y = m_relative_w = m_relative_h = -1; m_relative_x = m_relative_y = m_relative_w = m_relative_h = -1;
@ -344,11 +346,12 @@ void Widget::setVisible(bool visible)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Widget::setCollapsed(bool collapsed, Screen* calling_screen) void Widget::setCollapsed(const bool collapsed, Screen* calling_screen)
{ {
// check for height > 0 to not loose height of widget in uncollapsed state // check for height > 0 to not loose height of widget in uncollapsed state
// if widget is set to collapse twice. // if widget is set to collapse twice.
if (collapsed && m_h > 0) // the check for m_is_collapsed allows to save a height of 0 if widget was not collapsed
if (collapsed && (m_h > 0 || !m_is_collapsed))
m_uncollapsed_height = m_h; m_uncollapsed_height = m_h;
setCollapsed(collapsed, m_uncollapsed_height, calling_screen); setCollapsed(collapsed, m_uncollapsed_height, calling_screen);
@ -356,7 +359,7 @@ void Widget::setCollapsed(bool collapsed, Screen* calling_screen)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Widget::setCollapsed(bool collapsed, int uncollapsed_height, Screen* calling_screen) void Widget::setCollapsed(const bool collapsed, const int uncollapsed_height, Screen* calling_screen)
{ {
m_uncollapsed_height = uncollapsed_height; m_uncollapsed_height = uncollapsed_height;
@ -367,6 +370,8 @@ void Widget::setCollapsed(bool collapsed, int uncollapsed_height, Screen* callin
else else
m_properties[GUIEngine::PROP_HEIGHT] = StringUtils::toString(m_uncollapsed_height); m_properties[GUIEngine::PROP_HEIGHT] = StringUtils::toString(m_uncollapsed_height);
m_is_collapsed = collapsed;
if (calling_screen != NULL) if (calling_screen != NULL)
calling_screen->calculateLayout(); calling_screen->calculateLayout();
} }

View File

@ -276,10 +276,12 @@ namespace GUIEngine
bool m_has_tooltip; bool m_has_tooltip;
irr::core::stringw m_tooltip_text; irr::core::stringw m_tooltip_text;
/** height of the widget before it was collapsed (only set if widget got collapsed) */ /** height of the widget before it was collapsed (only set if widget got collapsed) */
int m_uncollapsed_height; int m_uncollapsed_height;
/** A flag to indicate whether this widget got collapsed. */
bool m_is_collapsed;
public: public:
/** /**
@ -354,6 +356,7 @@ namespace GUIEngine
/** /**
* \brief Sets the widget (and its children, if any) collapsed or not. * \brief Sets the widget (and its children, if any) collapsed or not.
* !!! Note: this has to be called inside beforeAddingWidget() !!! * !!! Note: this has to be called inside beforeAddingWidget() !!!
* Pass in the screen to get (the necessary) calculate Layout automatically called.
* This will also set the widget invisible depending of collapsed state. * This will also set the widget invisible depending of collapsed state.
* Note that setting a widget invisible implicitely calls setDeactivated(), and setting * Note that setting a widget invisible implicitely calls setDeactivated(), and setting
* it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls, * it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls,
@ -364,6 +367,7 @@ namespace GUIEngine
/** /**
* \brief Sets the widget (and its children, if any) collapsed or not. * \brief Sets the widget (and its children, if any) collapsed or not.
* !!! Note: this has to be called inside beforeAddingWidget() !!! * !!! Note: this has to be called inside beforeAddingWidget() !!!
* Pass in the screen to get (the necessary) calculate Layout automatically called.
* This will also set the widget invisible depending of collapsed state. * This will also set the widget invisible depending of collapsed state.
* Note that setting a widget invisible implicitely calls setDeactivated(), and setting * Note that setting a widget invisible implicitely calls setDeactivated(), and setting
* it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls, * it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls,
@ -374,6 +378,9 @@ namespace GUIEngine
/** Returns if the element is visible. */ /** Returns if the element is visible. */
bool isVisible() const; bool isVisible() const;
/** Returns whether the element is collapsed (through setCollapsed). */
bool isCollapsed() const { return m_is_collapsed; }
bool isActivated() const; bool isActivated() const;
virtual EventPropagation onActivationInput(const int playerID) { return EVENT_LET; } virtual EventPropagation onActivationInput(const int playerID) { return EVENT_LET; }