From 4cd645a411583bfc94ae6e9627e05f4d2be9718c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 30 May 2026 01:55:23 -0300 Subject: [PATCH] More flex fixes. --- src/eepp/ui/flexlayouter.cpp | 21 ++++++++++++++--- src/tests/unit_tests/uihtml_tests.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/eepp/ui/flexlayouter.cpp b/src/eepp/ui/flexlayouter.cpp index d5663a7c1..104ec9cab 100644 --- a/src/eepp/ui/flexlayouter.cpp +++ b/src/eepp/ui/flexlayouter.cpp @@ -828,8 +828,16 @@ void FlexLayouter::applyLayout( const SmallVector& lines, const Axi if ( widthPolicy == SizePolicy::WrapContent ) totW = containerPadding.Left + contentW + containerPadding.Right; - else if ( widthPolicy != SizePolicy::Fixed ) - totW = mContainer->getParent() ? mContainer->getParent()->getPixelsSize().getWidth() : totW; + else if ( widthPolicy != SizePolicy::Fixed ) { + auto* parent = mContainer->getParent(); + bool parentIsFlex = parent && parent->isType( UI_TYPE_HTML_WIDGET ) && + static_cast( parent )->isFlex(); + if ( parentIsFlex ) { + totW = containerWidth; + } else { + totW = parent ? parent->getPixelsSize().getWidth() : totW; + } + } if ( heightPolicy == SizePolicy::WrapContent ) totH = containerPadding.Top + contentH + containerPadding.Bottom; @@ -849,7 +857,14 @@ void FlexLayouter::updateLayout() { mPacking = true; mContainer->beginAttributesTransaction(); - setMatchParentIfNeededVerticalGrowth(); + + { + auto* parent = mContainer->getParent(); + bool parentIsFlexContainer = parent && parent->isType( UI_TYPE_HTML_WIDGET ) && + static_cast( parent )->isFlex(); + if ( !parentIsFlexContainer ) + setMatchParentIfNeededVerticalGrowth(); + } readContainerStyle( mDirection, mWrap, mJustify, mAlignItems, mAlignContent, mColumnGap, mRowGap ); diff --git a/src/tests/unit_tests/uihtml_tests.cpp b/src/tests/unit_tests/uihtml_tests.cpp index 40058db2e..4df046e7c 100644 --- a/src/tests/unit_tests/uihtml_tests.cpp +++ b/src/tests/unit_tests/uihtml_tests.cpp @@ -2521,6 +2521,39 @@ UTEST( UIHTML, BodyHeightMiscalculationFixture ) { EXPECT_GT( bodyWidget->getPixelsSize().getHeight(), 3000.f ); EXPECT_LT( bodyWidget->getPixelsSize().getHeight(), 6000.f ); + // Verify the nav layout: .wrap has justify-content: space-between, + // so .brand should be at the left and .links at the right. + auto nav = sceneNode->getRoot()->findByClass( "site-nav" ); + ASSERT_TRUE( nav != nullptr ); + auto navWidget = nav->asType(); + + auto wrap = navWidget->findByClass( "wrap" ); + ASSERT_TRUE( wrap != nullptr ); + auto wrapWidget = wrap->asType(); + + auto brand = wrapWidget->findByClass( "brand" ); + ASSERT_TRUE( brand != nullptr ); + auto brandWidget = brand->asType(); + + auto links = wrapWidget->findByClass( "links" ); + ASSERT_TRUE( links != nullptr ); + auto linksWidget = links->asType(); + + // With justify-content: space-between in a row-direction flex: + // .brand should be at the left side of .wrap (near padding edge). + EXPECT_LT( brandWidget->getPixelsPosition().x, + wrapWidget->getPixelsSize().getWidth() * 0.25f ); + + // .links should be at the right side of .wrap, NOT next to .brand. + Float wrapW = wrapWidget->getPixelsSize().getWidth(); + Float linksW = linksWidget->getPixelsSize().getWidth(); + Float linksRight = linksWidget->getPixelsPosition().x + linksW; + EXPECT_GT( linksWidget->getPixelsPosition().x, wrapW * 0.5f ); + + // .links should NOT occupy all available width — it must be content-sized. + EXPECT_GT( linksW, 0.f ); + EXPECT_LT( linksW, wrapW * 0.5f ); + Engine::destroySingleton(); }