Don't change orthogonal alignment in wxSizerFlags::CenterXXX()

It was unexpected that using wxSizerFlags().Right().CentreVertical()
didn't right-align the item because CentreVertical() reset the alignment
in the horizontal direction rather than just setting it in the vertical
one, so change this, document the new behaviour explicitly and add a new
unit test checking for it.

Closes #18989.
This commit is contained in:
Vadim Zeitlin
2021-01-25 12:58:04 +01:00
parent caf5a62fd9
commit 9130f8bfc6
3 changed files with 45 additions and 4 deletions

View File

@@ -85,7 +85,7 @@ void GridSizerTestCase::SetChildren(const wxVector<wxWindow*>& children,
// ----------------------------------------------------------------------------
TEST_CASE_METHOD(GridSizerTestCase,
"wxGridSizer::Expand",
"wxGridSizer::Layout",
"[grid-sizer][sizer]")
{
const wxSize sizeTotal = m_win->GetClientSize();
@@ -144,6 +144,29 @@ TEST_CASE_METHOD(GridSizerTestCase,
CHECK( children[2]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
CHECK( children[3]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
}
// Test alignment flag too.
SECTION("Right align")
{
SetChildren(children, wxSizerFlags().Right());
CHECK( children[0]->GetPosition() == wxPoint( 0, 0) );
CHECK( children[1]->GetPosition() == wxPoint(sizeRest.x, 0) );
CHECK( children[2]->GetPosition() == wxPoint( 0, sizeChild.y) );
CHECK( children[3]->GetPosition() == wxPoint(sizeRest.x, sizeChild.y) );
}
// Also test combining centering in one direction and aligning in another.
SECTION("Right align and center vertically")
{
SetChildren(children, wxSizerFlags().Right().CentreVertical());
const int yMid = sizeChild.y + (sizeRest.y - sizeChild.y) / 2;
CHECK( children[0]->GetPosition() == wxPoint( 0, 0) );
CHECK( children[1]->GetPosition() == wxPoint(sizeRest.x, 0) );
CHECK( children[2]->GetPosition() == wxPoint( 0, yMid) );
CHECK( children[3]->GetPosition() == wxPoint(sizeRest.x, yMid) );
}
}
TEST_CASE_METHOD(GridSizerTestCase,