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