9953ed8534311ae567394cad6560726d2836702b
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-length.h
1 #ifndef DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
2 #define DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19 #include <cstdint>
20 #include <iostream>
21
22 namespace Dali
23 {
24 namespace Toolkit
25 {
26
27 /**
28  * @brief A type that represents a layout length.
29  *
30  * Currently, this implies pixels, but could be extended to handle device dependant sizes, etc.
31  */
32 class LayoutLength
33 {
34 public:
35   using IntType = int;
36
37   LayoutLength( IntType value )
38   : mValue( value )
39   {
40   }
41
42   LayoutLength( const LayoutLength& layoutLength )
43   : mValue( layoutLength.mValue )
44   {
45   }
46
47   LayoutLength& operator=(const LayoutLength& rhs)
48   {
49     if( this != &rhs )
50     {
51       mValue = rhs.mValue;
52     }
53     return *this;
54   }
55
56   bool operator==( const LayoutLength& rhs )
57   {
58     return mValue == rhs.mValue;
59   }
60
61   bool operator==( LayoutLength::IntType rhs )
62   {
63     return mValue == rhs;
64   }
65
66   bool operator!=( const LayoutLength& rhs )
67   {
68     return !operator==(rhs);
69   }
70
71   bool operator<( const LayoutLength& rhs )
72   {
73     return mValue < rhs.mValue;
74   }
75
76   bool operator<( const LayoutLength rhs ) const
77   {
78     return mValue < rhs.mValue;
79   }
80
81   bool operator<=( const LayoutLength& rhs )
82   {
83     return mValue <= rhs.mValue;
84   }
85   bool operator<=( LayoutLength rhs )
86   {
87     return mValue <= rhs.mValue;
88   }
89   bool operator>( const LayoutLength& rhs )
90   {
91     return mValue > rhs.mValue;
92   }
93   bool operator>( LayoutLength rhs )
94   {
95     return mValue > rhs.mValue;
96   }
97   bool operator>=( const LayoutLength& rhs )
98   {
99     return mValue >= rhs.mValue;
100   }
101   bool operator>=( LayoutLength rhs )
102   {
103     return mValue >= rhs.mValue;
104   }
105
106   LayoutLength operator+( const LayoutLength& rhs )
107   {
108     return mValue + rhs.mValue;
109   }
110
111   LayoutLength operator+( LayoutLength::IntType rhs )
112   {
113     return mValue + rhs;
114   }
115
116   LayoutLength operator-( const LayoutLength& rhs )
117   {
118     return mValue - rhs.mValue;
119   }
120   LayoutLength operator-( LayoutLength::IntType rhs )
121   {
122     return mValue - rhs;
123   }
124
125   LayoutLength& operator+=( const LayoutLength& rhs )
126   {
127     mValue += rhs.mValue;
128     return *this;
129   }
130   LayoutLength& operator+=( LayoutLength::IntType rhs )
131   {
132     mValue += rhs;
133     return *this;
134   }
135
136   LayoutLength& operator-=( const LayoutLength& rhs )
137   {
138     mValue -= rhs.mValue;
139     return *this;
140   }
141
142   LayoutLength& operator-=( LayoutLength::IntType rhs )
143   {
144     mValue -= rhs;
145     return *this;
146   }
147
148   LayoutLength operator/( const LayoutLength& rhs )
149   {
150     return mValue / rhs.mValue;
151   }
152   LayoutLength operator/(  LayoutLength::IntType rhs )
153   {
154     return mValue / rhs;
155   }
156
157   LayoutLength operator*( const LayoutLength& rhs )
158   {
159     return mValue * rhs.mValue;
160   }
161   LayoutLength operator*( LayoutLength::IntType rhs )
162   {
163     return mValue * rhs;
164   }
165   LayoutLength operator*( float rhs )
166   {
167     return LayoutLength(LayoutLength::IntType(float(mValue) * rhs));
168   }
169
170   operator float()
171   {
172     return float( mValue );
173   }
174
175   IntType mValue;
176 };
177
178 /**
179  * @brief Prints a LayoutLength
180  *
181  * @param[in] o The output stream operator
182  * @param[in] layoutLength the layout length to print
183  * @return The output stream operator
184  */
185 inline std::ostream& operator<<( std::ostream& o, const LayoutLength& layoutLength )
186 {
187   return o<<layoutLength.mValue;
188 }
189
190 } // namespace Toolkit
191
192 } // namespace Dali
193
194 #endif //DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H