]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/boxsizer.tex
Prep for wxPython 2.1b3 release
[wxWidgets.git] / docs / latex / wx / boxsizer.tex
CommitLineData
8fe05782
VZ
1\section{\class{wxBoxSizer}}\label{wxboxsizer}
2
515da557
RR
3The basic idea behind a box sizer is that windows will most often be laid out in rather
4simple basic geomerty, typically in a row or a column or several hierachies of either.
5
6As an exmaple, we will construct a dialog that will contain a text field at the top and
7two buttons at the bottom. This can be seen as a top-hierarchy column with the text at
8the top and buttons at the bottom and a low-hierchary row with an OK button to the left
9and a Cancel button to the right. In many cases (particulary dialogs under Unix and
10normal frames) the main window will be resizable by the user and this change of size
11will have to get propagated to its children. In our case, we want the text area to grow
12with the dialog, whereas the button shall have a fixed size. In addition, there will be
13a thin border around all controls to make the dialog look nice and - to make matter worse -
14the buttons shall be centred as the width of the dialog changes.
15
16It is the unique feature of a box sizer, that it can grow in both directions (height and
17width) but can distribute its growth in the main direction (horizontal for a row) {\it unevenly}
18among its children. In our example case, the vertical sizer is supposed to propagate all its
19height changes to only the text area, not to the button area. This is determined by the
20{\it option} parameter when adding a window (or another sizer) to a sizer. It is interpreted
21as a weight factor, i.e. it can be zero, indicating that the window may not be resized
22at all, or above zero. If several windows have a value above zero, the value is interpreted
23relative to the sum of all weight factors of the sizer, so when adding two windows with
24a value of 1, they will both get resized equally much and each half as much as the sizer
25owning them. Then what do we do when a column sizer changes its width? This behaviour is
26controlled by {\it flags} (the second parameter of the Add() function): Zero or no flag indicates that
27the window will get aligned at the left (in a column sizer) and the top (row sizer), whereas
28wxALIGN\_RIGHT and wxALIGN\_BOTTOM will do what they say. The item can also be centered
29using the wxCENTRE flag (same as wxCENTER) or it can be forced to grow with the sizer (using
30the wxGROW flag (same as wxEXPAND)).
31
32As mentioned above, any window belonging to a sizer may have border, and it can be specified
33which of the four sides may have this border, using the wxTOP, wxLEFT, wxRIGHT and wxBOTTOM
34constants or wxALL for all directions (and you may also use wxNORTH, wxWEST etc instead). These
35flags can be used in combintaion with the alignement flags above as the second paramter of the
36Add() method using the binary or operator |. The sizer of the border also must be made known,
37and it is the third parameter in the Add() method. This means, that the entire behaviour of
38a sizer and its children can be controlled by the three parameters of the Add() method.
39
40\begin{verbatim}
41// we want to get a dialog that is stretchable because it
42// has a text ctrl at the top and two buttons at the bottom
43
44MyDialog::MyDialog(wxFrame *parent, wxWindowID id, const wxString &title ) :
45 wxDialog( parent, id, title, wxDefaultPosition, wxDefaultSize, wxDIALOG_STYLE | wxRESIZE_BORDER )
46{
47 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
48
49 // create text ctrl with minimal size 100x60
50 topsizer->Add(
51 new wxTextCtrl( this, -1, "My text.", wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE),
52 1, // make vertically stretchable
53 wxEXPAND | // make horizontally stretchable
54 wxALL, // and make border all around
55 10 ); // set border width to 10
56
57
58 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
59 button_sizer->Add(
60 new wxButton( this, wxID_OK, "OK" ),
61 0, // make horizontally unstretchable
62 wxALL, // make border all around (implicit top alignment)
63 10 ); // set border width to 10
64 button_sizer->Add(
65 new wxButton( this, wxID_CANCEL, "Cancel" ),
66 0, // make horizontally unstretchable
67 wxALL, // make border all around (implicit top alignment)
68 10 ); // set border width to 10
69
70 topsizer->Add(
71 button_sizer,
72 0, // make vertically unstretchable
73 wxCENTER ); // no border and centre horizontally
74
75 SetAutoLayout( TRUE ); // tell dialog to use sizer
76 SetSizer( topsizer ); // actually set the sizer
77
78 topsizer->Fit( this ); // set size to minimum size as calculated by the sizer
79 topsizer->SetSizeHints( this ); // set size hints to honour mininum size
80
81}
82\end{verbatim}
8fe05782
VZ
83
84
85\wxheading{Derived from}
86
87\helpref{wxSizer}{wxsizer}
4130b487 88\helpref{wxObject}{wxobject}
8fe05782
VZ
89
90\membersection{wxBoxSizer::wxBoxSizer}\label{wxboxsizerwxboxsizer}
91
92\func{}{wxBoxSizer}{\param{int }{orient}}
93
515da557
RR
94Constructor for a wxBoxSizer. {\it orient} may be either of wxVERTICAL
95or wxHORIZONTAL for creating either a column sizer or a row sizer.
8fe05782
VZ
96
97\membersection{wxBoxSizer::RecalcSizes}\label{wxboxsizerrecalcsizes}
98
99\func{void}{RecalcSizes}{\void}
100
9c884972
RR
101Implements the calculation of a box sizer's dimensions and then sets
102the size of its its children (calling \helpref{wxWindow::SetSize}{wxwindowsetsize}
103if the child is a window). It is used internally only and must not be called
104by the users. Documented for information.
8fe05782
VZ
105
106\membersection{wxBoxSizer::CalcMin}\label{wxboxsizercalcmin}
107
108\func{wxSize}{CalcMin}{\void}
109
9c884972
RR
110Implements the calculation of a box sizer's minimal. It is used internally
111only and must not be called by the users. Documented for information.
8fe05782
VZ
112
113\membersection{wxBoxSizer::GetOrientation}\label{wxboxsizergetorientation}
114
115\func{int}{GetOrientation}{\void}
116
9c884972
RR
117Returns the orientation of the boxsizer, either of wxVERTICAL
118or wxHORIZONTAL.
119