From 2dcc787ed78d5193cc136bde57b62bf717dc182f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 3 May 2026 00:33:32 -0300 Subject: [PATCH] Fix top + bottom and left + right html element expanding. --- src/eepp/ui/uihtmlwidget.cpp | 46 ++++++++++++++++++++------- src/tests/unit_tests/uihtml_tests.cpp | 15 +++++++++ 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/eepp/ui/uihtmlwidget.cpp b/src/eepp/ui/uihtmlwidget.cpp index bd1b8c547..fed61c101 100644 --- a/src/eepp/ui/uihtmlwidget.cpp +++ b/src/eepp/ui/uihtmlwidget.cpp @@ -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; diff --git a/src/tests/unit_tests/uihtml_tests.cpp b/src/tests/unit_tests/uihtml_tests.cpp index 38e9ad12a..9a4cc4fe9 100644 --- a/src/tests/unit_tests/uihtml_tests.cpp +++ b/src/tests/unit_tests/uihtml_tests.cpp @@ -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(); + auto barHTML = barNode->asType(); + + 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(); }