Layout fixes.

This commit is contained in:
Martín Lucas Golini
2026-03-11 02:46:19 -03:00
parent a83812272c
commit b063cbfecf
5 changed files with 41 additions and 30 deletions

View File

@@ -47,6 +47,7 @@ class EE_API UILayout : public UIWidget {
void setLayoutDirty();
bool setMatchParentIfNeededVerticalGrowth();
};
}} // namespace EE::UI

View File

@@ -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;

View File

@@ -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

View File

@@ -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();

View File

@@ -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 );