Fixed the linear-layout sizing bug:

The child margins were already included. The real issue was that a wrap-content UILinearLayout allocated weighted space from the parent’s full dimensions, ignoring the parent’s content padding. Added a regression reproducing a padded parent, weighted input, and fixed siblings with margins.

Added removeKeyBindingCommand in UISceneNode and UIWindow.
This commit is contained in:
Martín Lucas Golini
2026-08-21 13:48:46 -03:00
parent 8eed5fcd58
commit 866163457e
6 changed files with 49 additions and 4 deletions

View File

@@ -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.

View File

@@ -194,6 +194,7 @@ class EE_API UIWindow : public UIWidget {
void addKeyBinds( const std::map<KeyBindings::Shortcut, std::string>& binds );
void setKeyBindingCommand( const std::string& command, KeyBindingCommand func );
void removeKeyBindingCommand( const std::string& command );
void executeKeyBindingCommand( const std::string& command );

View File

@@ -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 );

View File

@@ -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() ) {

View File

@@ -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() ) {

View File

@@ -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<UIWidget>()->getPixelsPosition().x + 60.f,
0.1f );
}
UTEST( UILinearLayout, VerticalWeightsNormalize ) {
UIApplication app(
WindowSettings( 320, 240, "eepp - UILinearLayout Test", WindowStyle::Default,