1 #ifndef DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
2 #define DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
32 * @brief A type that represents a layout length.
34 * Currently, this implies pixels, but could be extended to handle device dependent sizes, etc.
41 * @brief default constructor, initialises to 0
51 * @param value the value to initialise with
53 LayoutLength( int value )
59 * @brief constructor from float
61 * @param value the value to initialise with
63 LayoutLength( float value )
71 * @param layoutLength the value to initialise with
73 LayoutLength( const LayoutLength& layoutLength )
74 : mValue( layoutLength.mValue )
79 * @brief assignment operator
81 * @param rhs LayoutLength to assign
82 * @return reference to itself
84 LayoutLength& operator=( const LayoutLength& rhs )
94 * @brief assignment operator from int
96 * @param value the value to assign
97 * @return reference to itself
99 LayoutLength& operator=( int value )
106 * @brief assignment operator from float
108 * @param value the value to assign
109 * @return reference to itself
111 LayoutLength& operator=( float value )
118 * @brief plus equals operator
120 * @param rhs to add to this
121 * @return reference to itself
123 LayoutLength& operator+=( LayoutLength rhs )
125 mValue += rhs.mValue;
130 * @brief minus equals operator
132 * @param rhs to subtract from this
133 * @return reference to itself
135 LayoutLength& operator-=( LayoutLength rhs )
137 mValue -= rhs.mValue;
142 * @brief return value as decimal value (full raw value)
144 * @return the LayoutLength as full decimal value
146 float AsDecimal() const
152 * @brief return value as rounded integer value (whole number)
154 * @return the LayoutLength rounded to next integer value
156 float AsInteger() const
158 return round( mValue );
162 * @brief return value as truncated integral value (whole number)
164 * @return the LayoutLength rounded to next integral value
166 float AsTruncated() const
168 return trunc( mValue );
178 * @brief equal to operator
180 * @param lhs value to compare
181 * @param rhs value to compare against
182 * @note Using value instead of reference to allow conversions from int and float
183 * @return true if identical, false otherwise
185 inline bool operator==( LayoutLength lhs, LayoutLength rhs )
187 return lhs.AsDecimal() == rhs.AsDecimal();
191 * @brief not equal to operator
193 * @param lhs value to compare
194 * @param rhs value to compare against
195 * @note Using value instead of reference to allow conversions from int and float
196 * @return true if value is not identical, false otherwise
198 inline bool operator!=( LayoutLength lhs, LayoutLength rhs )
200 return !operator==( lhs, rhs );
204 * @brief less than operator
206 * @param lhs value to compare
207 * @param rhs value to compare against
208 * @note Using value instead of reference to allow conversions from int and float
209 * @return true if lhs value is less, false otherwise
211 inline bool operator<( LayoutLength lhs, LayoutLength rhs )
213 return lhs.AsDecimal() < rhs.AsDecimal();
217 * @brief greater than operator
219 * @param lhs value to compare
220 * @param rhs value to compare against
221 * @note Using value instead of reference to allow conversions from int and float
222 * @return true if lhs value is greater, false otherwise
224 inline bool operator>( LayoutLength lhs, LayoutLength rhs )
230 * @brief less than or equal to operator
232 * @param lhs value to compare
233 * @param rhs value to compare against
234 * @note Using value instead of reference to allow conversions from int and float
235 * @return true if lhs value is less than or equal to, false otherwise
237 inline bool operator<=( LayoutLength lhs, LayoutLength rhs )
243 * @brief greater than or equal to operator
245 * @param lhs value to compare
246 * @param rhs value to compare against
247 * @note Using value instead of reference to allow conversions from int and float
248 * @return true if lhs value is greater than or equal to, false otherwise
250 inline bool operator>=( LayoutLength lhs, LayoutLength rhs )
256 * @brief add two LayoutLengths
258 * @param lhs The LayoutLength to add
259 * @param rhs The LayoutLength to add
260 * @note Using value instead of reference to allow conversions from int and float
261 * @return the resulting LayoutLength
263 inline LayoutLength operator+( LayoutLength lhs, LayoutLength rhs )
265 return lhs.AsDecimal() + rhs.AsDecimal();
269 * @brief subtract two LayoutLengths
271 * @param lhs The LayoutLength to subtract from
272 * @param rhs The LayoutLength to subtract
273 * @note Using value instead of reference to allow conversions from int and float
274 * @return the resulting LayoutLength
276 inline LayoutLength operator-( LayoutLength lhs, LayoutLength rhs )
278 return lhs.AsDecimal() - rhs.AsDecimal();
282 * @brief multiply two LayoutLengths
284 * @param lhs The LayoutLength to multiply
285 * @param rhs The LayoutLength to multiply
286 * @note Using value instead of reference to allow conversions from int and float
287 * @return the resulting LayoutLength
289 inline LayoutLength operator*( LayoutLength lhs, LayoutLength rhs )
291 return lhs.AsDecimal() * rhs.AsDecimal();
295 * @brief divide LayoutLength by a LayoutLength
297 * @param lhs The LayoutLength to divide
298 * @param rhs The LayoutLength to divide by
299 * @note Using value instead of reference to allow conversions from int and float
300 * @return the resulting value as float
302 inline LayoutLength operator/( LayoutLength lhs, LayoutLength rhs )
304 return lhs.AsDecimal() / rhs.AsDecimal();
308 * @brief Prints a LayoutLength
310 * @param[in] o The output stream operator
311 * @param[in] layoutLength the layout length to print
312 * @return The output stream operator
314 inline std::ostream& operator<<( std::ostream& o, const LayoutLength& layoutLength )
316 return o << layoutLength.AsDecimal();
319 } // namespace Toolkit
323 #endif //DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H