New layouting classes
[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     mValue = rhs.mValue;
50     return *this;
51   }
52
53   bool operator==( const LayoutLength& rhs )
54   {
55     return mValue == rhs.mValue;
56   }
57
58   bool operator==( LayoutLength::IntType rhs )
59   {
60     return mValue == rhs;
61   }
62
63   bool operator!=( const LayoutLength& rhs )
64   {
65     return !operator==(rhs);
66   }
67
68   bool operator<( const LayoutLength& rhs )
69   {
70     return mValue < rhs.mValue;
71   }
72
73   bool operator<( const LayoutLength rhs ) const
74   {
75     return mValue < rhs.mValue;
76   }
77
78   bool operator<=( const LayoutLength& rhs )
79   {
80     return mValue <= rhs.mValue;
81   }
82   bool operator<=( LayoutLength rhs )
83   {
84     return mValue <= rhs.mValue;
85   }
86   bool operator>( const LayoutLength& rhs )
87   {
88     return mValue > rhs.mValue;
89   }
90   bool operator>( LayoutLength rhs )
91   {
92     return mValue > rhs.mValue;
93   }
94   bool operator>=( const LayoutLength& rhs )
95   {
96     return mValue >= rhs.mValue;
97   }
98   bool operator>=( LayoutLength rhs )
99   {
100     return mValue >= rhs.mValue;
101   }
102
103   LayoutLength operator+( const LayoutLength& rhs )
104   {
105     return mValue + rhs.mValue;
106   }
107
108   LayoutLength operator+( LayoutLength::IntType rhs )
109   {
110     return mValue + rhs;
111   }
112
113   LayoutLength operator-( const LayoutLength& rhs )
114   {
115     return mValue - rhs.mValue;
116   }
117   LayoutLength operator-( LayoutLength::IntType rhs )
118   {
119     return mValue - rhs;
120   }
121
122   LayoutLength& operator+=( const LayoutLength& rhs )
123   {
124     mValue += rhs.mValue;
125     return *this;
126   }
127   LayoutLength& operator+=( LayoutLength::IntType rhs )
128   {
129     mValue += rhs;
130     return *this;
131   }
132
133   LayoutLength& operator-=( const LayoutLength& rhs )
134   {
135     mValue -= rhs.mValue;
136     return *this;
137   }
138
139   LayoutLength& operator-=( LayoutLength::IntType rhs )
140   {
141     mValue -= rhs;
142     return *this;
143   }
144
145   LayoutLength operator/( const LayoutLength& rhs )
146   {
147     return mValue / rhs.mValue;
148   }
149   LayoutLength operator/(  LayoutLength::IntType rhs )
150   {
151     return mValue / rhs;
152   }
153
154   LayoutLength operator*( const LayoutLength& rhs )
155   {
156     return mValue * rhs.mValue;
157   }
158   LayoutLength operator*( LayoutLength::IntType rhs )
159   {
160     return mValue * rhs;
161   }
162   LayoutLength operator*( float rhs )
163   {
164     return LayoutLength(LayoutLength::IntType(float(mValue) * rhs));
165   }
166
167   operator float()
168   {
169     return float( mValue );
170   }
171
172   IntType mValue;
173 };
174
175 /**
176  * @brief Prints a LayoutLength
177  *
178  * @param[in] o The output stream operator
179  * @param[in] layoutLength the layout length to print
180  * @return The output stream operator
181  */
182 inline std::ostream& operator<<( std::ostream& o, const LayoutLength& layoutLength )
183 {
184   return o<<layoutLength.mValue;
185 }
186
187 } // namespace Toolkit
188
189 } // namespace Dali
190
191 #endif //DALI_TOOLKIT_DEVEL_LAYOUT_LENGTH_H