Optimized sizers to not call CalcMin more often than neccessary
Window items added with wxFIXED_MINSIZE flag will set the window's minsize to its curent size. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28011 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -74,10 +74,11 @@ public:
|
|||||||
|
|
||||||
wxSize GetMinSize() const
|
wxSize GetMinSize() const
|
||||||
{ return m_minSize; }
|
{ return m_minSize; }
|
||||||
|
wxSize GetMinSizeWithBorder() const;
|
||||||
|
|
||||||
void SetMinSize(const wxSize& size)
|
void SetMinSize(const wxSize& size)
|
||||||
{
|
{
|
||||||
if (IsWindow() && !(m_flag & wxFIXED_MINSIZE))
|
if (IsWindow()) m_window->SetMinSize(size);
|
||||||
m_window->SetSizeHints(size);
|
|
||||||
m_minSize = size;
|
m_minSize = size;
|
||||||
}
|
}
|
||||||
void SetMinSize( int x, int y )
|
void SetMinSize( int x, int y )
|
||||||
@@ -451,6 +452,9 @@ protected:
|
|||||||
int m_flexDirection;
|
int m_flexDirection;
|
||||||
wxFlexSizerGrowMode m_growMode;
|
wxFlexSizerGrowMode m_growMode;
|
||||||
|
|
||||||
|
// saves CalcMin result to optimize RecalcSizes
|
||||||
|
wxSize m_calculatedMinSize;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_CLASS(wxFlexGridSizer)
|
DECLARE_CLASS(wxFlexGridSizer)
|
||||||
DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
|
DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
|
||||||
|
@@ -494,7 +494,8 @@ wxSize wxGridBagSizer::CalcMin()
|
|||||||
for (idx=0; idx < m_rows; idx++)
|
for (idx=0; idx < m_rows; idx++)
|
||||||
height += m_rowHeights[idx] + ( idx == m_rows-1 ? 0 : m_vgap );
|
height += m_rowHeights[idx] + ( idx == m_rows-1 ? 0 : m_vgap );
|
||||||
|
|
||||||
return wxSize(width, height);
|
m_calculatedMinSize = wxSize(width, height);
|
||||||
|
return m_calculatedMinSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,9 +505,6 @@ void wxGridBagSizer::RecalcSizes()
|
|||||||
if (m_children.GetCount() == 0)
|
if (m_children.GetCount() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Calculates minsize and populates m_rowHeights and m_colWidths
|
|
||||||
wxSize minsz( CalcMin() );
|
|
||||||
|
|
||||||
wxPoint pt( GetPosition() );
|
wxPoint pt( GetPosition() );
|
||||||
wxSize sz( GetSize() );
|
wxSize sz( GetSize() );
|
||||||
|
|
||||||
@@ -514,7 +512,7 @@ void wxGridBagSizer::RecalcSizes()
|
|||||||
m_cols = m_colWidths.GetCount();
|
m_cols = m_colWidths.GetCount();
|
||||||
int idx, width, height;
|
int idx, width, height;
|
||||||
|
|
||||||
AdjustForGrowables(sz, minsz, m_rows, m_cols);
|
AdjustForGrowables(sz, m_calculatedMinSize, m_rows, m_cols);
|
||||||
|
|
||||||
// Find the start positions on the window of the rows and columns
|
// Find the start positions on the window of the rows and columns
|
||||||
wxArrayInt rowpos;
|
wxArrayInt rowpos;
|
||||||
|
@@ -99,7 +99,6 @@ wxSizerItem::wxSizerItem( int width, int height, int proportion, int flag, int b
|
|||||||
wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
|
wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData )
|
||||||
: m_window( window )
|
: m_window( window )
|
||||||
, m_sizer( NULL )
|
, m_sizer( NULL )
|
||||||
, m_minSize( window->GetSize() ) // minimal size is the initial size
|
|
||||||
, m_proportion( proportion )
|
, m_proportion( proportion )
|
||||||
, m_border( border )
|
, m_border( border )
|
||||||
, m_flag( flag )
|
, m_flag( flag )
|
||||||
@@ -109,6 +108,10 @@ wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border
|
|||||||
// aspect ratio calculated from initial size
|
// aspect ratio calculated from initial size
|
||||||
SetRatio( m_minSize );
|
SetRatio( m_minSize );
|
||||||
|
|
||||||
|
if (flag & wxFIXED_MINSIZE)
|
||||||
|
window->SetMinSize(window->GetSize());
|
||||||
|
m_minSize = window->GetSize();
|
||||||
|
|
||||||
// m_size is calculated later
|
// m_size is calculated later
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,25 +181,29 @@ wxSize wxSizerItem::GetSize() const
|
|||||||
wxSize wxSizerItem::CalcMin()
|
wxSize wxSizerItem::CalcMin()
|
||||||
{
|
{
|
||||||
wxSize ret;
|
wxSize ret;
|
||||||
|
|
||||||
if (IsSizer())
|
if (IsSizer())
|
||||||
{
|
{
|
||||||
ret = m_sizer->GetMinSize();
|
m_minSize = m_sizer->GetMinSize();
|
||||||
|
|
||||||
// if we have to preserve aspect ratio _AND_ this is
|
// if we have to preserve aspect ratio _AND_ this is
|
||||||
// the first-time calculation, consider ret to be initial size
|
// the first-time calculation, consider ret to be initial size
|
||||||
if ((m_flag & wxSHAPED) && !m_ratio)
|
if ((m_flag & wxSHAPED) && !m_ratio)
|
||||||
SetRatio(ret);
|
SetRatio(ret);
|
||||||
}
|
}
|
||||||
else
|
else if ( IsWindow() )
|
||||||
{
|
|
||||||
if ( IsWindow() && !(m_flag & wxFIXED_MINSIZE) )
|
|
||||||
{
|
{
|
||||||
// Since the size of the window may change during runtime, we
|
// Since the size of the window may change during runtime, we
|
||||||
// should use the current minimal/best size.
|
// should use the current minimal/best size.
|
||||||
m_minSize = m_window->GetBestFittingSize();
|
m_minSize = m_window->GetBestFittingSize();
|
||||||
}
|
}
|
||||||
ret = m_minSize;
|
|
||||||
}
|
return GetMinSizeWithBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxSizerItem::GetMinSizeWithBorder() const
|
||||||
|
{
|
||||||
|
wxSize ret = m_minSize;
|
||||||
|
|
||||||
if (m_flag & wxWEST)
|
if (m_flag & wxWEST)
|
||||||
ret.x += m_border;
|
ret.x += m_border;
|
||||||
@@ -210,6 +217,7 @@ wxSize wxSizerItem::CalcMin()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxSizerItem::SetDimension( wxPoint pos, wxSize size )
|
void wxSizerItem::SetDimension( wxPoint pos, wxSize size )
|
||||||
{
|
{
|
||||||
if (m_flag & wxSHAPED)
|
if (m_flag & wxSHAPED)
|
||||||
@@ -596,7 +604,11 @@ void wxSizer::FitInside( wxWindow *window )
|
|||||||
|
|
||||||
void wxSizer::Layout()
|
void wxSizer::Layout()
|
||||||
{
|
{
|
||||||
|
// (re)calculates minimums needed for each item and other preparations
|
||||||
|
// for layout
|
||||||
CalcMin();
|
CalcMin();
|
||||||
|
|
||||||
|
// Applies the layout and repositions/resizes the items
|
||||||
RecalcSizes();
|
RecalcSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,7 +823,7 @@ bool wxSizer::DoSetItemMinSize( size_t index, int width, int height )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ... but the minimal size of spacers and windows in stored in them
|
// ... but the minimal size of spacers and windows is stored via the item
|
||||||
item->SetMinSize( width, height );
|
item->SetMinSize( width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1093,9 +1105,8 @@ void wxFlexGridSizer::RecalcSizes()
|
|||||||
|
|
||||||
wxPoint pt( GetPosition() );
|
wxPoint pt( GetPosition() );
|
||||||
wxSize sz( GetSize() );
|
wxSize sz( GetSize() );
|
||||||
wxSize minsz( CalcMin() );
|
|
||||||
|
|
||||||
AdjustForGrowables(sz, minsz, nrows, ncols);
|
AdjustForGrowables(sz, m_calculatedMinSize, nrows, ncols);
|
||||||
|
|
||||||
sz = wxSize( pt.x + sz.x, pt.y + sz.y );
|
sz = wxSize( pt.x + sz.x, pt.y + sz.y );
|
||||||
|
|
||||||
@@ -1180,7 +1191,8 @@ wxSize wxFlexGridSizer::CalcMin()
|
|||||||
if ( m_rowHeights[ row ] != -1 )
|
if ( m_rowHeights[ row ] != -1 )
|
||||||
height += m_rowHeights[ row ] + ( row == nrows-1 ? 0 : m_vgap );
|
height += m_rowHeights[ row ] + ( row == nrows-1 ? 0 : m_vgap );
|
||||||
|
|
||||||
return wxSize( width, height );
|
m_calculatedMinSize = wxSize( width, height );
|
||||||
|
return m_calculatedMinSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFlexGridSizer::AdjustForFlexDirection()
|
void wxFlexGridSizer::AdjustForFlexDirection()
|
||||||
@@ -1375,7 +1387,7 @@ void wxBoxSizer::RecalcSizes()
|
|||||||
|
|
||||||
if (item->IsShown())
|
if (item->IsShown())
|
||||||
{
|
{
|
||||||
wxSize size( item->CalcMin() );
|
wxSize size( item->GetMinSizeWithBorder() );
|
||||||
|
|
||||||
if (m_orient == wxVERTICAL)
|
if (m_orient == wxVERTICAL)
|
||||||
{
|
{
|
||||||
@@ -1446,11 +1458,15 @@ wxSize wxBoxSizer::CalcMin()
|
|||||||
m_fixedWidth = 0;
|
m_fixedWidth = 0;
|
||||||
m_fixedHeight = 0;
|
m_fixedHeight = 0;
|
||||||
|
|
||||||
|
// precalc item minsizes and count proportions
|
||||||
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
|
wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
|
||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxSizerItem *item = node->GetData();
|
wxSizerItem *item = node->GetData();
|
||||||
|
|
||||||
|
if (item->IsShown())
|
||||||
|
item->CalcMin(); // result is stored in the item
|
||||||
|
|
||||||
if (item->IsShown() && item->GetProportion() != 0)
|
if (item->IsShown() && item->GetProportion() != 0)
|
||||||
m_stretchable += item->GetProportion();
|
m_stretchable += item->GetProportion();
|
||||||
|
|
||||||
@@ -1468,7 +1484,7 @@ wxSize wxBoxSizer::CalcMin()
|
|||||||
if (item->IsShown() && item->GetProportion() != 0)
|
if (item->IsShown() && item->GetProportion() != 0)
|
||||||
{
|
{
|
||||||
int stretch = item->GetProportion();
|
int stretch = item->GetProportion();
|
||||||
wxSize size( item->CalcMin() );
|
wxSize size( item->GetMinSizeWithBorder() );
|
||||||
int minSize;
|
int minSize;
|
||||||
|
|
||||||
// Integer division rounded up is (a + b - 1) / b
|
// Integer division rounded up is (a + b - 1) / b
|
||||||
@@ -1493,7 +1509,7 @@ wxSize wxBoxSizer::CalcMin()
|
|||||||
|
|
||||||
if (item->IsShown())
|
if (item->IsShown())
|
||||||
{
|
{
|
||||||
wxSize size( item->CalcMin() );
|
wxSize size( item->GetMinSizeWithBorder() );
|
||||||
if (item->GetProportion() != 0)
|
if (item->GetProportion() != 0)
|
||||||
{
|
{
|
||||||
if (m_orient == wxHORIZONTAL)
|
if (m_orient == wxHORIZONTAL)
|
||||||
|
Reference in New Issue
Block a user