From b063cbfecfac1283e6a24b3c7995ecdfd5eca3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 11 Mar 2026 02:46:19 -0300 Subject: [PATCH] Layout fixes. --- include/eepp/ui/uilayout.hpp | 1 + src/eepp/ui/uihtmltable.cpp | 13 +++++++------ src/eepp/ui/uilayout.cpp | 28 ++++++++++++++++++++++++++++ src/eepp/ui/uilinearlayout.cpp | 24 +----------------------- src/eepp/ui/uirichtext.cpp | 5 ++++- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/include/eepp/ui/uilayout.hpp b/include/eepp/ui/uilayout.hpp index 8aaa79702..419dc8dbd 100644 --- a/include/eepp/ui/uilayout.hpp +++ b/include/eepp/ui/uilayout.hpp @@ -47,6 +47,7 @@ class EE_API UILayout : public UIWidget { void setLayoutDirty(); + bool setMatchParentIfNeededVerticalGrowth(); }; }} // namespace EE::UI diff --git a/src/eepp/ui/uihtmltable.cpp b/src/eepp/ui/uihtmltable.cpp index b619ed67c..7f0209bec 100644 --- a/src/eepp/ui/uihtmltable.cpp +++ b/src/eepp/ui/uihtmltable.cpp @@ -8,6 +8,7 @@ UIHTMLTable* UIHTMLTable::New() { } UIHTMLTable::UIHTMLTable() : UILayout( "table" ) { + mFlags |= UI_OWNS_CHILDREN_POSITION; mWidthPolicy = SizePolicy::MatchParent; mHeightPolicy = SizePolicy::WrapContent; } @@ -24,6 +25,7 @@ void UIHTMLTable::updateLayout() { if ( mPacking || !mVisible ) return; mPacking = true; + setMatchParentIfNeededVerticalGrowth(); UIHTMLTableHead* head = nullptr; UIHTMLTableBody* body = nullptr; @@ -76,6 +78,10 @@ void UIHTMLTable::updateLayout() { mColWidths.assign( maxCols, 0.f ); + if ( maxCols == 1 ) { + mColWidths[0] = mSize.getWidth(); + } + // Get natural width for each column (without wrapping) for ( size_t r = 0; r < mRows.size(); ++r ) { Uint32 start = mRowCellOffsets[r]; @@ -131,7 +137,7 @@ void UIHTMLTable::updateLayout() { UIHTMLTableRow* row = mRows[r]; row->setPixelsSize( availableWidth, rowHeight ); - if ( r == 0 ) { + if ( r == 0 && mCells[start]->getParent()->isType( UI_TYPE_HTML_TABLE_HEAD ) ) { headHeight = rowHeight; } else if ( r == rowCount - 1 && columnCount && mCells[start]->getParent()->isType( UI_TYPE_HTML_TABLE_FOOTER ) ) { @@ -173,13 +179,8 @@ void UIHTMLTable::updateLayout() { if ( footer && !mRows.empty() ) mRows[rowCount - 1]->setPixelsPosition( mPaddingPx.Left, 0 ); - if ( mWidthPolicy == SizePolicy::MatchParent ) - setInternalPixelsWidth( getMatchParentWidth() ); - if ( mHeightPolicy == SizePolicy::WrapContent ) { setInternalPixelsHeight( headHeight + bodyHeight + footerHeight + mPaddingPx.Bottom ); - } else if ( mHeightPolicy == SizePolicy::MatchParent ) { - setInternalPixelsHeight( getMatchParentHeight() ); } mPacking = false; diff --git a/src/eepp/ui/uilayout.cpp b/src/eepp/ui/uilayout.cpp index c96511a37..62ce1a3b9 100644 --- a/src/eepp/ui/uilayout.cpp +++ b/src/eepp/ui/uilayout.cpp @@ -94,4 +94,32 @@ void UILayout::updateLayoutTree() { onLayoutUpdate(); } +bool UILayout::setMatchParentIfNeededVerticalGrowth() { + bool sizeChanged = false; + Sizef size( getPixelsSize() ); + + if ( getLayoutWidthPolicy() == SizePolicy::MatchParent && 0 == getLayoutWeight() ) { + Float w = getMatchParentWidth(); + + if ( (int)w != (int)getPixelsSize().getWidth() ) { + sizeChanged = true; + size.setWidth( w ); + } + } + + if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { + Float h = getMatchParentHeight(); + + if ( (int)h != (int)getPixelsSize().getHeight() ) { + sizeChanged = true; + size.setHeight( h ); + } + } + + if ( sizeChanged ) + setInternalPixelsSize( size ); + + return sizeChanged; +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index a043103fa..684fc87c6 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -174,29 +174,7 @@ void UILinearLayout::packVertical() { if ( mPacking ) return; mPacking = true; - bool sizeChanged = false; - Sizef size( getPixelsSize() ); - - if ( getLayoutWidthPolicy() == SizePolicy::MatchParent && 0 == getLayoutWeight() ) { - Float w = getMatchParentWidth(); - - if ( (int)w != (int)getPixelsSize().getWidth() ) { - sizeChanged = true; - size.setWidth( w ); - } - } - - if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { - Float h = getMatchParentHeight(); - - if ( (int)h != (int)getPixelsSize().getHeight() ) { - sizeChanged = true; - size.setHeight( h ); - } - } - - if ( sizeChanged ) - setInternalPixelsSize( size ); + setMatchParentIfNeededVerticalGrowth(); applyWidthPolicyOnChildren(); diff --git a/src/eepp/ui/uirichtext.cpp b/src/eepp/ui/uirichtext.cpp index 4233db9ba..3d21fb291 100644 --- a/src/eepp/ui/uirichtext.cpp +++ b/src/eepp/ui/uirichtext.cpp @@ -23,7 +23,7 @@ UIRichText* UIRichText::NewWithTag( const std::string& tag ) { } UIRichText::UIRichText( const std::string& tag ) : UILayout( tag ) { - mFlags |= UI_LOADS_ITS_CHILDREN; + mFlags |= UI_LOADS_ITS_CHILDREN | UI_OWNS_CHILDREN_POSITION; UITheme* theme = getUISceneNode()->getUIThemeManager()->getDefaultTheme(); @@ -622,6 +622,8 @@ void UIRichText::updateLayout() { mResizedCount = 0; mPacking = true; + setMatchParentIfNeededVerticalGrowth(); + rebuildRichText(); mRichText.updateLayout(); @@ -632,6 +634,7 @@ void UIRichText::updateLayout() { setInternalPixelsWidth( mRichText.getSize().getWidth() + mPaddingPx.Left + mPaddingPx.Right ); } + if ( mHeightPolicy == SizePolicy::WrapContent ) { setInternalPixelsHeight( mRichText.getSize().getHeight() + mPaddingPx.Top + mPaddingPx.Bottom );