From 866163457e117dd4b0f71a44f65506220995defd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 21 Aug 2026 13:48:46 -0300 Subject: [PATCH] =?UTF-8?q?Fixed=20the=20linear-layout=20sizing=20bug:=20T?= =?UTF-8?q?he=20child=20margins=20were=20already=20included.=20The=20real?= =?UTF-8?q?=20issue=20was=20that=20a=20wrap-content=20UILinearLayout=20all?= =?UTF-8?q?ocated=20weighted=20space=20from=20the=20parent=E2=80=99s=20ful?= =?UTF-8?q?l=20dimensions,=20ignoring=20the=20parent=E2=80=99s=20content?= =?UTF-8?q?=20padding.=20Added=20a=20regression=20reproducing=20a=20padded?= =?UTF-8?q?=20parent,=20weighted=20input,=20and=20fixed=20siblings=20with?= =?UTF-8?q?=20margins.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added removeKeyBindingCommand in UISceneNode and UIWindow. --- include/eepp/ui/uiscenenode.hpp | 1 + include/eepp/ui/uiwindow.hpp | 1 + src/eepp/ui/uilinearlayout.cpp | 6 ++-- src/eepp/ui/uiscenenode.cpp | 4 +++ src/eepp/ui/uiwindow.cpp | 4 +++ src/tests/unit_tests/uilayout_tests.cpp | 37 +++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index 7964f009d..a4d3a119e 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -679,6 +679,7 @@ class EE_API UISceneNode : public SceneNode { * @param func The function to call when the command is executed. */ void setKeyBindingCommand( const std::string& command, KeyBindingCommand func ); + void removeKeyBindingCommand( const std::string& command ); /** * @brief Executes a keybinding command. diff --git a/include/eepp/ui/uiwindow.hpp b/include/eepp/ui/uiwindow.hpp index bbb3a3473..86402c2e3 100644 --- a/include/eepp/ui/uiwindow.hpp +++ b/include/eepp/ui/uiwindow.hpp @@ -194,6 +194,7 @@ class EE_API UIWindow : public UIWidget { void addKeyBinds( const std::map& binds ); void setKeyBindingCommand( const std::string& command, KeyBindingCommand func ); + void removeKeyBindingCommand( const std::string& command ); void executeKeyBindingCommand( const std::string& command ); diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index 46beeeeed..5e5888384 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -198,8 +198,7 @@ void UILinearLayout::packVertical() { ( getLayoutHeightPolicy() == SizePolicy::MatchParent || getLayoutHeightPolicy() == SizePolicy::Fixed ) ? getPixelsSize().getHeight() - mPaddingPx.Top - mPaddingPx.Bottom - : getParent()->getPixelsSize().getHeight() - mLayoutMarginPx.Bottom - - mLayoutMarginPx.Top - mPaddingPx.Top - mPaddingPx.Bottom; + : getMatchParentHeight() - mPaddingPx.Top - mPaddingPx.Bottom; Float newSize = eemax( eeceil( totSize - freeSize.getHeight() ) * widget->getLayoutWeight() / totalWeight, 0.f ); @@ -334,8 +333,7 @@ void UILinearLayout::packHorizontal() { ( getLayoutWidthPolicy() == SizePolicy::MatchParent || getLayoutWidthPolicy() == SizePolicy::Fixed ) ? getPixelsSize().getWidth() - mPaddingPx.Left - mPaddingPx.Right - : getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Right - - mLayoutMarginPx.Left - mPaddingPx.Left - mPaddingPx.Right; + : getMatchParentWidth() - mPaddingPx.Left - mPaddingPx.Right; Float newSize = eemax( eeceil( totSize - freeSize.getWidth() ) * widget->getLayoutWeight() / totalWeight, 0.f ); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 284118ad2..f7cc296c0 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -2091,6 +2091,10 @@ void UISceneNode::setKeyBindingCommand( const std::string& command, mKeyBindingCommands[command] = func; } +void UISceneNode::removeKeyBindingCommand( const std::string& command ) { + mKeyBindingCommands.erase( command ); +} + void UISceneNode::executeKeyBindingCommand( const std::string& command ) { auto cmdIt = mKeyBindingCommands.find( command ); if ( cmdIt != mKeyBindingCommands.end() ) { diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 694d6fd7e..6d9fe1906 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1812,6 +1812,10 @@ void UIWindow::setKeyBindingCommand( const std::string& command, mKeyBindingCommands[command] = func; } +void UIWindow::removeKeyBindingCommand( const std::string& command ) { + mKeyBindingCommands.erase( command ); +} + void UIWindow::executeKeyBindingCommand( const std::string& command ) { auto cmdIt = mKeyBindingCommands.find( command ); if ( cmdIt != mKeyBindingCommands.end() ) { diff --git a/src/tests/unit_tests/uilayout_tests.cpp b/src/tests/unit_tests/uilayout_tests.cpp index 55b798227..689829716 100644 --- a/src/tests/unit_tests/uilayout_tests.cpp +++ b/src/tests/unit_tests/uilayout_tests.cpp @@ -115,6 +115,43 @@ UTEST( UILinearLayout, HorizontalWeightsNormalizeAcrossVisibleChildren ) { EXPECT_NEAR( 150.f, last->getPixelsSize().getWidth(), 0.1f ); } +UTEST( UILinearLayout, HorizontalWeightAccountsForFixedSiblingMargins ) { + UIApplication app( + WindowSettings( 480, 240, "eepp - UILinearLayout Margin Weight Test", WindowStyle::Default, + WindowBackend::Default, 32 ), + UIApplication::Settings( Sys::getProcessPath() + ".." + FileSystem::getOSSlash(), 1 ) ); + + UIWidget* parent = UIWidget::New(); + parent->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); + parent->setPixelsSize( 400, 100 ); + parent->setPadding( { 12, 0, 12, 0 } ); + parent->setParent( app.getUI()->getRoot() ); + + UILinearLayout* layout = UILinearLayout::NewHorizontal(); + layout->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ); + layout->setParent( parent ); + + UIWidget* weighted = UIWidget::New(); + weighted->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); + weighted->setPixelsSize( 0, 30 ); + weighted->setLayoutWeight( 1 ); + weighted->setParent( layout ); + + for ( int i = 0; i < 3; ++i ) { + UIWidget* fixed = UIWidget::New(); + fixed->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); + fixed->setPixelsSize( 60, 30 ); + fixed->setLayoutMarginLeft( 8 ); + fixed->setParent( layout ); + } + + app.getUI()->updateDirtyLayouts(); + + EXPECT_NEAR( 172.f, weighted->getPixelsSize().getWidth(), 0.1f ); + EXPECT_NEAR( 376.f, layout->getLastChild()->asType()->getPixelsPosition().x + 60.f, + 0.1f ); +} + UTEST( UILinearLayout, VerticalWeightsNormalize ) { UIApplication app( WindowSettings( 320, 240, "eepp - UILinearLayout Test", WindowStyle::Default,