[SRUK] Initial copy from Tizen 2.2 version
[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_FRAMEWORK
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  * 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    * 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    * 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   struct Padding
78   {
79     Padding()
80     : left( 0.f ),
81       right( 0.f ),
82       top( 0.f ),
83       bottom( 0.f )
84     {
85     }
86
87     Padding( float l, float r, float t, float b )
88     : left( l ),
89       right( r ),
90       top( t ),
91       bottom( b )
92     {
93     }
94
95     float left;
96     float right;
97     float top;
98     float bottom;
99   };
100
101   /**
102    * Create an Alignment handle; this can be initialised with Alignment::New()
103    * Calling member functions with an uninitialised handle is not allowed.
104    */
105   Alignment();
106
107   /**
108    * Creates an alignment control.
109    * @param [in] horizontal Specifies how to align actors horizontally. Could be HorizontalLeft, HorizontalCenter or HorizontalRight. By default HorizontalCenter.
110    * @param [in] vertical Specifies how to align actors vertically. Could be VerticalTop, VerticalCenter or VerticalBottom. By default VerticalCenter.
111    * @return A handle to the Alignment control.
112    */
113   static Alignment New( Type horizontal = HorizontalCenter, Type vertical = VerticalCenter );
114
115   /**
116    * Copy constructor. Creates another handle that points to the same real object.
117    */
118   Alignment(const Alignment& alignment);
119
120   /**
121    * Virtual destructor.
122    * Dali::Object derived classes typically do not contain member data.
123    */
124   virtual ~Alignment();
125
126   /**
127    * Downcast an Object handle to Alignment. If handle points to a Alignment the
128    * downcast produces valid handle. If not the returned handle is left uninitialized.
129    * @param[in] handle Handle to an object
130    * @return handle to a Alignment or an uninitialized handle
131    */
132   static Alignment DownCast( BaseHandle handle );
133
134   /**
135    * Sets the new alignment. By default ( HorizontalCenter | VerticalCenter ).
136    * @param [in] type The new alignment option.
137    */
138   void SetAlignmentType( Type type );
139
140   /**
141    * Get the current alignment combined into a single value.
142    * The values can be tested by using the & operator
143    * and the desired flag. e.g. if (GetAlignmentType() & HorizontalCentre) ...
144    * @return the alignment value.
145    */
146   Type GetAlignmentType() const;
147
148   /**
149    * Sets how added actors scale to fit the alignment's boundary.
150    * @see Scaling.
151    * @param[in] scaling The scaling property.
152    */
153   void SetScaling( Scaling scaling );
154
155   /**
156    * Retrieves the scaling property.
157    * @see Scaling.
158    * @return The scaling.
159    */
160   Scaling GetScaling() const;
161
162   /**
163    * Set a padding value.
164    *
165    * @param [in] padding The left, right, top, bottom padding values.
166    */
167   void SetPadding( const Padding& padding );
168
169   /**
170    * @return The left, right, top, bottom padding values.
171    */
172   const Padding& GetPadding() const;
173
174   /**
175    * Assignment operator. Changes this handle to point to another real object.
176    */
177   Alignment& operator=(const Alignment& alignment);
178
179 public: // Not intended for application developers
180
181   /**
182    * Creates a handle using the Toolkit::Internal implementation.
183    * @param[in]  implementation  The Control implementation.
184    */
185   Alignment( Internal::Alignment& implementation );
186
187   /**
188    * Allows the creation of this Control from an Internal::CustomActor pointer.
189    * @param[in]  internal  A pointer to the internal CustomActor.
190    */
191   Alignment( Dali::Internal::CustomActor* internal );
192 };
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 /**
199  * @}
200  */
201 #endif // __DALI_TOOLKIT_LAYOUT_H__