Improve layout in the samples to avoid problems under Mac.

Changes the samples to look better under Mac and avoid the worst problems such
as overlapping buttons or truncated controls.

Closes #11651.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70152 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-28 13:51:21 +00:00
parent 7f3f059ac5
commit d159e96495
4 changed files with 97 additions and 36 deletions

View File

@@ -131,7 +131,7 @@ MyFrame::MyFrame(const wxString& title)
wxPanel *panel = new wxPanel( this, -1 ); wxPanel *panel = new wxPanel( this, -1 );
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
main_sizer->Add( new wxButton( panel, ID_Write, "Get clipboard text" ) ); main_sizer->Add( new wxButton( panel, ID_Write, "Get clipboard text" ), 0, wxALL, 5 );
m_textctrl = new wxTextCtrl( panel, ID_Text, "", wxDefaultPosition, m_textctrl = new wxTextCtrl( panel, ID_Text, "", wxDefaultPosition,
wxDefaultSize, wxTE_MULTILINE ); wxDefaultSize, wxTE_MULTILINE );
main_sizer->Add( m_textctrl, 1, wxGROW ); main_sizer->Add( m_textctrl, 1, wxGROW );

View File

@@ -198,11 +198,16 @@ MyFrame::MyFrame()
m_collPane = new wxCollapsiblePane(this, -1, wxT("test!")); m_collPane = new wxCollapsiblePane(this, -1, wxT("test!"));
wxWindow *win = m_collPane->GetPane(); wxWindow *win = m_collPane->GetPane();
m_paneSizer = new wxBoxSizer( wxVERTICAL ); m_paneSizer = new wxBoxSizer( wxHORIZONTAL );
m_paneSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT ); wxBoxSizer* paneSubSizer = new wxBoxSizer( wxVERTICAL );
m_paneSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT ); m_paneSizer->AddSpacer( 20 );
m_paneSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT ); m_paneSizer->Add( paneSubSizer, 1 );
m_paneSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT );
paneSubSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT | wxALL, 3 );
paneSubSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT | wxALL, 3 );
paneSubSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT | wxALL, 3 );
paneSubSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT | wxALL, 3 );
win->SetSizer( m_paneSizer ); win->SetSizer( m_paneSizer );
} }

View File

@@ -927,7 +927,7 @@ MyFrame::MyFrame(const wxString& title)
panel->SetSizer( topSizer ); panel->SetSizer( topSizer );
topSizer->SetSizeHints( panel ); topSizer->SetSizeHints( panel );
SetSize(740,400); Fit();
Centre(); Centre();
} }

View File

@@ -25,6 +25,7 @@
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/artprov.h" #include "wx/artprov.h"
#include "wx/cshelp.h" #include "wx/cshelp.h"
#include "wx/gbsizer.h"
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
#include "wx/tooltip.h" #include "wx/tooltip.h"
@@ -731,6 +732,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_book->SetImageList(imagelist); m_book->SetImageList(imagelist);
#endif #endif
// ------------------------------------------------------------------------
// listbox page
// ------------------------------------------------------------------------
wxPanel *panel = new wxPanel(m_book); wxPanel *panel = new wxPanel(m_book);
m_listbox = new wxListBox( panel, ID_LISTBOX, m_listbox = new wxListBox( panel, ID_LISTBOX,
wxPoint(10,10), wxSize(120,70), wxPoint(10,10), wxSize(120,70),
@@ -761,6 +765,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
panel->SetCursor(wxCursor(wxCURSOR_HAND)); panel->SetCursor(wxCursor(wxCURSOR_HAND));
m_book->AddPage(panel, wxT("wxListBox"), true, Image_List); m_book->AddPage(panel, wxT("wxListBox"), true, Image_List);
// ------------------------------------------------------------------------
// choice page
// ------------------------------------------------------------------------
#if wxUSE_CHOICE #if wxUSE_CHOICE
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
m_choice = new MyChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices ); m_choice = new MyChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,wxDefaultCoord), 5, choices );
@@ -782,6 +789,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_book->AddPage(panel, wxT("wxChoice"), false, Image_Choice); m_book->AddPage(panel, wxT("wxChoice"), false, Image_Choice);
#endif // wxUSE_CHOICE #endif // wxUSE_CHOICE
// ------------------------------------------------------------------------
// combo page
// ------------------------------------------------------------------------
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
(void)new wxStaticBox( panel, wxID_ANY, wxT("&Box around combobox"), (void)new wxStaticBox( panel, wxID_ANY, wxT("&Box around combobox"),
wxPoint(5, 5), wxSize(150, 100)); wxPoint(5, 5), wxSize(150, 100));
@@ -800,6 +810,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
(void)new wxCheckBox( panel, ID_COMBO_ENABLE, wxT("&Disable"), wxPoint(20,130), wxSize(140,30) ); (void)new wxCheckBox( panel, ID_COMBO_ENABLE, wxT("&Disable"), wxPoint(20,130), wxSize(140,30) );
m_book->AddPage(panel, wxT("wxComboBox"), false, Image_Combo); m_book->AddPage(panel, wxT("wxComboBox"), false, Image_Combo);
// ------------------------------------------------------------------------
// radio box
// ------------------------------------------------------------------------
wxString choices2[] = wxString choices2[] =
{ {
wxT("First"), wxT("Second"), wxT("First"), wxT("Second"),
@@ -809,18 +822,24 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
}; };
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
new MyRadioBox(panel, ID_RADIOBOX2, wxT("&That"), wxGridBagSizer* radio_page_sizer = new wxGridBagSizer(5, 5);
wxPoint(10,160), wxDefaultSize,
WXSIZEOF(choices2), choices2,
1, wxRA_SPECIFY_ROWS );
m_radio = new wxRadioBox(panel, ID_RADIOBOX, wxT("T&his"), m_radio = new wxRadioBox(panel, ID_RADIOBOX, wxT("T&his"),
wxPoint(10,10), wxDefaultSize, wxPoint(10,10), wxDefaultSize,
WXSIZEOF(choices), choices, WXSIZEOF(choices), choices,
1, wxRA_SPECIFY_COLS ); 1, wxRA_SPECIFY_COLS );
MyRadioBox* mybox = new MyRadioBox(panel, ID_RADIOBOX2, wxT("&That"),
wxPoint(10,160), wxDefaultSize,
WXSIZEOF(choices2), choices2,
1, wxRA_SPECIFY_ROWS );
radio_page_sizer->Add( m_radio, wxGBPosition(0,0), wxGBSpan(2,1) );
radio_page_sizer->Add( mybox, wxGBPosition(2,0), wxGBSpan(2,1) );
#if wxUSE_HELP #if wxUSE_HELP
for( unsigned int item = 0; item < WXSIZEOF(choices); ++item ) for (unsigned int item = 0; item < WXSIZEOF(choices); ++item)
m_radio->SetItemHelpText( item, wxString::Format( wxT("Help text for \"%s\""), choices[item].c_str() ) ); m_radio->SetItemHelpText( item, wxString::Format( wxT("Help text for \"%s\""),
choices[item].c_str() ) );
// erase help text for the second item // erase help text for the second item
m_radio->SetItemHelpText( 1, wxT("") ); m_radio->SetItemHelpText( 1, wxT("") );
@@ -828,26 +847,42 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_radio->SetHelpText( wxT("Default helptext for wxRadioBox") ); m_radio->SetHelpText( wxT("Default helptext for wxRadioBox") );
#endif // wxUSE_HELP #endif // wxUSE_HELP
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, wxT("Select #&2"), wxPoint(180,30), wxSize(140,30) ); wxButton* select_two = new wxButton ( panel, ID_RADIOBOX_SEL_NUM, wxT("Select #&2") );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, wxT("&Select 'This'"), wxPoint(180,80), wxSize(140,30) ); wxButton* select_this = new wxButton ( panel, ID_RADIOBOX_SEL_STR, wxT("&Select 'This'") );
m_fontButton = new wxButton( panel, ID_SET_FONT, wxT("Set &more Italic font"), wxPoint(340,30), wxSize(140,30) ); m_fontButton = new wxButton ( panel, ID_SET_FONT, wxT("Set &more Italic font") );
(void)new wxButton( panel, ID_RADIOBOX_FONT, wxT("Set &Italic font"), wxPoint(340,80), wxSize(140,30) ); wxButton* set_italic = new wxButton ( panel, ID_RADIOBOX_FONT, wxT("Set &Italic font") );
(void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, wxT("&Disable"), wxPoint(340,130), wxDefaultSize ); wxCheckBox* disable_cb = new wxCheckBox( panel, ID_RADIOBOX_ENABLE, wxT("&Disable") );
wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, wxT("Radiobutton1"),
wxRadioButton *rb = new wxRadioButton( panel, ID_RADIOBUTTON_1, wxT("Radiobutton1"), wxPoint(210,170), wxDefaultSize, wxRB_GROUP ); wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
wxRadioButton *rb2 = new wxRadioButton( panel, ID_RADIOBUTTON_2, wxT("&Radiobutton2"),
wxDefaultPosition, wxDefaultSize );
rb->SetValue( false ); rb->SetValue( false );
(void)new wxRadioButton( panel, ID_RADIOBUTTON_2, wxT("&Radiobutton2"), wxPoint(340,170), wxDefaultSize );
radio_page_sizer->Add( select_two, wxGBPosition(0, 1), wxDefaultSpan, wxALL , 10 );
radio_page_sizer->Add( select_this, wxGBPosition(1, 1), wxDefaultSpan, wxALL , 10 );
radio_page_sizer->Add( m_fontButton, wxGBPosition(0, 2), wxDefaultSpan, wxALL , 10 );
radio_page_sizer->Add( set_italic, wxGBPosition(1, 2), wxDefaultSpan, wxALL , 10 );
radio_page_sizer->Add( disable_cb, wxGBPosition(2, 2), wxDefaultSpan, wxLEFT | wxRIGHT, 10 );
radio_page_sizer->Add( rb, wxGBPosition(3, 1), wxDefaultSpan, wxLEFT | wxRIGHT, 10 );
radio_page_sizer->Add( rb2, wxGBPosition(3, 2), wxDefaultSpan, wxLEFT | wxRIGHT, 10 );
panel->SetSizer( radio_page_sizer );
m_book->AddPage(panel, wxT("wxRadioBox"), false, Image_Radio); m_book->AddPage(panel, wxT("wxRadioBox"), false, Image_Radio);
// ------------------------------------------------------------------------
// gauge and slider
// ------------------------------------------------------------------------
#if wxUSE_SLIDER && wxUSE_GAUGE #if wxUSE_SLIDER && wxUSE_GAUGE
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *gauge_page_vsizer = new wxBoxSizer( wxVERTICAL );
panel->SetSizer( main_sizer );
wxBoxSizer *gauge_page_first_row_sizer = new wxBoxSizer( wxHORIZONTAL );
wxStaticBoxSizer *gauge_sizer = new wxStaticBoxSizer( wxHORIZONTAL, panel, wxT("&wxGauge and wxSlider") ); wxStaticBoxSizer *gauge_sizer = new wxStaticBoxSizer( wxHORIZONTAL, panel, wxT("&wxGauge and wxSlider") );
main_sizer->Add( gauge_sizer, 0, wxALL, 5 ); gauge_page_first_row_sizer->Add( gauge_sizer, 0, wxALL, 5 );
wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL );
gauge_sizer->Add( sz ); gauge_sizer->Add( sz );
m_gauge = new wxGauge( panel, wxID_ANY, 200, wxDefaultPosition, wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER ); m_gauge = new wxGauge( panel, wxID_ANY, 200, wxDefaultPosition, wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
@@ -868,7 +903,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
wxStaticBox *sb = new wxStaticBox( panel, wxID_ANY, wxT("&Explanation"), wxStaticBox *sb = new wxStaticBox( panel, wxID_ANY, wxT("&Explanation"),
wxDefaultPosition, wxDefaultSize ); //, wxALIGN_CENTER ); wxDefaultPosition, wxDefaultSize ); //, wxALIGN_CENTER );
wxStaticBoxSizer *wrapping_sizer = new wxStaticBoxSizer( sb, wxVERTICAL ); wxStaticBoxSizer *wrapping_sizer = new wxStaticBoxSizer( sb, wxVERTICAL );
main_sizer->Add( wrapping_sizer, 0, wxALL, 5 ); gauge_page_first_row_sizer->Add( wrapping_sizer, 0, wxALL, 5 );
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
// No wrapping text in wxStaticText yet :-( // No wrapping text in wxStaticText yet :-(
@@ -892,7 +927,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
wrapping_sizer->Add( m_wrappingText ); wrapping_sizer->Add( m_wrappingText );
wxStaticBoxSizer *non_wrapping_sizer = new wxStaticBoxSizer( wxVERTICAL, panel, wxT("Non-wrapping") ); wxStaticBoxSizer *non_wrapping_sizer = new wxStaticBoxSizer( wxVERTICAL, panel, wxT("Non-wrapping") );
main_sizer->Add( non_wrapping_sizer, 0, wxALL, 5 ); gauge_page_first_row_sizer->Add( non_wrapping_sizer, 0, wxALL, 5 );
m_nonWrappingText = new wxStaticText( panel, wxID_ANY, m_nonWrappingText = new wxStaticText( panel, wxID_ANY,
wxT("This static text has two lines.\nThey do not wrap."), wxT("This static text has two lines.\nThey do not wrap."),
@@ -901,33 +936,51 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
); );
non_wrapping_sizer->Add( m_nonWrappingText ); non_wrapping_sizer->Add( m_nonWrappingText );
(void)new wxButton( panel, ID_BTNNEWTEXT, wxT("New text"), wxPoint(450, 160) ); gauge_page_vsizer->Add( gauge_page_first_row_sizer, 1 );
wxBoxSizer *gauge_page_second_row_sizer = new wxBoxSizer( wxHORIZONTAL );
int initialSpinValue = -5; int initialSpinValue = -5;
wxString s; wxString s;
s << initialSpinValue; s << initialSpinValue;
m_spintext = new wxTextCtrl( panel, wxID_ANY, s, wxPoint(20,160), wxSize(80,wxDefaultCoord) ); m_spintext = new wxTextCtrl( panel, wxID_ANY, s );
gauge_page_second_row_sizer->Add( m_spintext, 0, wxALL, 5 );
#if wxUSE_SPINBTN #if wxUSE_SPINBTN
m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,160), wxSize(-1, m_spintext->GetSize().y) ); m_spinbutton = new wxSpinButton( panel, ID_SPIN );
m_spinbutton->SetRange(-40,30); m_spinbutton->SetRange(-40,30);
m_spinbutton->SetValue(initialSpinValue); m_spinbutton->SetValue(initialSpinValue);
gauge_page_second_row_sizer->Add( m_spinbutton, 0, wxALL, 5 );
#if wxUSE_PROGRESSDLG
m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, wxT("&Show progress dialog"),
wxPoint(300, 160) );
#endif // wxUSE_PROGRESSDLG
#endif // wxUSE_SPINBTN #endif // wxUSE_SPINBTN
#if wxUSE_SPINCTRL #if wxUSE_SPINCTRL
m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, wxEmptyString, wxPoint(200, 160), wxSize(80, wxDefaultCoord) ); m_spinctrl = new wxSpinCtrl( panel, ID_SPINCTRL, wxEmptyString );
m_spinctrl->SetRange(-10,30); m_spinctrl->SetRange(-10,30);
m_spinctrl->SetValue(15); m_spinctrl->SetValue(15);
gauge_page_second_row_sizer->Add( m_spinctrl, 0, wxALL, 5 );
#endif // wxUSE_SPINCTRL #endif // wxUSE_SPINCTRL
#if wxUSE_SPINBTN
#if wxUSE_PROGRESSDLG
m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, wxT("&Show progress dialog") );
gauge_page_second_row_sizer->Add( m_btnProgress, 0, wxALL, 5 );
#endif // wxUSE_PROGRESSDLG
#endif // wxUSE_SPINBTN
wxButton* newTextButton = new wxButton( panel, ID_BTNNEWTEXT, wxT("New text"));
gauge_page_second_row_sizer->Add( newTextButton, 0, wxALL, 5 );
gauge_page_vsizer->Add(gauge_page_second_row_sizer, 1);
panel->SetSizer( gauge_page_vsizer );
m_book->AddPage(panel, wxT("wxGauge"), false, Image_Gauge); m_book->AddPage(panel, wxT("wxGauge"), false, Image_Gauge);
#endif // wxUSE_SLIDER && wxUSE_GAUGE #endif // wxUSE_SLIDER && wxUSE_GAUGE
// ------------------------------------------------------------------------
// wxBitmapXXX
// ------------------------------------------------------------------------
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
#if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet. #if !defined(__WXMOTIF__) // wxStaticBitmap not working under Motif yet.
@@ -988,7 +1041,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_book->AddPage(panel, wxT("wxBitmapXXX")); m_book->AddPage(panel, wxT("wxBitmapXXX"));
// sizer // ------------------------------------------------------------------------
// sizer page
// ------------------------------------------------------------------------
panel = new wxPanel(m_book); panel = new wxPanel(m_book);
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );