Modify wxBoxSizer minimal size calculations to respect the proportions.

Make wxBoxSizer minimal size big enough to not only give each item enough
space to satisfy its minimal size but also to respect the proportions among
the items by default.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-05-22 14:57:34 +00:00
parent b534aeb219
commit f27d62bf2f
2 changed files with 80 additions and 4 deletions

View File

@@ -43,10 +43,12 @@ private:
CPPUNIT_TEST_SUITE( BoxSizerTestCase );
CPPUNIT_TEST( Size1 );
CPPUNIT_TEST( Size3 );
CPPUNIT_TEST( CalcMin );
CPPUNIT_TEST_SUITE_END();
void Size1();
void Size3();
void CalcMin();
wxWindow *m_win;
wxSizer *m_sizer;
@@ -248,3 +250,54 @@ void BoxSizerTestCase::Size3()
}
}
}
void BoxSizerTestCase::CalcMin()
{
static const unsigned NUM_TEST_ITEM = 3;
static const struct CalcMinTestData
{
// proportions of the elements, if one of them is -1 it means to not
// use this window at all in this test
int prop[NUM_TEST_ITEM];
// minimal sizes of the elements in the sizer direction
int minsize[NUM_TEST_ITEM];
// the expected minimal sizer size
int total;
} calcMinTestData[] =
{
{ { 1, 1, -1 }, { 30, 50, 0 }, 100 },
{ { 1, 1, 0 }, { 30, 50, 20 }, 120 },
{ { 10, 10, -1 }, { 30, 50, 0 }, 100 },
{ { 1, 2, 2 }, { 50, 50, 80 }, 250 },
{ { 1, 2, 2 }, { 100, 50, 80 }, 500 },
};
unsigned n;
wxWindow *child[NUM_TEST_ITEM];
for ( n = 0; n < NUM_TEST_ITEM; n++ )
child[n] = new wxWindow(m_win, wxID_ANY);
for ( unsigned i = 0; i < WXSIZEOF(calcMinTestData); i++ )
{
m_sizer->Clear();
const CalcMinTestData& cmtd = calcMinTestData[i];
for ( n = 0; n < NUM_TEST_ITEM; n++ )
{
if ( cmtd.prop[n] != -1 )
{
child[n]->SetInitialSize(wxSize(cmtd.minsize[n], -1));
m_sizer->Add(child[n], wxSizerFlags(cmtd.prop[n]));
}
}
WX_ASSERT_EQUAL_MESSAGE
(
("In test #%u", i),
cmtd.total, m_sizer->CalcMin().x
);
}
}