|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definition of THuiMetric, which is used to achieve |
|
15 * text size dependent layouts, normalized child coordinate system and |
|
16 * unified metrics system for all layout calculations. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __HUIMETRIC_H__ |
|
23 #define __HUIMETRIC_H__ |
|
24 |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <e32std.h> |
|
28 |
|
29 #include <uiacceltk/huitextstylemanager.h> |
|
30 #include <uiacceltk/HuiRealPoint.h> |
|
31 |
|
32 /** |
|
33 * Metric units. The unit defines how the @c iMagnitude member of the THuiMetric |
|
34 * struct is interpreted in practice. The interpretation may be dependent on |
|
35 * the size of the layout where it is being used, the size of a font, or |
|
36 * for example a globally defined constant. |
|
37 */ |
|
38 enum THuiUnit |
|
39 { |
|
40 /** Real pixel that corresponds the pixels on the physical device screen. */ |
|
41 EHuiUnitPixel, |
|
42 |
|
43 /** Normalized to parent layout size (0.0 -- 1.0). */ |
|
44 EHuiUnitNormalized, |
|
45 EHuiUnitParentSize = EHuiUnitNormalized, |
|
46 |
|
47 /** Relative to the display where the metric is being used (0.0 -- 1.0). */ |
|
48 EHuiUnitRelativeToDisplay, |
|
49 EHuiUnitDisplaySize = EHuiUnitRelativeToDisplay, |
|
50 |
|
51 /** |
|
52 * Layout unit defined by S60 for a particular display device. |
|
53 * @see CHuiDisplay::UnitValue |
|
54 */ |
|
55 EHuiUnitS60, |
|
56 |
|
57 /** |
|
58 * Relative to the size of the visual where the metric is being used (0.0 -- 1.0). |
|
59 * This is particularly useful for anchor layout offsets, and for paddings. |
|
60 */ |
|
61 EHuiUnitRelativeToMySize, |
|
62 EHuiUnitMySize = EHuiUnitRelativeToMySize, |
|
63 |
|
64 /** relative weight; interpretation depends on sibling elements |
|
65 * (for example, cells in a grid) |
|
66 */ |
|
67 EHuiUnitWeight, |
|
68 |
|
69 /** |
|
70 * Not supported at the moment. |
|
71 * Line height of the font of the reference text style (the "em width") |
|
72 */ |
|
73 EHuiUnitLine, |
|
74 |
|
75 /** |
|
76 * Not Supported at the moment. |
|
77 * Physical millimeters on the screen (for instance for icons). |
|
78 */ |
|
79 EHuiUnitMillimeter, |
|
80 |
|
81 /** |
|
82 * Similar to EHuiUnitMysize. Can be used for example to constrain the aspect ratio of a visual, |
|
83 * by constraining one axis to be defined in relation to its orthogonal axis. |
|
84 */ |
|
85 EHuiUnitMyWidth, |
|
86 EHuiUnitMyHeight, |
|
87 |
|
88 /** |
|
89 * Similar to EHuiUnitNormalized. Can be used for example to constrain the aspect ratio of a visual |
|
90 * by constraining one axis to be defined in relation to its parent's orthogonal axis. |
|
91 */ |
|
92 EHuiUnitParentWidth, |
|
93 EHuiUnitParentHeight, |
|
94 |
|
95 /** |
|
96 * Not Supported at the moment. |
|
97 * Similar to EHuiUnitMysize. The minimum of a visual's dimensions. |
|
98 */ |
|
99 EHuiUnitMyDimensionMinimum, |
|
100 |
|
101 /** |
|
102 * Similar to EHuiUnitMysize. The Average of a visual's dimensions. |
|
103 */ |
|
104 EHuiUnitMyDimensionAverage, |
|
105 }; |
|
106 |
|
107 |
|
108 /** |
|
109 * A Metric is used to represent a value in a specified unit type. This is |
|
110 * to support the definition of Layouts using screen-size independent as well |
|
111 * as screen-size dependent measurements. |
|
112 * |
|
113 * The metrics are used for different things in different contexts: |
|
114 * coordinate base units, anchor offsets, grid column/row weights, paddings, etc. |
|
115 * The interpretation of the units used in the metric depends on the context, |
|
116 * the type of Layout in which they are used, etc. |
|
117 * |
|
118 */ |
|
119 struct THuiMetric |
|
120 { |
|
121 public: |
|
122 /** |
|
123 * Constructor. The constructor defaults to using [1px] units. |
|
124 * |
|
125 * @param aMagnitude the size of the metric value, for example it may represent a length or a scale factor |
|
126 * @param aUnit the unit type in which the metric value is represented |
|
127 * @param aReferenceTextStyleID can be used to specify a text style in the case of EHuiUnitLine. |
|
128 */ |
|
129 IMPORT_C THuiMetric(TReal32 aMagnitude = 1.f, TInt aUnit = EHuiUnitPixel, TInt aReferenceTextStyleId = EHuiTextStyleNormal) __SOFTFP; |
|
130 |
|
131 /** |
|
132 * Constructor. Allows the compiler to pass integers instead of THuiMetric |
|
133 * in parameters, in place of pixel metrics. |
|
134 * |
|
135 * @param aPixels Number of pixels for the metric. |
|
136 */ |
|
137 IMPORT_C THuiMetric(TInt aPixels); |
|
138 |
|
139 /** |
|
140 * Returns a copy of the metric with the absolute value of the magnitude component. |
|
141 */ |
|
142 inline THuiMetric Abs() const |
|
143 { |
|
144 return THuiMetric(::Abs(iMagnitude), iUnit, iReferenceTextStyleId); |
|
145 } |
|
146 |
|
147 inline THuiMetric operator * (TReal32 aValue) const |
|
148 { |
|
149 THuiMetric result = *this; |
|
150 result.iMagnitude *= aValue; |
|
151 return result; |
|
152 } |
|
153 |
|
154 public: |
|
155 TReal32 iMagnitude; |
|
156 |
|
157 /** |
|
158 * @see THuiUnit |
|
159 */ |
|
160 TInt iUnit; |
|
161 |
|
162 /** |
|
163 * @see CHuiTextStyleManager::TextStyle |
|
164 */ |
|
165 TInt iReferenceTextStyleId; |
|
166 |
|
167 private: |
|
168 TInt iSpare1; |
|
169 TInt iSpare2; |
|
170 }; |
|
171 |
|
172 |
|
173 /** |
|
174 * A pair of metrics used to represent a value in both X and Y directions, similar to a THuiRealPoint. |
|
175 */ |
|
176 struct THuiXYMetric |
|
177 { |
|
178 public: |
|
179 /** |
|
180 * Constructor. |
|
181 */ |
|
182 IMPORT_C THuiXYMetric(); |
|
183 |
|
184 /** |
|
185 * Constructor. Uses the same metric for both axes. |
|
186 * |
|
187 * @param aMetric Metric for the X and Y axes. |
|
188 */ |
|
189 IMPORT_C THuiXYMetric(const THuiMetric& aMetric); |
|
190 |
|
191 /** |
|
192 * Constructor. |
|
193 * |
|
194 * @param aX metric for the X axis |
|
195 * @param aY metric for the Y axis |
|
196 */ |
|
197 IMPORT_C THuiXYMetric(const THuiMetric& aX, const THuiMetric& aY); |
|
198 |
|
199 inline THuiXYMetric operator * (const THuiRealPoint& aPoint) const |
|
200 { |
|
201 THuiXYMetric result = *this; |
|
202 result.iX.iMagnitude *= aPoint.iX; |
|
203 result.iY.iMagnitude *= aPoint.iY; |
|
204 return result; |
|
205 } |
|
206 |
|
207 inline THuiXYMetric Abs() const |
|
208 { |
|
209 return THuiXYMetric(iX.Abs(), iY.Abs()); |
|
210 } |
|
211 |
|
212 |
|
213 public: |
|
214 THuiMetric iX; |
|
215 THuiMetric iY; |
|
216 |
|
217 private: |
|
218 TInt iSpare1; |
|
219 TInt iSpare2; |
|
220 }; |
|
221 |
|
222 |
|
223 /** |
|
224 * Four metrics used to indicate space around the four edges of a rectangle. |
|
225 * Not called a rectangle because those are typically made up of two XY points, |
|
226 * while this contains just four edge metrics (named top, bottom, left, and right). |
|
227 */ |
|
228 struct THuiBoxMetric |
|
229 { |
|
230 public: |
|
231 /** |
|
232 * Constructor. |
|
233 */ |
|
234 IMPORT_C THuiBoxMetric(); |
|
235 |
|
236 /** |
|
237 * Constructor. Uses the same metric on all sides of the box. |
|
238 * |
|
239 * @param aMetric Metric for all sides of the box. |
|
240 */ |
|
241 IMPORT_C THuiBoxMetric(const THuiMetric& aMetric); |
|
242 |
|
243 /** |
|
244 * Constructor. The X metric is used for the left and right sides, and the |
|
245 * Y metric is used for the top and bottom sides. |
|
246 * |
|
247 * @param aMetric Metric for all sides of the box. |
|
248 */ |
|
249 IMPORT_C THuiBoxMetric(const THuiXYMetric& aMetric); |
|
250 |
|
251 /** |
|
252 * Constructor. The top and left edges are specified in a single parameter, |
|
253 * and the bottom and right edges are also specified in a single parameter. |
|
254 * |
|
255 * @param aTopLeft Metrics for the left and top sides. |
|
256 * @param aBottomRight Metrics for the right and bottom sides. |
|
257 */ |
|
258 IMPORT_C THuiBoxMetric(const THuiXYMetric& aTopLeft, |
|
259 const THuiXYMetric& aBottomRight); |
|
260 |
|
261 /** |
|
262 * Constructor. |
|
263 * |
|
264 * @param aLeft Metric for the left edge of the box. |
|
265 * @param aRight Metric for the right edge of the box. |
|
266 * @param aTop Metric for the top edge of the box. |
|
267 * @param aBottom Metric for the bottom edge of the box. |
|
268 */ |
|
269 IMPORT_C THuiBoxMetric(const THuiMetric& aLeft, const THuiMetric& aRight, |
|
270 const THuiMetric& aTop, const THuiMetric& aBottom); |
|
271 |
|
272 public: |
|
273 THuiMetric iLeft; |
|
274 THuiMetric iRight; |
|
275 THuiMetric iTop; |
|
276 THuiMetric iBottom; |
|
277 |
|
278 private: |
|
279 TInt iSpare1; |
|
280 TInt iSpare2; |
|
281 }; |
|
282 |
|
283 |
|
284 #endif // __HUIMETRIC_H__ |