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,