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:
@@ -69,14 +69,26 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// some shortcuts for Align()
|
// this is just a shortcut for Align()
|
||||||
wxSizerFlags& Centre() { return Align(wxALIGN_CENTRE); }
|
wxSizerFlags& Centre() { return Align(wxALIGN_CENTRE); }
|
||||||
wxSizerFlags& Center() { return Centre(); }
|
wxSizerFlags& Center() { return Centre(); }
|
||||||
|
|
||||||
wxSizerFlags& CentreVertical() { return Align(wxALIGN_CENTRE_VERTICAL); }
|
// but all the remaining methods turn on the corresponding alignment flag
|
||||||
|
// without affecting the existing ones
|
||||||
|
wxSizerFlags& CentreVertical()
|
||||||
|
{
|
||||||
|
m_flags = (m_flags & ~wxALIGN_BOTTOM) | wxALIGN_CENTRE_VERTICAL;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
wxSizerFlags& CenterVertical() { return CentreVertical(); }
|
wxSizerFlags& CenterVertical() { return CentreVertical(); }
|
||||||
|
|
||||||
wxSizerFlags& CentreHorizontal() { return Align(wxALIGN_CENTRE_HORIZONTAL); }
|
wxSizerFlags& CentreHorizontal()
|
||||||
|
{
|
||||||
|
m_flags = (m_flags & ~wxALIGN_RIGHT) | wxALIGN_CENTRE_HORIZONTAL;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
wxSizerFlags& CenterHorizontal() { return CentreHorizontal(); }
|
wxSizerFlags& CenterHorizontal() { return CentreHorizontal(); }
|
||||||
|
|
||||||
wxSizerFlags& Top()
|
wxSizerFlags& Top()
|
||||||
|
@@ -1455,6 +1455,9 @@ public:
|
|||||||
them anyhow. For 2D sizers, centering an item in one direction is quite
|
them anyhow. For 2D sizers, centering an item in one direction is quite
|
||||||
different from centering it in both directions however.
|
different from centering it in both directions however.
|
||||||
|
|
||||||
|
Note that, unlike Align(), this method doesn't change the vertical
|
||||||
|
alignment.
|
||||||
|
|
||||||
@see CentreVertical()
|
@see CentreVertical()
|
||||||
|
|
||||||
@since 3.1.0
|
@since 3.1.0
|
||||||
@@ -1467,6 +1470,9 @@ public:
|
|||||||
The remarks in CentreHorizontal() documentation also apply to this
|
The remarks in CentreHorizontal() documentation also apply to this
|
||||||
function.
|
function.
|
||||||
|
|
||||||
|
Note that, unlike Align(), this method doesn't change the horizontal
|
||||||
|
alignment.
|
||||||
|
|
||||||
@since 3.1.0
|
@since 3.1.0
|
||||||
*/
|
*/
|
||||||
wxSizerFlags& CentreVertical();
|
wxSizerFlags& CentreVertical();
|
||||||
|
@@ -85,7 +85,7 @@ void GridSizerTestCase::SetChildren(const wxVector<wxWindow*>& children,
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
TEST_CASE_METHOD(GridSizerTestCase,
|
TEST_CASE_METHOD(GridSizerTestCase,
|
||||||
"wxGridSizer::Expand",
|
"wxGridSizer::Layout",
|
||||||
"[grid-sizer][sizer]")
|
"[grid-sizer][sizer]")
|
||||||
{
|
{
|
||||||
const wxSize sizeTotal = m_win->GetClientSize();
|
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[2]->GetSize() == wxSize(sizeChild.x, sizeRest.y) );
|
||||||
CHECK( children[3]->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,
|
TEST_CASE_METHOD(GridSizerTestCase,
|
||||||
|
Reference in New Issue
Block a user