From 999d78a3bcec5b74c0fe63bb035d123eb8512b74 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 23 Mar 2019 17:18:48 +0100 Subject: [PATCH] Allow using alignment with wxEXPAND and wxSHAPED in wxBoxSizer Don't assert in wxBoxSizer when both alignment flags and wxEXPAND are used together if wxSHAPED is also used, as such flag combinations may make sense and so shouldn't be forbidden. Add a unit test checking that this is allowed. --- src/common/sizer.cpp | 7 +++++-- tests/sizers/boxsizer.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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 }