b1ebcd3508e80697215521319b34fecb4d0cf1d5
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / alignment / alignment.h
1 #ifndef __DALI_ALIGNMENT_H__
2 #define __DALI_ALIGNMENT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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
20 /**
21  * @addtogroup CAPI_DALI_TOOLKIT_ALIGNMENT_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class Alignment;
37 }
38
39 /**
40  * @brief Alignment is a container which provides an easy way to align other actors inside its boundary.
41  *
42  * Additionaly it provides a scaling property to resize the contained actors @see Scaling.
43  * @note The use of scaling property will override all constraints applied to actors.
44  *
45  * All actors added to an alignment are going to be set with the same anchor point and parent origin. And, if the scaling property is set to a value
46  * different than ScaleNone, constraints as well.
47  */
48 class Alignment : public Control
49 {
50 public:
51   /**
52    * @brief Different types of alignment.
53    */
54   enum Type
55   {
56     HorizontalLeft   = 1,
57     HorizontalCenter = 2,
58     HorizontalRight  = 4,
59     VerticalTop      = 8,
60     VerticalCenter   = 16,
61     VerticalBottom   = 32
62   };
63
64   /**
65    * @brief Scaling determines how actors are scaled, to match the alignment's boundary.
66    */
67   enum Scaling
68   {
69     ScaleNone,             ///< The original size is kept.
70     ScaleToFill,           ///< Scale added actors to fill alignment's boundary. Aspect ratio is not maintained.
71     ScaleToFitKeepAspect,  ///< Scale added actors to fit within the alignment's boundary. Aspect ratio is maintained.
72     ScaleToFillKeepAspect, ///< Scale added actors to fill the alignment's boundary. Aspect ratio is maintained, and the actor may exceed the alignment's boundary.
73     ShrinkToFit,           ///< If added actors are larger than the alignment's boundary it will be shrunk down to fit. Aspect ratio is not maintained
74     ShrinkToFitKeepAspect, ///< If added actors are larger than the alignment's boundary it will be shrunk down to fit. Aspect ratio is maintained
75   };
76
77   /**
78    * @brief Structure describing the padding values.
79    */
80   struct Padding
81   {
82     /**
83      * @brief Constructor
84      */
85     Padding()
86     : left( 0.f ),
87       right( 0.f ),
88       top( 0.f ),
89       bottom( 0.f )
90     {
91     }
92
93     /**
94      * @brief Constructor
95      *
96      * @param[in] l Left padding
97      * @param[in] r Right padding
98      * @param[in] t Top padding
99      * @param[in] b Bottom padding
100      */
101     Padding( float l, float r, float t, float b )
102     : left( l ),
103       right( r ),
104       top( t ),
105       bottom( b )
106     {
107     }
108
109     float left;  ///< The left padding
110     float right; ///< The right padding
111     float top;   ///< The top padding
112     float bottom; ///< The bottom padding
113   };
114
115   /**
116    * @brief Create an Alignment handle; this can be initialised with Alignment::New().
117    *
118    * Calling member functions with an uninitialised handle is not allowed.
119    */
120   Alignment();
121
122   /**
123    * @brief Creates an alignment control.
124    *
125    * @param [in] horizontal Specifies how to align actors horizontally. Could be HorizontalLeft, HorizontalCenter or HorizontalRight. By default HorizontalCenter.
126    * @param [in] vertical Specifies how to align actors vertically. Could be VerticalTop, VerticalCenter or VerticalBottom. By default VerticalCenter.
127    * @return A handle to the Alignment control.
128    */
129   static Alignment New( Type horizontal = HorizontalCenter, Type vertical = VerticalCenter );
130
131   /**
132    * @brief Copy constructor. Creates another handle that points to the same real object.
133    *
134    * @param[in] alignment Object to copy.
135    */
136   Alignment(const Alignment& alignment);
137
138   /**
139    * @brief Virtual destructor.
140    *
141    * Dali::Object derived classes typically do not contain member data.
142    */
143   virtual ~Alignment();
144
145   /**
146    * @brief Downcast an Object handle to Alignment.
147    *
148    * If handle points to a Alignment the downcast produces valid
149    * handle. If not the returned handle is left uninitialized.
150    *
151    * @param[in] handle Handle to an object
152    * @return handle to a Alignment or an uninitialized handle
153    */
154   static Alignment DownCast( BaseHandle handle );
155
156   /**
157    * @brief Sets the new alignment. By default ( HorizontalCenter | VerticalCenter ).
158    * @param [in] type The new alignment option.
159    */
160   void SetAlignmentType( Type type );
161
162   /**
163    * @brief Get the current alignment combined into a single value.
164    *
165    * The values can be tested by using the & operator and the desired
166    * flag. e.g.
167    * @code
168    *   if (GetAlignmentType() & HorizontalCentre)
169    *   {
170    *     ...
171    *   }
172    * @endcode
173    *
174    * @return the alignment value.
175    */
176   Type GetAlignmentType() const;
177
178   /**
179    * @brief Sets how added actors scale to fit the alignment's boundary.
180    *
181    * @see Scaling.
182    * @param[in] scaling The scaling property.
183    */
184   void SetScaling( Scaling scaling );
185
186   /**
187    * @brief Retrieves the scaling property.
188    *
189    * @see Scaling.
190    * @return The scaling.
191    */
192   Scaling GetScaling() const;
193
194   /**
195    * @brief Set a padding value.
196    *
197    * @param [in] padding The left, right, top, bottom padding values.
198    */
199   void SetPadding( const Padding& padding );
200
201   /**
202    * @brief Get the padding values.
203    *
204    * @return The left, right, top, bottom padding values.
205    */
206   const Padding& GetPadding() const;
207
208   /**
209    * @brief Assignment operator.
210    *
211    * Changes this handle to point to another real object.
212    * @param[in] alignment Object to copy
213    * @return A reference to this
214    */
215   Alignment& operator=(const Alignment& alignment);
216
217 public: // Not intended for application developers
218
219   /**
220    * @brief Creates a handle using the Toolkit::Internal implementation.
221    *
222    * @param[in]  implementation  The Control implementation.
223    */
224   Alignment( Internal::Alignment& implementation );
225
226   /**
227    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
228    *
229    * @param[in]  internal  A pointer to the internal CustomActor.
230    */
231   Alignment( Dali::Internal::CustomActor* internal );
232 };
233
234 } // namespace Toolkit
235
236 } // namespace Dali
237
238 /**
239  * @}
240  */
241 #endif // __DALI_TOOLKIT_LAYOUT_H__