Make it possible to combine wxEXPAND and alignment in wxGridSizer.
Allow overriding wxEXPAND effect in one of the directions by specifying wxALIGN_{RIGHT,BOTTOM} or wxALIGN_CENTRE_{HORIZONTAL,VERTICAL} together with it (unfortunately this doesn't work for wxALIGN_{LEFT,TOP} as their value is 0 and so their presence in flags can't be detected).
This commit is contained in:
@@ -68,7 +68,17 @@
|
||||
These flags are used to specify which side(s) of the sizer item
|
||||
the border width will apply to.}
|
||||
@itemdef{wxEXPAND,
|
||||
The item will be expanded to fill the space assigned to the item.}
|
||||
The item will be expanded to fill the space assigned to the item.
|
||||
When used for the items of wxBoxSizer, the expansion only happens
|
||||
in the transversal direction of the sizer as only the item
|
||||
proportion governs its behaviour in the principal sizer direction.
|
||||
But when it is used for the items of wxGridSizer, this flag can be
|
||||
combined with the alignment flags which override it in the
|
||||
corresponding direction if specified, e.g. @c wxEXPAND |
|
||||
wxALIGN_CENTRE_VERTICAL would expand the item only horizontally
|
||||
but center it vertically. Notice that this doesn't work for the
|
||||
default left/top alignment and @c wxEXPAND still applies in both
|
||||
directions if it is combined with @c wxALIGN_LEFT or @c wxALIGN_TOP.}
|
||||
@itemdef{wxSHAPED,
|
||||
The item will be expanded as much as possible while also
|
||||
maintaining its aspect ratio.}
|
||||
|
@@ -1517,11 +1517,13 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h )
|
||||
wxSize sz( item->GetMinSizeWithBorder() );
|
||||
int flag = item->GetFlag();
|
||||
|
||||
if ((flag & wxEXPAND) || (flag & wxSHAPED))
|
||||
// wxSHAPED maintains aspect ratio and so always applies to both
|
||||
// directions.
|
||||
if ( flag & wxSHAPED )
|
||||
{
|
||||
sz = wxSize(w, h);
|
||||
sz = wxSize(w, h);
|
||||
}
|
||||
else
|
||||
else // Otherwise we handle each direction individually.
|
||||
{
|
||||
if (flag & wxALIGN_CENTER_HORIZONTAL)
|
||||
{
|
||||
@@ -1531,6 +1533,10 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h )
|
||||
{
|
||||
pt.x = x + (w - sz.x);
|
||||
}
|
||||
else if (flag & wxEXPAND)
|
||||
{
|
||||
sz.x = w;
|
||||
}
|
||||
|
||||
if (flag & wxALIGN_CENTER_VERTICAL)
|
||||
{
|
||||
@@ -1540,6 +1546,10 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h )
|
||||
{
|
||||
pt.y = y + (h - sz.y);
|
||||
}
|
||||
else if ( flag & wxEXPAND )
|
||||
{
|
||||
sz.y = h;
|
||||
}
|
||||
}
|
||||
|
||||
item->SetDimension(pt, sz);
|
||||
|
@@ -136,4 +136,23 @@ void GridSizerTestCase::Expand()
|
||||
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y),
|
||||
children[2]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( sizeRest, children[3]->GetSize() );
|
||||
|
||||
// With expand and another alignment flag, they should expand only in the
|
||||
// direction in which the alignment is not given.
|
||||
SetChildren(children, wxSizerFlags().Expand().CentreVertical());
|
||||
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y),
|
||||
children[1]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( sizeChild, children[2]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( wxSize(sizeRest.x, sizeChild.y),
|
||||
children[3]->GetSize() );
|
||||
|
||||
// Same as above but mirrored.
|
||||
SetChildren(children, wxSizerFlags().Expand().CentreHorizontal());
|
||||
CPPUNIT_ASSERT_EQUAL( sizeChild, children[0]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( sizeChild, children[1]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y),
|
||||
children[2]->GetSize() );
|
||||
CPPUNIT_ASSERT_EQUAL( wxSize(sizeChild.x, sizeRest.y),
|
||||
children[3]->GetSize() );
|
||||
}
|
||||
|
Reference in New Issue
Block a user