WxSizer
lastmod 2018-08-17created 2015-03-1110 edits
Proportion
Functions such as Add() have an argument called proportion.
Below is the description of the Proportion argument.
| Although the meaning of this parameter is undefined in wxSizer, it is used in wxBoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wxBoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wxBoxSizer. For example, you might have a horizontal wxBoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer's horizontal dimension. |
In summary:
- It is not used in wxSizer.
- It is used in wxBoxSizer.
- It is the ratio of space taken up by the children of a wxBoxSizer.
- If this value is
0, the size is not changed (stands for not changeable). - If greater than
0, it is interpreted relative to the ratios (Proportion) of the children.
In other words, it plays a role similar to weight in Android LinearLayout. And wxBoxSizer plays the role of LinearLayout.
FLAG
Flag values are covered in wxSizerFlags.
ALIGN CENTER
For center alignment, see wxSizerFlags#ALIGN_CENTER.
Media Controller Sizer Sample
Below is a sample widget layout for media controls:
MediaControlPanel::MediaControlPanel(wxWindow * parent
, wxWindowID id, wxPoint const & pos, wxSize const & size)
: wxPanel(parent, id, pos, size)
{
wxBoxSizer * sizer = new wxBoxSizer(wxHORIZONTAL);
{
int const kButtonProportion = 0;
int const kProgressProportion = 1;
int const kBorder = wxSizerFlags::GetDefaultBorder();
R r;
wxBitmap play(r.icon().get("media-playback-start-5.png"), wxBITMAP_TYPE_PNG);
wxBitmap stop(r.icon().get("media-playback-stop-5.png"), wxBITMAP_TYPE_PNG);
wxBitmap prev(r.icon().get("media-skip-backward-5.png"), wxBITMAP_TYPE_PNG);
wxBitmap next(r.icon().get("media-skip-forward-5.png"), wxBITMAP_TYPE_PNG);
_play_button = new wxBitmapButton(this, ID_MEDIA_CONTROL_PANEL__PLAY_BUTTON, play);
_stop_button = new wxBitmapButton(this, ID_MEDIA_CONTROL_PANEL__STOP_BUTTON, stop);
_prev_button = new wxBitmapButton(this, ID_MEDIA_CONTROL_PANEL__PREV_BUTTON, prev);
_next_button = new wxBitmapButton(this, ID_MEDIA_CONTROL_PANEL__NEXT_BUTTON, next);
int const kProgressMin = 0;
int const kProgressMax = 100;
_video_progress = new wxSlider(this, ID_MEDIA_CONTROL_PANEL__VIDEO_PROGRESS
, kProgressMin, kProgressMin, kProgressMax, wxDefaultPosition, wxDefaultSize
, wxSL_BOTH | wxSL_MIN_MAX_LABELS);
wxSizerFlags flags = wxSizerFlags().Proportion(kButtonProportion).Align(wxALIGN_LEFT)
.Border(wxUP | wxDOWN | wxRIGHT, kBorder);
sizer->Add(_play_button, kButtonProportion, wxALIGN_LEFT | wxALL, kBorder);
sizer->Add(_stop_button, flags);
sizer->Add(_prev_button, flags);
sizer->Add(_next_button, flags);
sizer->Add(_video_progress, flags.Proportion(kProgressProportion));
}
SetSizer(sizer);
Center();
}
ImageListView
Below is a sample widget layout for an image list view:
MainFrame::MainFrame(wxString const & title
, wxWindowID id, wxPoint const & pos, wxSize const & size, long style)
: wxFrame(nullptr, id, title, pos, size, style)
{
createMenu();
int const kBorder = 5;
wxBoxSizer * control_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer * button_sizer = new wxBoxSizer(wxHORIZONTAL);
{
_list = new wxListCtrl(this, ID_MAINFRAME__IMAGE_LISTCTRL);
control_sizer->Add(_list, 1, wxEXPAND, kBorder);
wxButton * refresh = new wxButton(this, ID_MAINFRAME__REFRESH_BUTTON, wxT("Refresh"));
wxButton * exit = new wxButton(this, ID_MAINFRAME__EXIT_BUTTON, wxT("Exit"));
button_sizer->Add(refresh);
button_sizer->Add(exit);
}
control_sizer->Add(button_sizer, 0, wxALIGN_RIGHT | wxALL, kBorder);
SetSizer(control_sizer);
refresh();
Centre();
}