]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/src/layout/SizeModel.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / layout / SizeModel.js
CommitLineData
6527f429
DM
1/**\r
2 * This class describes a size determination strategy or algorithm used by the layout\r
3 * system. There are special instances of this class stored as static properties to\r
4 * avoid needless object instantiation. These instances should be treated as readonly.\r
5 * \r
6 * * `calculated`\r
7 * * `configured`\r
8 * * `constrainedMax`\r
9 * * `constrainedMin`\r
10 * * `natural`\r
11 * * `shrinkWrap`\r
12 * * `calculatedFromConfigured`\r
13 * * `calculatedFromNatural`\r
14 * * `calculatedFromShrinkWrap`\r
15 *\r
16 * Using one of these instances is simply:\r
17 *\r
18 * var calculated = Ext.layout.SizeModel.calculated;\r
19 *\r
20 * @private\r
21 */\r
22Ext.define('Ext.layout.SizeModel', {\r
23 constructor: function (config) {\r
24 var me = this,\r
25 SizeModel = me.self,\r
26 sizeModelsArray = SizeModel.sizeModelsArray,\r
27 name;\r
28\r
29 Ext.apply(me, config);\r
30\r
31 me[name = me.name] = true; // set the one special flag that matches our name\r
32\r
33 me.fixed = !(me.auto = me.natural || me.shrinkWrap);\r
34\r
35 /**\r
36 * @property {Number} ordinal\r
37 * The 0-based ordinal for this `SizeModel` instance.\r
38 * @readonly\r
39 */\r
40 sizeModelsArray[me.ordinal = sizeModelsArray.length] =\r
41 SizeModel[name] =\r
42 SizeModel.sizeModels[name] = me;\r
43 },\r
44\r
45 statics: {\r
46 /**\r
47 * An array of all SizeModel instances.\r
48 * @private\r
49 */\r
50 sizeModelsArray: [],\r
51\r
52 /**\r
53 * An object containing all SizeModel instances keyed by `name`.\r
54 * @private\r
55 */\r
56 sizeModels: {}\r
57 },\r
58\r
59 /**\r
60 * @property {String} name\r
61 * The name of this size model (e.g., "calculated").\r
62 * @readonly\r
63 */\r
64\r
65 /**\r
66 * @property {Boolean} auto\r
67 * True if the size is either `natural` or `shrinkWrap`, otherwise false.\r
68 * @readonly\r
69 */\r
70\r
71 /**\r
72 * @property {Boolean} calculated\r
73 * True if the size is calculated by the `ownerLayout`.\r
74 * @readonly\r
75 */\r
76 calculated: false,\r
77\r
78 /**\r
79 * @property {Boolean} configured\r
80 * True if the size is configured (e.g., by a `width` or `minWidth`). The names of\r
81 * configuration properties can be found in the {@link #names} property.\r
82 * @readonly\r
83 */\r
84 configured: false,\r
85\r
86 /**\r
87 * @property {Boolean} constrainedMax\r
88 * True if the size is constrained by a `maxWidth` or `maxHeight` configuration. This\r
89 * is a flavor of `configured` (since `maxWidth` and `maxHeight` are config options).\r
90 * If true, the {@link #names} property will be defined as well.\r
91 * @readonly\r
92 */\r
93 constrainedMax: false,\r
94\r
95 /**\r
96 * @property {Boolean} constrainedMin\r
97 * True if the size is constrained by a `minWidth` or `minHeight` configuration. This\r
98 * is a flavor of `configured` (since `minWidth` and `minHeight` are config options).\r
99 * If true, the {@link #names} property will be defined as well.\r
100 * @readonly\r
101 */\r
102 constrainedMin: false,\r
103\r
104 /**\r
105 * @property {Boolean} fixed\r
106 * True if the size is either `calculated` or `configured`, otherwise false.\r
107 * @readonly\r
108 */\r
109\r
110 /**\r
111 * @property {Boolean} natural\r
112 * True if the size is determined by CSS and not by content. Such sizes are assumed to\r
113 * be dependent on the container box and measurement occurs on the outer-most element.\r
114 * @readonly\r
115 */\r
116 natural: false,\r
117\r
118 /**\r
119 * @property {Boolean} shrinkWrap\r
120 * True if the size is determined by content irrespective of the container box.\r
121 * @readonly\r
122 */\r
123 shrinkWrap: false,\r
124\r
125 /**\r
126 * @property {Boolean} calculatedFromConfigured\r
127 * True if the size is calculated by the `ownerLayout` based on a configured size.\r
128 * @readonly\r
129 */\r
130 calculatedFromConfigured: false,\r
131\r
132 /**\r
133 * @property {Boolean} calculatedFromNatural\r
134 * True if the size is calculated by the `ownerLayout` based on `natural` size model\r
135 * results.\r
136 * @readonly\r
137 */\r
138 calculatedFromNatural: false,\r
139\r
140 /**\r
141 * @property {Boolean} calculatedFromShrinkWrap\r
142 * True if the size is calculated by the `ownerLayout` based on `shrinkWrap` size model\r
143 * results.\r
144 * @readonly\r
145 */\r
146 calculatedFromShrinkWrap: false,\r
147\r
148 /**\r
149 * @property {Object} names An object with the config property names that determine the\r
150 * size.\r
151 * @property {String} names.width The width property name (e.g., 'width').\r
152 * @property {String} names.height The height property name (e.g., 'minHeight').\r
153 * @readonly\r
154 */\r
155 names: null\r
156},\r
157function () {\r
158 var SizeModel = this,\r
159 sizeModelsArray = SizeModel.sizeModelsArray,\r
160 i, j, n, pairs, sizeModel;\r
161\r
162 //-------------------------------------------------------------------------------\r
163 // These are the 4 fundamental size models.\r
164\r
165 new SizeModel({ // jshint ignore:line\r
166 name: 'calculated'\r
167 });\r
168\r
169 new SizeModel({ // jshint ignore:line\r
170 name: 'configured',\r
171 names: { width: 'width', height: 'height' }\r
172 });\r
173\r
174 new SizeModel({ // jshint ignore:line\r
175 name: 'natural'\r
176 });\r
177\r
178 new SizeModel({ // jshint ignore:line\r
179 name: 'shrinkWrap'\r
180 });\r
181\r
182 //-------------------------------------------------------------------------------\r
183 // These are the size models are flavors of the above but with some extra detail\r
184 // about their dynamic use.\r
185\r
186 new SizeModel({ // jshint ignore:line\r
187 name: 'calculatedFromConfigured',\r
188 configured: true,\r
189 calculatedFrom: true,\r
190 names: { width: 'width', height: 'height' }\r
191 });\r
192\r
193 new SizeModel({ // jshint ignore:line\r
194 name: 'calculatedFromNatural',\r
195 natural: true,\r
196 calculatedFrom: true\r
197 });\r
198\r
199 new SizeModel({ // jshint ignore:line\r
200 name: 'calculatedFromShrinkWrap',\r
201 shrinkWrap: true,\r
202 calculatedFrom: true\r
203 });\r
204\r
205 new SizeModel({ // jshint ignore:line\r
206 name: 'constrainedMax',\r
207 configured: true,\r
208 constrained: true,\r
209 names: { width: 'maxWidth', height: 'maxHeight' }\r
210 });\r
211\r
212 new SizeModel({ // jshint ignore:line\r
213 name: 'constrainedMin',\r
214 configured: true,\r
215 constrained: true,\r
216 names: { width: 'minWidth', height: 'minHeight' }\r
217 });\r
218\r
219 new SizeModel({ // jshint ignore:line\r
220 name: 'constrainedDock',\r
221 configured: true,\r
222 constrained: true,\r
223 constrainedByMin: true,\r
224 names: { width: 'dockConstrainedWidth', height: 'dockConstrainedHeight' }\r
225 });\r
226\r
227 for (i = 0, n = sizeModelsArray.length; i < n; ++i) {\r
228 sizeModel = sizeModelsArray[i];\r
229\r
230 /**\r
231 * An array of objects indexed by the {@link #ordinal} of a height `SizeModel` on\r
232 * a width `SizeModel` to yield an object describing both height and width size\r
233 * models.\r
234 * \r
235 * Used like this:\r
236 *\r
237 * widthModel.pairsByHeightOrdinal[heightModel.ordinal]\r
238 *\r
239 * This provides a reusable object equivalent to the following:\r
240 * \r
241 * {\r
242 * width: widthModel,\r
243 * height: heightModel\r
244 * }\r
245 *\r
246 * @property {Object[]} pairsByHeightOrdinal\r
247 * @property {Ext.layout.SizeModel} pairsByHeightOrdinal.width The `SizeModel` for\r
248 * the width.\r
249 * @property {Ext.layout.SizeModel} pairsByHeightOrdinal.height The `SizeModel` for\r
250 * the height.\r
251 */\r
252 sizeModel.pairsByHeightOrdinal = pairs = [];\r
253\r
254 for (j = 0; j < n; ++j) {\r
255 pairs.push({\r
256 width: sizeModel,\r
257 height: sizeModelsArray[j]\r
258 });\r
259 }\r
260 }\r
261});\r