From d2a90dfb28cccca698df2a0d0983d529e6d02cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 8 May 2020 23:44:49 -0300 Subject: [PATCH] Fixed layout invalidation when the invalidated layout does not have a inmediate parent layout. --- include/eepp/ui/uitabwidget.hpp | 8 +++--- src/eepp/ui/uiscenenode.cpp | 31 ++++++++++++---------- src/eepp/ui/uitabwidget.cpp | 46 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/include/eepp/ui/uitabwidget.hpp b/include/eepp/ui/uitabwidget.hpp index f416637dc..375d50159 100644 --- a/include/eepp/ui/uitabwidget.hpp +++ b/include/eepp/ui/uitabwidget.hpp @@ -2,12 +2,12 @@ #define EE_UICUITABWIDGET_HPP #include -#include #include +#include namespace EE { namespace UI { -class EE_API UITabWidget : public UILayout { +class EE_API UITabWidget : public UIWidget { public: class StyleConfig { public: @@ -127,9 +127,11 @@ class EE_API UITabWidget : public UILayout { UITab* createTab( const String& Text, UINode* CtrlOwned, Drawable* Icon ); + virtual void onSizeChange(); + virtual void onChildCountChange( Node* child, const bool& removed ); - virtual void updateLayout(); + virtual void onPaddingChange(); void setContainerSize(); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index de6386285..2a6b2948f 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -546,26 +546,29 @@ void UISceneNode::invalidateLayout( UILayout* node ) { if ( mDirtyLayouts.count( node ) > 0 ) return; - for ( auto& dirtyCtrl : mDirtyLayouts ) { - if ( NULL != dirtyCtrl && dirtyCtrl->isParentOf( node ) ) { - return; + if ( node->getParent()->isLayout() ) { + for ( auto& dirtyCtrl : mDirtyLayouts ) { + if ( NULL != dirtyCtrl && dirtyCtrl->isParentOf( node ) && + node->getParent()->isLayout() ) { + return; + } } - } - std::vector::iterator> itEraseList; + std::vector::iterator> itEraseList; - for ( auto it = mDirtyLayouts.begin(); it != mDirtyLayouts.end(); ++it ) { - itNode = *it; + for ( auto it = mDirtyLayouts.begin(); it != mDirtyLayouts.end(); ++it ) { + itNode = *it; - if ( NULL != itNode && node->isParentOf( itNode ) ) { - itEraseList.push_back( it ); - } else if ( NULL == itNode ) { - itEraseList.push_back( it ); + if ( NULL != itNode && node->isParentOf( itNode ) && itNode->getParent()->isLayout() ) { + itEraseList.push_back( it ); + } else if ( NULL == itNode ) { + itEraseList.push_back( it ); + } } - } - for ( auto ite = itEraseList.begin(); ite != itEraseList.end(); ++ite ) { - mDirtyLayouts.erase( *ite ); + for ( auto ite = itEraseList.begin(); ite != itEraseList.end(); ++ite ) { + mDirtyLayouts.erase( *ite ); + } } mDirtyLayouts.insert( node ); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 1789fad49..714c3575f 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -14,7 +14,7 @@ UITabWidget* UITabWidget::New() { } UITabWidget::UITabWidget() : - UILayout( "tabwidget" ), + UIWidget( "tabwidget" ), mCtrlContainer( NULL ), mTabContainer( NULL ), mTabSelected( NULL ), @@ -35,6 +35,8 @@ UITabWidget::UITabWidget() : ->setPosition( 0, mStyleConfig.TabHeight ); mCtrlContainer->clipEnable(); + onSizeChange(); + applyDefaultTheme(); } @@ -45,11 +47,11 @@ Uint32 UITabWidget::getType() const { } bool UITabWidget::isType( const Uint32& type ) const { - return UITabWidget::getType() == type ? true : UILayout::isType( type ); + return UITabWidget::getType() == type ? true : UIWidget::isType( type ); } void UITabWidget::setTheme( UITheme* Theme ) { - UILayout::setTheme( Theme ); + UIWidget::setTheme( Theme ); mTabContainer->setThemeSkin( Theme, "tabwidget" ); @@ -73,9 +75,9 @@ void UITabWidget::setTheme( UITheme* Theme ) { } void UITabWidget::onThemeLoaded() { - tryUpdateLayout(); + onSizeChange(); - UILayout::onThemeLoaded(); + UIWidget::onThemeLoaded(); } void UITabWidget::setContainerSize() { @@ -128,7 +130,7 @@ std::string UITabWidget::getPropertyString( const PropertyDefinition* propertyDe case PropertyId::TabHeight: return String::fromFloat( getTabsHeight(), "dp" ); default: - return UILayout::getPropertyString( propertyDef, propertyIndex ); + return UIWidget::getPropertyString( propertyDef, propertyIndex ); } } @@ -189,7 +191,7 @@ bool UITabWidget::applyProperty( const StyleSheetProperty& attribute ) { setTabsHeight( attribute.asDpDimension( this ) ); break; default: - return UILayout::applyProperty( attribute ); + return UIWidget::applyProperty( attribute ); } return true; @@ -574,6 +576,17 @@ Uint32 UITabWidget::getSelectedTabIndex() const { return mTabSelectedIndex; } +void UITabWidget::onSizeChange() { + setContainerSize(); + posTabs(); + + if ( NULL != mTabSelected && NULL != mTabSelected->getOwnedWidget() ) { + mTabSelected->getOwnedWidget()->setSize( mCtrlContainer->getSize() ); + } + + UIWidget::onSizeChange(); +} + void UITabWidget::onChildCountChange( Node* child, const bool& removed ) { if ( !removed && child != mTabContainer && child != mCtrlContainer ) { if ( child->isType( UI_TYPE_TAB ) ) { @@ -592,27 +605,16 @@ void UITabWidget::onChildCountChange( Node* child, const bool& removed ) { child->setParent( mCtrlContainer ); child->setVisible( false ); child->setEnabled( true ); - - if ( child->isLayout() ) { - mLayouts.insert( child->asType() ); - } } } - if ( removed && child->isLayout() ) { - mLayouts.erase( child->asType() ); - } - - tryUpdateLayout(); + UIWidget::onChildCountChange( child, removed ); } -void UITabWidget::updateLayout() { - setContainerSize(); - posTabs(); +void UITabWidget::onPaddingChange() { + onSizeChange(); - if ( NULL != mTabSelected && NULL != mTabSelected->getOwnedWidget() ) { - mTabSelected->getOwnedWidget()->setSize( mCtrlContainer->getSize() ); - } + UIWidget::onPaddingChange(); } void UITabWidget::applyThemeToTabs() {