diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 651af1c48f..d34ad21eec 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -2071,7 +2071,10 @@ wxSizerItem *wxBoxSizer::DoInsert(size_t index, wxSizerItem *item) ); } - if ( flags & wxEXPAND ) + // Note that using alignment with wxEXPAND can make sense if wxSHAPED + // is also used, as the item doesn't necessarily fully expand in the + // other direction in this case. + if ( (flags & wxEXPAND) && !(flags & wxSHAPED) ) { wxASSERT_MSG ( @@ -2097,7 +2100,7 @@ wxSizerItem *wxBoxSizer::DoInsert(size_t index, wxSizerItem *item) ); } - if ( flags & wxEXPAND ) + if ( (flags & wxEXPAND) && !(flags & wxSHAPED) ) { wxASSERT_MSG( !(flags & (wxALIGN_BOTTOM | wxALIGN_CENTRE_VERTICAL)), diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp index 403e74703a..f7df2d95c8 100644 --- a/tests/sizers/boxsizer.cpp +++ b/tests/sizers/boxsizer.cpp @@ -398,6 +398,15 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::IncompatibleFlags", "[sizer]") ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_CENTRE_VERTICAL); ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_BOTTOM); + // But combining it with these flags and wxSHAPED does make sense and so + // shouldn't result in an assert. + CHECK_NOTHROW( + sizer->Add(10, 10, 0, wxEXPAND | wxSHAPED | wxALIGN_CENTRE_VERTICAL) + ); + CHECK_NOTHROW( + sizer->Add(10, 10, 0, wxEXPAND | wxSHAPED | wxALIGN_TOP) + ); + // And now exactly the same thing in the other direction. sizer = new wxBoxSizer(wxVERTICAL); @@ -419,6 +428,13 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::IncompatibleFlags", "[sizer]") ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_CENTRE_HORIZONTAL); ASSERT_SIZER_INCOMPATIBLE_FLAGS(wxEXPAND, wxALIGN_RIGHT); + CHECK_NOTHROW( + sizer->Add(10, 10, 0, wxEXPAND | wxSHAPED | wxALIGN_CENTRE_HORIZONTAL) + ); + CHECK_NOTHROW( + sizer->Add(10, 10, 0, wxEXPAND | wxSHAPED | wxALIGN_RIGHT) + ); + #undef ASSERT_SIZER_INCOMPATIBLE_FLAGS #undef ASSERT_SIZER_INVALID_FLAGS }