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