Remove dependency on DLOG.
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / table-view / table-view.h
1 #ifndef __DALI_TOOLKIT_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_TABLE_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 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  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali-toolkit/public-api/controls/control.h>
24
25 namespace Dali DALI_IMPORT_API
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 class TableView;
34 }
35
36 /**
37  * TableView is a layout container for aligning child actors in a grid like layout.
38  * TableView constrains the x and y position and width and height of the child actors.
39  * z position and depth are left intact so that 3D model actors can also be laid out
40  * in a grid without loosing their depth scaling.
41  */
42 class TableView : public Control
43 {
44 public:
45
46   /// @name Properties
47   /** @{ */
48   static const Property::Index PROPERTY_ROWS;                       ///< name "rows",                      type UNSIGNED_INTEGER
49   static const Property::Index PROPERTY_COLUMNS;                    ///< name "columns",                   type UNSIGNED_INTEGER
50   static const Property::Index PROPERTY_CELL_PADDING;               ///< name "cell-padding",              type VECTOR2
51   static const Property::Index PROPERTY_LAYOUT_ANIMATION_DURATION;  ///< name "layout-animation-duration", type FLOAT
52
53   /*
54    * PROPERTY_LAYOUT_ROWS set the height of the rows
55    * It has the format as follows in script:
56    * @code
57    * "layout-rows":
58       {
59         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedHight
60         "2": { "policy": "relative", "value": 0.33 }   //@see SetRelativeHeight
61       }
62    * @endcode
63    */
64   static const Property::Index PROPERTY_LAYOUT_ROWS;                ///< name "layout-rows",               type MAP
65
66   /*
67    * PROPERTY_LAYOUT_COLUMNS set the height of the rows
68    * It has the format as follows in script:
69    * @code
70    * "layout-columns":
71       {
72         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedWidth
73         "2": { "policy": "relative", "value": 0.33 }   //@see SetRelativeWidth
74       }
75    * @endcode
76    */
77   static const Property::Index PROPERTY_LAYOUT_COLUMNS;             ///< name "layout-columns",            type MAP
78   /** @} */
79
80
81   // Custom properties for where to put the actor, these properties should be registered to the child which would be added to the table
82   static const std::string CELL_INDICES_PROPERTY_NAME;           ///< Property, name "cell-indices", type VECTOR2
83   static const std::string ROW_SPAN_PROPERTY_NAME;               ///< Property, name "row-span",     type FLOAT (Currently builder unable to differentiate integer and float from Json string)
84   static const std::string COLUMN_SPAN_PROPERTY_NAME;            ///< Property, name "column-span",  type FLOAT (Currently builder unable to differentiate integer and float from Json string)
85
86
87   /**
88    * @brief Describes how the size of a row / column been set
89    */
90   enum LayoutPolicy
91   {
92     Fixed,      ///< Fixed with the given value.
93     Relative,   ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width
94     Fill        ///< Get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns
95   };
96
97   /**
98    * Structure to specify layout position for child actor
99    */
100   struct CellPosition
101   {
102     /**
103      * Constructor to initialise values to defaults for convenience
104      */
105     CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
106                     unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
107     : rowIndex( rowIndex ), columnIndex( columnIndex ),
108       rowSpan( rowSpan ), columnSpan( columnSpan )
109     { }
110
111     unsigned int rowIndex;
112     unsigned int columnIndex;
113     unsigned int rowSpan;
114     unsigned int columnSpan;
115   };
116
117   /**
118    * Create a TableView handle; this can be initialised with TableView::New()
119    * Calling member functions with an uninitialised handle is not allowed.
120    */
121   TableView();
122
123   /**
124    * Copy constructor. Creates another handle that points to the same real object
125    * @param handle to copy from
126    */
127   TableView( const TableView& handle );
128
129   /**
130    * Assignment operator. Changes this handle to point to another real object
131    */
132   TableView& operator=( const TableView& handle );
133
134   /**
135    * @brief Destructor
136    *
137    * This is non-virtual since derived Handle types must not contain data or virtual methods.
138    */
139   ~TableView();
140
141   /**
142    * Create the TableView control.
143    * @param[in] initialRows for the table
144    * @param[in] initialColumns for the table
145    * @return A handle to the TableView control.
146    */
147   static TableView New( unsigned int initialRows, unsigned int initialColumns );
148
149   /**
150    * Downcast an Object handle to TableView. If handle points to a TableView the
151    * downcast produces valid handle. If not the returned handle is left uninitialized.
152    * @param[in] handle Handle to an object
153    * @return handle to a TableView or an uninitialized handle
154    */
155   static TableView DownCast( BaseHandle handle );
156
157   /**
158    * Adds a child to the table
159    * If the row or column index is outside the table, the table gets resized bigger
160    * @pre The child actor has been initialized.
161    * @param[in] child to add
162    * @param[in] position for the child
163    * @return true if the addition succeeded, false if the cell is already occupied
164    */
165   bool AddChild( Actor child, CellPosition position );
166
167   /**
168    * Returns a child from the given layout position
169    * Note! if there is no child in this position this method returns an uninitialized
170    * Actor handle
171    * @param[in] position in the table
172    * @return child that was in the cell or an uninitialized handle
173    */
174   Actor GetChildAt( CellPosition position );
175
176   /**
177    * Removes a child from the given layout position
178    * Note! if there is no child in this position this method does nothing
179    * @param[in] position for the child to remove
180    * @return child that was removed or an uninitialized handle
181    */
182   Actor RemoveChildAt( CellPosition position );
183
184   /**
185    * Finds the childs layout position
186    * @param[in] child to search for
187    * @param[out] position for the child
188    * @return true if the child was included in this TableView
189    */
190   bool FindChildPosition( Actor child, CellPosition& position );
191
192   /**
193    * Insert a new row to given index
194    * @param [in] rowIndex of the new row
195    */
196   void InsertRow( unsigned int rowIndex );
197
198   /**
199    * Delete a row from given index
200    * Removed elements are deleted
201    * @param [in] rowIndex of the row to delete
202    */
203   void DeleteRow( unsigned int rowIndex );
204
205   /**
206    * Delete a row from given index
207    * @param [in] rowIndex of the row to delete
208    * @param [out] removed elements
209    */
210   void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
211
212   /**
213    * Insert a new column to given index
214    * @param [in] columnIndex of the new column
215    */
216   void InsertColumn( unsigned int columnIndex );
217
218   /**
219    * Delete a column from given index.
220    * Removed elements are deleted
221    * @param [in] columnIndex of the column to delete
222    */
223   void DeleteColumn( unsigned int columnIndex );
224
225   /**
226    * Delete a column from given index
227    * @param [in] columnIndex of the column to delete
228    * @param [out] removed elements
229    */
230   void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
231
232   /**
233    * Resize the TableView. Note! if the new size is smaller than old,
234    * superfluous actors get removed. If you want to relayout removed children,
235    * use the variant that returns the removed Actors and reinsert them into the table
236    * If an actor spans to a removed row or column it gets removed from the table
237    * @param[in] rows for the table
238    * @param[in] columns for the table
239    */
240   void Resize( unsigned int rows, unsigned int columns );
241
242   /**
243    * Resize the TableView. Note! if the new size is smaller than old,
244    * superfluous actors get removed.
245    * If an actor spans to a removed row or column it gets removed from the table
246    * @param[in] rows for the table
247    * @param[in] columns for the table
248    * @param[out] removed actor handles
249    */
250   void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
251
252   /**
253    * Set horizontal and vertical padding between cells
254    * @param[in] padding width and height
255    */
256   void SetCellPadding( Size padding );
257
258   /**
259    * @return the current padding as width and height
260    */
261   Size GetCellPadding();
262
263   /**
264    * Sets a row to have fixed height
265    * Setting a fixed height of 0 has no effect
266    * @pre The row rowIndex must exist.
267    * @param rowIndex for row with fixed height
268    * @param height in world coordinate units
269    */
270   void SetFixedHeight( unsigned int rowIndex, float height );
271
272   /**
273    * Gets a row's fixed height.
274    * Note! The returned value is valid if it has been set before.
275    * @pre The row rowIndex must exist.
276    * @return height in world coordinate units.
277    */
278   float GetFixedHeight( unsigned int rowIndex ) const;
279
280   /**
281    * Sets a row to have relative height. Relative height means percentage of
282    * the remainder of the table height after subtracting Padding and Fixed height rows
283    * Setting a relative height of 0 has no effect
284    * @pre The row rowIndex must exist.
285    * @param rowIndex for row with relative height
286    * @param heightPercentage between 0.0f and 1.0f
287    */
288   void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
289
290   /**
291    * Gets a row's relative height.
292    * Note! The returned value is valid if it has been set before.
293    * @pre The row rowIndex must exist.
294    * @return height in percentage units, between 0.0f and 1.0f.
295    */
296   float GetRelativeHeight( unsigned int rowIndex ) const;
297
298   /**
299    * Sets a column to have fixed width
300    * Setting a fixed width of 0 has no effect
301    * @pre The column columnIndex must exist.
302    * @param columnIndex for column with fixed width
303    * @param width in world coordinate units
304    */
305   void SetFixedWidth( unsigned int columnIndex, float width );
306
307   /**
308    * Gets a column's fixed width.
309    * Note! The returned value is valid if it has been set before.
310    * @pre The column columnIndex must exist.
311    * @return width in world coordinate units.
312    */
313   float GetFixedWidth( unsigned int columnIndex ) const;
314
315   /**
316    * Sets a column to have relative width. Relative width means percentage of
317    * the remainder of table width after subtracting Padding and Fixed width columns
318    * Setting a relative width of 0 has no effect
319    * @pre The column columnIndex must exist.
320    * @param columnIndex for column with fixed width
321    * @param widthPercentage between 0.0f and 1.0f
322    */
323   void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
324
325   /**
326    * Gets a column's relative width.
327    * Note! The returned value is valid if it has been set before.
328    * @pre The column columnIndex must exist.
329    * @return width in percentage units, between 0.0f and 1.0f.
330    */
331   float GetRelativeWidth( unsigned int columnIndex ) const;
332
333   /**
334    * Sets the layout animation duration for add, remove and relayout
335    * @param duration for the layout animations
336    * @note The default duration is 0.0f.
337    */
338   void SetLayoutAnimationDuration( float duration );
339
340   /**
341    * Gets the layout animation duration for add, remove and relayout
342    * @return duration for the layout animations
343    */
344   float GetLayoutAnimationDuration();
345
346   /**
347    * @return the amount of rows in the table
348    */
349   unsigned int GetRows();
350
351   /**
352    * @return the amount of columns in the table
353    */
354   unsigned int GetColumns();
355
356 public: // Not intended for application developers
357
358   /**
359    * Creates a handle using the Toolkit::Internal implementation.
360    * @param[in]  implementation  The Control implementation.
361    */
362   TableView(Internal::TableView& implementation);
363
364   /**
365    * Allows the creation of this Control from an Internal::CustomActor pointer.
366    * @param[in]  internal  A pointer to the internal CustomActor.
367    */
368   TableView( Dali::Internal::CustomActor* internal );
369 };
370
371 } // namespace Toolkit
372
373 } // namespace Dali
374
375 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__