Finished porting Robin's wxSizers
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3320 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
class wxNewSizerItem;
|
||||
class wxNewSizer;
|
||||
class wxBorderNewSizer;
|
||||
class wxBoxNewSizer;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -136,6 +137,29 @@ protected:
|
||||
int m_sides;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxBoxNewSizer
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxBoxNewSizer: public wxNewSizer
|
||||
{
|
||||
public:
|
||||
wxBoxNewSizer( int orient );
|
||||
|
||||
void RecalcSizes();
|
||||
wxSize CalcMin();
|
||||
|
||||
int GetOrientation()
|
||||
{ return m_orient; }
|
||||
|
||||
protected:
|
||||
int m_orient;
|
||||
int m_stretchable;
|
||||
int m_minWidth;
|
||||
int m_minHeight;
|
||||
int m_fixedWidth;
|
||||
int m_fixedHeight;
|
||||
};
|
||||
|
||||
#endif
|
||||
// __WXSIZER_H__
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include "wx/sizer.h"
|
||||
#include "wx/statline.h"
|
||||
|
||||
#include "layout.h"
|
||||
|
||||
@@ -367,11 +368,59 @@ void SizerFrame::OnSize(wxSizeEvent& event)
|
||||
NewSizerFrame::NewSizerFrame(wxFrame *frame, char *title, int x, int y ):
|
||||
wxFrame(frame, -1, title, wxPoint(x, y) )
|
||||
{
|
||||
// no extra options means border all around
|
||||
topsizer = new wxBorderNewSizer();
|
||||
// we want to get a dialog that is stretchable because it
|
||||
// has a text ctrl in the middle. at the bottom, we have
|
||||
// two buttons which are not supposed to get stretched
|
||||
// and therefore we insert two spacers next to them
|
||||
|
||||
topsizer = new wxBoxNewSizer( wxVERTICAL );
|
||||
|
||||
|
||||
// 1) upper part: text ctrl
|
||||
|
||||
// make border around textctrl in all directions
|
||||
wxBorderNewSizer *text_border = new wxBorderNewSizer();
|
||||
|
||||
// make border around text ctrl 20 pixels wide
|
||||
// minimum size for the text ctrl is 60x30
|
||||
text_border->Add( new wxTextCtrl( this, -1, "My text.", wxDefaultPosition, wxSize(170,30), wxTE_MULTILINE), 5 );
|
||||
|
||||
// add text ctrl with border to top sizer
|
||||
// a value of more than zero indicates that it's stretchable
|
||||
topsizer->Add( text_border, 1 );
|
||||
|
||||
|
||||
// 2) middle part: static line
|
||||
|
||||
// make border for beauty static line
|
||||
wxBorderNewSizer *line_border = new wxBorderNewSizer();
|
||||
|
||||
// make border around static line 2 pixels wide
|
||||
// minimum size for the static line is 3x3
|
||||
line_border->Add( new wxStaticLine( this, -1, wxDefaultPosition, wxSize(170,3), wxHORIZONTAL), 5 );
|
||||
|
||||
// add text ctrl with border to top sizer
|
||||
topsizer->Add( line_border );
|
||||
|
||||
|
||||
// 3) bottom: buttons
|
||||
|
||||
// make border around button in all directions
|
||||
wxBoxNewSizer *button_sizer = new wxBoxNewSizer( wxHORIZONTAL );
|
||||
|
||||
// make border around buttons 5 pixels wide
|
||||
// minimum size for the button is its default size
|
||||
wxBorderNewSizer *button1_border = new wxBorderNewSizer();
|
||||
button1_border->Add( new wxButton( this, -1, "Hello 1", wxDefaultPosition, wxSize(80,30) ), 5 );
|
||||
button_sizer->Add( button1_border );
|
||||
|
||||
wxBorderNewSizer *button2_border = new wxBorderNewSizer();
|
||||
button2_border->Add( new wxButton( this, -1, "Hello 2", wxDefaultPosition, wxSize(80,30) ), 5 );
|
||||
button_sizer->Add( button2_border );
|
||||
|
||||
// add buttons with border to top sizer
|
||||
topsizer->Add( button_sizer );
|
||||
|
||||
// make border 20 pixels wide
|
||||
topsizer->Add( new wxButton( this, -1, "Hello" ), 20 );
|
||||
|
||||
// set frame to minimum size
|
||||
topsizer->Fit( this );
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#endif
|
||||
|
||||
#include "wx/sizer.h"
|
||||
|
||||
#include "wx/utils.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxNewSizerItem
|
||||
@@ -251,5 +251,135 @@ wxSize wxBorderNewSizer::CalcMin()
|
||||
return size;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxBoxNewSizer
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
wxBoxNewSizer::wxBoxNewSizer( int orient )
|
||||
{
|
||||
m_orient = orient;
|
||||
}
|
||||
|
||||
void wxBoxNewSizer::RecalcSizes()
|
||||
{
|
||||
if (m_children.GetCount() == 0)
|
||||
{
|
||||
SetDimension( m_position.x, m_position.y, 2, 2 );
|
||||
return;
|
||||
}
|
||||
|
||||
int delta = 0;
|
||||
int extra = 0;
|
||||
if (m_stretchable)
|
||||
{
|
||||
if (m_orient == wxHORIZONTAL)
|
||||
{
|
||||
delta = (m_size.x - m_fixedWidth) / m_stretchable;
|
||||
extra = (m_size.x - m_fixedWidth) % m_stretchable;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = (m_size.y - m_fixedHeight) / m_stretchable;
|
||||
extra = (m_size.y - m_fixedHeight) % m_stretchable;
|
||||
}
|
||||
}
|
||||
|
||||
wxPoint pt( m_position );
|
||||
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
wxNewSizerItem *item = (wxNewSizerItem*) node->Data();
|
||||
|
||||
int weight = 1;
|
||||
if (item->GetOption())
|
||||
weight = item->GetOption();
|
||||
|
||||
wxSize size( item->CalcMin() );
|
||||
|
||||
if (m_orient == wxVERTICAL)
|
||||
{
|
||||
long height = size.y;
|
||||
if (item->GetOption())
|
||||
{
|
||||
height = (delta * weight) + extra;
|
||||
extra = 0; // only the first item will get the remainder as extra size
|
||||
}
|
||||
item->SetDimension( pt, wxSize( size.x, height) );
|
||||
pt.y += height;
|
||||
}
|
||||
else
|
||||
{
|
||||
long width = size.x;
|
||||
if (item->GetOption())
|
||||
{
|
||||
width = (delta * weight) + extra;
|
||||
extra = 0; // only the first item will get the remainder as extra size
|
||||
}
|
||||
item->SetDimension( pt, wxSize(width, size.y) );
|
||||
pt.x += width;
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
wxSize wxBoxNewSizer::CalcMin()
|
||||
{
|
||||
if (m_children.GetCount() == 0)
|
||||
return wxSize(2,2);
|
||||
|
||||
m_stretchable = 0;
|
||||
m_minWidth = 0;
|
||||
m_minHeight = 0;
|
||||
m_fixedWidth = 0;
|
||||
m_fixedHeight = 0;
|
||||
|
||||
wxNode *node = m_children.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
wxNewSizerItem *item = (wxNewSizerItem*) node->Data();
|
||||
|
||||
int weight = 1;
|
||||
if (item->GetOption())
|
||||
weight = item->GetOption();
|
||||
|
||||
wxSize size( item->CalcMin() );
|
||||
|
||||
if (m_orient == wxHORIZONTAL)
|
||||
{
|
||||
m_minWidth += (size.x * weight);
|
||||
m_minHeight = wxMax( m_minHeight, size.y );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minHeight += (size.y * weight);
|
||||
m_minWidth = wxMax( m_minWidth, size.x );
|
||||
}
|
||||
|
||||
if (item->GetOption())
|
||||
{
|
||||
m_stretchable += weight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_orient == wxVERTICAL)
|
||||
{
|
||||
m_fixedHeight += size.y;
|
||||
m_fixedWidth = wxMax( m_fixedWidth, size.x );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fixedWidth += size.x;
|
||||
m_fixedHeight = wxMax( m_fixedHeight, size.y );
|
||||
}
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
return wxSize( m_minWidth, m_minHeight );
|
||||
}
|
||||
|
||||
#endif
|
||||
// __SIZERS_H__
|
||||
|
Reference in New Issue
Block a user