Fix top + bottom and left + right html element expanding.

This commit is contained in:
Martín Lucas Golini
2026-05-03 00:33:32 -03:00
parent a698348abd
commit 2dcc787ed7
2 changed files with 50 additions and 11 deletions

View File

@@ -270,28 +270,52 @@ void UIHTMLWidget::updateOutOfFlowPosition() {
Float top = 0;
Float left = 0;
Float right = 0;
Float bottom = 0;
bool useTop = mTopEq != "auto";
bool useBottom = mBottomEq != "auto";
bool useLeft = mLeftEq != "auto";
bool useRight = mRightEq != "auto";
if ( useLeft ) {
if ( useLeft )
left = lengthFromValue( mLeftEq, CSS::PropertyRelativeTarget::ContainingBlockWidth, 0 );
} else if ( useRight ) {
Float rightVal =
lengthFromValue( mRightEq, CSS::PropertyRelativeTarget::ContainingBlockWidth, 0 );
left = cbContentWidth - childWidth - margin.Left - margin.Right - rightVal;
if ( useRight )
right = lengthFromValue( mRightEq, CSS::PropertyRelativeTarget::ContainingBlockWidth, 0 );
if ( useTop )
top = lengthFromValue( mTopEq, CSS::PropertyRelativeTarget::ContainingBlockHeight, 0 );
if ( useBottom )
bottom =
lengthFromValue( mBottomEq, CSS::PropertyRelativeTarget::ContainingBlockHeight, 0 );
Float finalWidth = childWidth;
Float finalHeight = childHeight;
if ( useLeft && useRight && getLayoutWidthPolicy() == SizePolicy::WrapContent ) {
Float stretched = cbContentWidth - left - right - margin.Left - margin.Right;
if ( stretched >= 0 )
finalWidth = stretched;
}
if ( useTop ) {
top = lengthFromValue( mTopEq, CSS::PropertyRelativeTarget::ContainingBlockHeight, 0 );
} else if ( useBottom ) {
Float bottomVal =
lengthFromValue( mBottomEq, CSS::PropertyRelativeTarget::ContainingBlockHeight, 0 );
top = cbContentHeight - childHeight - margin.Top - margin.Bottom - bottomVal;
if ( useTop && useBottom && getLayoutHeightPolicy() == SizePolicy::WrapContent ) {
Float stretched = cbContentHeight - top - bottom - margin.Top - margin.Bottom;
if ( stretched >= 0 )
finalHeight = stretched;
}
if ( finalWidth != childWidth || finalHeight != childHeight ) {
setPixelsSize( finalWidth, finalHeight );
childWidth = finalWidth;
childHeight = finalHeight;
}
if ( !useLeft && useRight )
left = cbContentWidth - childWidth - margin.Left - margin.Right - right;
if ( !useTop && useBottom )
top = cbContentHeight - childHeight - margin.Top - margin.Bottom - bottom;
top += margin.Top;
left += margin.Left;

View File

@@ -1206,6 +1206,21 @@ UTEST( UIHTML, HeightExpansion ) {
EXPECT_GE( htmlWidget->getSize().getHeight(), bodyWidget->getSize().getHeight() );
auto barNode = sceneNode->getRoot()->find( "bar" );
ASSERT_TRUE( barNode != nullptr );
auto barWidget = barNode->asType<UIWidget>();
auto barHTML = barNode->asType<UIHTMLWidget>();
EXPECT_EQ( barHTML->getCSSPosition(), CSSPosition::Fixed );
EXPECT_NEAR( barWidget->getPixelsSize().getWidth(), 250.f, 1.f );
auto rootWidget = sceneNode->getRoot();
EXPECT_GT( rootWidget->getPixelsSize().getHeight(), 0 );
EXPECT_NEAR( barWidget->getPixelsSize().getHeight(), rootWidget->getPixelsSize().getHeight(),
1.f );
Engine::destroySingleton();
}