diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index 6ff63ff1e..f1f23757c 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -5,6 +5,8 @@ #include #include +#include + namespace EE { namespace UI { enum class InnerWidgetOrientation { @@ -117,9 +119,9 @@ class EE_API UIPushButton : public UIWidget { void updateTextBox(); - Vector2f packLayout( const std::vector& widgets, const Rectf& padding ); + Vector2f packLayout( const std::array& widgets, const Rectf& padding ); - Vector2f calcLayoutSize( const std::vector& widgets, const Rectf& padding ) const; + Vector2f calcLayoutSize( const std::array& widgets, const Rectf& padding ) const; }; }} // namespace EE::UI diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index 1b5ce29ef..db8d7925c 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -548,6 +548,8 @@ UIWidget* UIAbstractTableView::createCell( UIWidget* rowWidget, const ModelIndex UIWidget* UIAbstractTableView::setupCell( UITableCell* widget, UIWidget* rowWidget, const ModelIndex& index ) { + mUISceneNode->invalidateStyle( this ); + mUISceneNode->invalidateStyleState( this, true ); widget->setParent( rowWidget ); widget->unsetFlags( UI_AUTO_SIZE ); widget->setClipType( ClipType::ContentBox ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index e7f64d71b..2cfad5fae 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -160,7 +160,7 @@ void UIPushButton::onAutoSize() { } } -Vector2f UIPushButton::calcLayoutSize( const std::vector& widgets, +Vector2f UIPushButton::calcLayoutSize( const std::array& widgets, const Rectf& padding ) const { Vector2f totSize{ padding.Left, padding.Top + padding.Bottom }; UIWidget* widget; @@ -182,8 +182,8 @@ Vector2f UIPushButton::calcLayoutSize( const std::vector& widgets, return totSize; } -Vector2f UIPushButton::packLayout( const std::vector& widgets, const Rectf& padding ) { - std::vector pos( widgets.size() ); +Vector2f UIPushButton::packLayout( const std::array& widgets, const Rectf& padding ) { + std::array pos; Vector2f totSize{ padding.Left, padding.Top + padding.Bottom }; UIWidget* widget; for ( size_t i = 0; i < widgets.size(); i++ ) { diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index c6ded1694..bba0e684a 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -672,6 +672,7 @@ void UISceneNode::invalidateStyle( UIWidget* node, bool tryReinsert ) { if ( node->isClosing() ) return; + // Already invalidated? if ( mDirtyStyle.count( node ) > 0 ) { if ( !tryReinsert ) return; @@ -679,12 +680,17 @@ void UISceneNode::invalidateStyle( UIWidget* node, bool tryReinsert ) { mDirtyStyle.erase( node ); } - for ( auto& dirtyNode : mDirtyStyle ) - if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) ) + // Any parent dirty? + Node* parent = node->getParent(); + while ( parent != nullptr ) { + if ( parent->isWidget() && mDirtyStyle.count( parent->asType() ) > 0 ) return; + parent = parent->getParent(); + } std::vector eraseList; + // Any child in list? remove it for ( auto widget : mDirtyStyle ) if ( NULL == widget || node->isParentOf( widget ) ) eraseList.push_back( widget ); @@ -702,6 +708,7 @@ void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimation if ( node->isClosing() ) return; + // Already invalidated? if ( mDirtyStyleState.count( node ) > 0 ) { if ( !tryReinsert ) return; @@ -709,12 +716,17 @@ void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimation mDirtyStyleState.erase( node ); } - for ( auto& dirtyNode : mDirtyStyleState ) - if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) ) + // Any parent dirty? + Node* parent = node->getParent(); + while ( parent != nullptr ) { + if ( parent->isWidget() && mDirtyStyleState.count( parent->asType() ) > 0 ) return; + parent = parent->getParent(); + } std::vector eraseList; + // Any child in list? remove it for ( auto widget : mDirtyStyleState ) if ( NULL == widget || node->isParentOf( widget ) ) eraseList.push_back( widget ); diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index a21e3e09e..2eba4cf93 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -177,6 +177,8 @@ bool UITreeView::tryOpenModelIndex( const ModelIndex& index, bool forceUpdate ) UIWidget* UITreeView::setupCell( UITableCell* widget, UIWidget* rowWidget, const ModelIndex& index ) { + mUISceneNode->invalidateStyle( this ); + mUISceneNode->invalidateStyleState( this, true ); widget->setParent( rowWidget ); widget->unsetFlags( UI_AUTO_SIZE ); widget->setClipType( mDisableCellClipping ? ClipType::None : ClipType::ContentBox ); diff --git a/src/examples/7guis/cells/cells.cpp b/src/examples/7guis/cells/cells.cpp index 1127ebb6a..94d35aeb9 100644 --- a/src/examples/7guis/cells/cells.cpp +++ b/src/examples/7guis/cells/cells.cpp @@ -3,7 +3,7 @@ // Referece https://eugenkiss.github.io/7guis/tasks/#cells EE_MAIN_FUNC int main( int, char** ) { - UIApplication app( { 1024, 768, "eepp - 7GUIs - Cells" } ); + UIApplication app( { 1280, 768, "eepp - 7GUIs - Cells" } ); UIWidget* rlay = app.getUI()->loadLayoutFromString( R"xml(