]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/twinsizes.tex
changed wxLog::OnLog(String) to take wxString instead of wxChar* to avoid unnecessary...
[wxWidgets.git] / docs / latex / wx / twinsizes.tex
... / ...
CommitLineData
1\section{Window Sizing Overview}\label{windowsizingoverview}
2
3
4
5
6It can sometimes be confusing to keep track of the various
7size-related attributes of a \helpref{wxWindow}{wxwindow}, how they
8relate to each other, and how they interact with sizers. This document
9will attempt to clear the fog a little, and give some simple
10explanations of things.
11
12{\bf BestSize}: The best size of a widget depends on what kind of widget it
13is, and usually also on the contents of the widget. For example a
14\helpref{wxListBox}{wxlistbox}'s best size will be calculated based on
15how many items it has, up to a certain limit, or a
16\helpref{wxButton}{wxbutton}'s best size will be calculated based on
17its label size, but normally won't be smaller than the platform
18default button size (unless a style flag overrides that). Get the
19picture? There is a special virtual method in the C++ window classes
20called \texttt{DoGetBestSize()} that a class needs to override if it
21wants to calculate its own best size based on its content. The default
22\texttt{DoGetBestSize()} is designed for use in container windows,
23such as \helpref{wxPanel}{wxpanel}, and works something like this:
24
25\begin{enumerate}
26 \item{If the window has a sizer then it is used to calculate the best size.}
27 \item{Otherwise if the window has layout constraints then that is used to calculate the best size.}
28 \item{Otherwise if the window has children then the best size is set to be large enough to show all the children.}
29 \item{Otherwise if there are no children then the window's min size will be used for the best size.}
30 \item{Otherwise if there is no min size set, then the current size is used for the best size.}
31\end{enumerate}
32
33{\bf MinSize}: The min size of a widget is a size that is normally
34explicitly set by the programmer either with the \texttt{SetMinSize()}
35method or the \texttt{SetSizeHints()} method. Most controls will also
36set the min size to the size given in the control's constructor if a
37non-default value is passed. Top-level windows such as
38\helpref{wxFrame}{wxframe} will not allow the user to resize the frame
39below the min size.
40
41{\bf Size}: The size of a widget can be explicitly set or fetched with
42the \texttt{SetSize()} or \texttt{GetSize()} methods. This size value
43is the size that the widget is currently using on screen and is the
44way to change the size of something that is not being managed by a
45sizer.
46
47{\bf ClientSize}: The client size represents the widget's area inside
48of any borders belonging to the widget and is the area that can be
49drawn upon in a \texttt{EVT\_PAINT} event. If a widget doesn't have a
50border then its client size is the same as its size.
51
52{\bf InitialSize}: The initial size of a widget is the size given to
53the constructor of the widget, if any. As mentioned above most
54controls will also set this size value as the control's min size. If
55the size passed to the constructor is the default
56\texttt{wxDefaultSize}, or if the size is not fully specified (such as
57\texttt{wxSize(150,-1)}) then most controls will fill in the missing
58size components using the best size and will set the initial size of
59the control to the resulting size.
60
61{\bf GetEffectiveMinSize()}: (formerly \texttt{GetBestFittingSize}) A
62blending of the widget's min size and best size, giving precedence to
63the min size. For example, if a widget's min size is set to (150, -1)
64and the best size is (80, 22) then the best fitting size is (150,
6522). If the min size is (50, 20) then the best fitting size is (50,
6620). This method is what is called by the sizers when determining what
67the requirements of each item in the sizer is, and is used for
68calculating the overall minimum needs of the sizer.
69
70{\bf SetInitialSize(size)}: (formerly \texttt{SetBestFittingSize})
71This is a little different than the typical size setters. Rather than
72just setting an "initial size" attribute it actually sets the minsize
73to the value passed in, blends that value with the best size, and then
74sets the size of the widget to be the result. So you can consider this
75method to be a "Smart SetSize". This method is what is called by the
76constructor of most controls to set the minsize and initial size of
77the control.
78
79{\bf window.Fit()}: The \texttt{Fit()} method sets the size of a
80window to fit around its children. If it has no children then nothing
81is done, if it does have children then the size of the window is set
82to the window's best size.
83
84{\bf sizer.Fit(window)}: This sets the size of the window to be large
85enough to accommodate the minimum size needed by the sizer, (along with
86a few other constraints...) If the sizer is the one that is assigned
87to the window then this should be equivalent to \texttt{window.Fit()}.
88
89{\bf sizer.Layout()}: Recalculates the minimum space needed by each
90item in the sizer, and then lays out the items within the space
91currently allotted to the sizer.
92
93{\bf window.Layout()}: If the window has a sizer then it sets the
94space given to the sizer to the current size of the window, which
95results in a call to \texttt{sizer.Layout()}. If the window has layout
96constraints instead of a sizer then the constraints algorithm is
97run. The \texttt{Layout()} method is what is called by the default
98\texttt{EVT\_SIZE} handler for container windows.
99
100
101
102