Merge "Fix Svace issue" into devel/master
[platform/core/uifw/dali-toolkit.git] / 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) 2015 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/actors/actor-enumerations.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class TableView;
37 }
38 /**
39  * @addtogroup dali_toolkit_controls_table_view
40  * @{
41  */
42
43 /**
44  * @brief TableView is a layout container for aligning child actors in a grid like layout.
45  *
46  * TableView constrains the x and y position and width and height of the child actors.
47  * z position and depth are left intact so that 3D model actors can also be laid out
48  * in a grid without loosing their depth scaling.
49  *
50  * @nosubgrouping
51  * <h3>Per-child Custom properties for script supporting:</h3>
52  *
53  * When an actor is add to the tableView through Actor::Add() instead of TableView::AddChild,
54  * the following custom properties of the actor are checked to decide the actor position inside the table.
55  *
56  * These properties are registered dynamically to the child and is non-animatable.
57  *
58  * | %Property Name          | Type        |
59  * |-------------------------|-------------|
60  * | cellIndex               | Vector2     |
61  * | rowSpan                 | float       |
62  * | columnSpan              | float       |
63  * | cellHorizontalAlignment | string      |
64  * | cellVerticalAlignment   | string      |
65  *
66  * The rowSpan or columnSpan has integer value, but its type is float here due to the limitation of the builder's ability to differentiate integer and float from Json string.
67  * The available values for cellHorizontalAlignment are: left, center, right.
68  * The available values for cellVerticalAlignment are: top, center, bottom.
69  *
70  * @code
71  * "name":"gallery1",
72  * "type":"ImageView",
73  * "image": {
74  *    "url": "{DALI_IMAGE_DIR}gallery-small-1.jpg"
75  *  },
76  *  "properties": {
77  *     "cellIndex":[1,1],  // property to specify the top-left cell this child occupies, if not set, the first available cell is used
78  *     "rowSpan":3,        // property to specify how many rows this child occupies, if not set, default value is 1
79  *     "columnSpan": 2,    // property to specify how many columns this child occupies, if nor set, default value is 1
80  *     "cellHorizontalAlignment": "left", // property to specify how to align horizontally inside the cells, if not set, default value is 'left'
81  *     "cellVerticalAlignment": "center"  // property to specify how to align vertically inside the cells, if not set, default value is 'top'
82  *   }
83  * @endcode
84  * @SINCE_1_0.0
85  */
86 class DALI_IMPORT_API TableView : public Control
87 {
88 public:
89
90   /**
91    * @brief The start and end property ranges for this control.
92    * @SINCE_1_0.0
93    */
94   enum PropertyRange
95   {
96     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
97     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000,             ///< Reserve property indices @SINCE_1_0.0
98
99     CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX,         ///< @SINCE_1_1.36
100     CHILD_PROPERTY_END_INDEX =   CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000   ///< Reserve child property indices @SINCE_1_1.36
101   };
102
103   /**
104    * @brief An enumeration of properties belonging to the TableView class.
105    *
106    * LayoutRows: set the height of the rows.
107    * It has the format as follows in script:
108    * @code
109    * "layoutRows":
110    *       {
111    *         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedHight
112    *         "2": { "policy": "relative", "value": 0.33 },  //@see SetRelativeHeight
113    *         "3": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its height is decided by the children in this row
114    *       }
115    * @endcode
116    *
117    * LayoutColumns: set the width of the columns.
118    * It has the format as follows in script:
119    * @code
120    * "layoutColumns":
121    *       {
122    *         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedWidth
123    *         "1": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its width is decided by the children in this column
124    *         "2": { "policy": "relative", "value": 0.33 }   //@see SetRelativeWidth
125    *       }
126    * @endcode
127    * @SINCE_1_0.0
128    */
129   struct Property
130   {
131     enum
132     {
133       ROWS = PROPERTY_START_INDEX, ///< name "rows",           type unsigned int @SINCE_1_0.0
134       COLUMNS,                     ///< name "columns",        type unsigned int @SINCE_1_0.0
135       CELL_PADDING,                ///< name "cellPadding",    type Vector2 @SINCE_1_0.0
136       LAYOUT_ROWS,                 ///< name "layoutRows",     type Map @SINCE_1_0.0
137       LAYOUT_COLUMNS,              ///< name "layoutColumns",  type Map @SINCE_1_0.0
138     };
139   };
140
141   /**
142    * @brief An enumeration of child properties belonging to the TableView class.
143    * @SINCE_1_1.36
144    */
145   struct ChildProperty
146   {
147     enum
148     {
149       CELL_INDEX = CHILD_PROPERTY_START_INDEX,  ///< name "cellIndex",                The top-left cell this child occupies, if not set, the first available cell is used,           type VECTOR2 @SINCE_1_1.36
150       ROW_SPAN,                                 ///< name "rowSpan",                  The number of rows this child occupies, if not set, default value is 1,                        type FLOAT @SINCE_1_1.36
151       COLUMN_SPAN,                              ///< name "columnSpan",               The number of columns this child occupies, if not set, default value is 1,                     type FLOAT @SINCE_1_1.36
152       CELL_HORIZONTAL_ALIGNMENT,                ///< name "cellHorizontalAlignment",  The horizontal alignment of this child inside the cells, if not set, default value is 'left',  type STRING @SINCE_1_1.36
153       CELL_VERTICAL_ALIGNMENT                   ///< name "cellVerticalAlignment",    The vertical alignment of this child inside the cells, if not set, default value is 'top',     type STRING @SINCE_1_1.36
154     };
155   };
156
157   /**
158    * @brief Describes how the size of a row / column been set
159    * @SINCE_1_0.0
160    */
161   enum LayoutPolicy
162   {
163     FIXED,      ///< Fixed with the given value. @SINCE_1_0.0
164     RELATIVE,   ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width @SINCE_1_0.0
165     FILL,       ///< Default policy, get the remainder of the 100% (after subtracting Fixed, Fit and Relative height/ width) divided evenly between 'fill' rows/columns @SINCE_1_0.0
166     FIT         ///< Fit around its children. @SINCE_1_0.0
167   };
168
169   /**
170    * @brief Structure to specify layout position for child actor
171    * @SINCE_1_0.0
172    */
173   struct CellPosition
174   {
175     /**
176      * @brief Constructor to initialise values to defaults for convenience
177      * @SINCE_1_0.0
178      */
179     CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
180                     unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
181     : rowIndex( rowIndex ), columnIndex( columnIndex ),
182       rowSpan( rowSpan ), columnSpan( columnSpan )
183     { }
184
185     unsigned int rowIndex;
186     unsigned int columnIndex;
187     unsigned int rowSpan;
188     unsigned int columnSpan;
189   };
190
191   /**
192    * @brief Create a TableView handle; this can be initialised with TableView::New()
193    * Calling member functions with an uninitialised handle is not allowed.
194    * @SINCE_1_0.0
195    */
196   TableView();
197
198   /**
199    * @brief Copy constructor. Creates another handle that points to the same real object
200    * @SINCE_1_0.0
201    * @param handle to copy from
202    */
203   TableView( const TableView& handle );
204
205   /**
206    * @brief Assignment operator. Changes this handle to point to another real object
207    * @SINCE_1_0.0
208    */
209   TableView& operator=( const TableView& handle );
210
211   /**
212    * @brief Destructor
213    *
214    * This is non-virtual since derived Handle types must not contain data or virtual methods.
215    * @SINCE_1_0.0
216    */
217   ~TableView();
218
219   /**
220    * @brief Create the TableView control.
221    * @SINCE_1_0.0
222    * @param[in] initialRows for the table
223    * @param[in] initialColumns for the table
224    * @return A handle to the TableView control.
225    */
226   static TableView New( unsigned int initialRows, unsigned int initialColumns );
227
228   /**
229    * @brief Downcast a handle to TableView handle.
230    *
231    * If handle points to a TableView the
232    * downcast produces valid handle. If not the returned handle is left uninitialized.
233    * @SINCE_1_0.0
234    * @param[in] handle Handle to an object
235    * @return handle to a TableView or an uninitialized handle
236    */
237   static TableView DownCast( BaseHandle handle );
238
239   /**
240    * @brief Adds a child to the table
241    * If the row or column index is outside the table, the table gets resized bigger
242    * @SINCE_1_0.0
243    * @param[in] child to add
244    * @param[in] position for the child
245    * @return true if the addition succeeded, false if the cell is already occupied
246    * @pre The child actor has been initialized.
247    */
248   bool AddChild( Actor child, CellPosition position );
249
250   /**
251    * @brief Returns a child from the given layout position
252    * @SINCE_1_0.0
253    * @param[in] position in the table
254    * @return child that was in the cell or an uninitialized handle
255    * @note If there is no child in this position this method returns an uninitialized.
256    * Actor handle
257    */
258   Actor GetChildAt( CellPosition position );
259
260   /**
261    * @brief Removes a child from the given layout position
262    * @SINCE_1_0.0
263    * @param[in] position for the child to remove
264    * @return child that was removed or an uninitialized handle
265    * @note If there is no child in this position this method does nothing.
266    */
267   Actor RemoveChildAt( CellPosition position );
268
269   /**
270    * @brief Finds the childs layout position
271    * @SINCE_1_0.0
272    * @param[in] child to search for
273    * @param[out] position for the child
274    * @return true if the child was included in this TableView
275    */
276   bool FindChildPosition( Actor child, CellPosition& position );
277
278   /**
279    * @brief Insert a new row to given index
280    * @SINCE_1_0.0
281    * @param [in] rowIndex of the new row
282    */
283   void InsertRow( unsigned int rowIndex );
284
285   /**
286    * @brief Delete a row from given index
287    * Removed elements are deleted
288    * @SINCE_1_0.0
289    * @param [in] rowIndex of the row to delete
290    */
291   void DeleteRow( unsigned int rowIndex );
292
293   /**
294    * @brief Delete a row from given index
295    * @SINCE_1_0.0
296    * @param [in] rowIndex of the row to delete
297    * @param [out] removed elements
298    */
299   void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
300
301   /**
302    * @brief Insert a new column to given index
303    * @SINCE_1_0.0
304    * @param [in] columnIndex of the new column
305    */
306   void InsertColumn( unsigned int columnIndex );
307
308   /**
309    * @brief Delete a column from given index.
310    * Removed elements are deleted
311    * @SINCE_1_0.0
312    * @param [in] columnIndex of the column to delete
313    */
314   void DeleteColumn( unsigned int columnIndex );
315
316   /**
317    * @brief Delete a column from given index
318    * @SINCE_1_0.0
319    * @param [in] columnIndex of the column to delete
320    * @param [out] removed elements
321    */
322   void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
323
324   /**
325    * @brief Resize the TableView.
326    * @SINCE_1_0.0
327    * @param[in] rows for the table
328    * @param[in] columns for the table
329    * @note If the new size is smaller than old,
330    * superfluous actors get removed. If you want to relayout removed children,
331    * use the variant that returns the removed Actors and reinsert them into the table.
332    * If an actor spans to a removed row or column it gets removed from the table.
333    */
334   void Resize( unsigned int rows, unsigned int columns );
335
336   /**
337    * @brief Resize the TableView.
338    * @SINCE_1_0.0
339    * @param[in] rows for the table
340    * @param[in] columns for the table
341    * @param[out] removed actor handles
342    * @note If the new size is smaller than old,
343    * superfluous actors get removed.
344    * If an actor spans to a removed row or column it gets removed from the table.
345    */
346   void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
347
348   /**
349    * @brief Set horizontal and vertical padding between cells
350    * @SINCE_1_0.0
351    * @param[in] padding width and height
352    */
353   void SetCellPadding( Size padding );
354
355   /**
356    * @brief Get the current padding as width and height.
357    * @SINCE_1_0.0
358    * @return the current padding as width and height
359    */
360   Size GetCellPadding();
361
362   /**
363    * @brief Specify this row as fitting its height to its children
364    *
365    * @SINCE_1_0.0
366    * @param[in] rowIndex The row to set
367    */
368   void SetFitHeight( unsigned int rowIndex );
369
370   /**
371    * @brief Is the row a fit row
372    *
373    * @SINCE_1_0.0
374    * @param[in] rowIndex The row to check
375    * @return Return true if the row is fit
376    */
377   bool IsFitHeight( unsigned int rowIndex ) const;
378
379   /**
380    * @brief Specify this column as fitting its width to its children
381    *
382    * @SINCE_1_0.0
383    * @param[in] columnIndex The column to set
384    */
385   void SetFitWidth( unsigned int columnIndex );
386
387   /**
388    * @brief Is the column a fit column
389    *
390    * @SINCE_1_0.0
391    * @param[in] columnIndex The column to check
392    * @return Return true if the column is fit
393    */
394   bool IsFitWidth( unsigned int columnIndex ) const;
395
396   /**
397    * @brief Sets a row to have fixed height
398    * Setting a fixed height of 0 has no effect
399    * @SINCE_1_0.0
400    * @param rowIndex for row with fixed height
401    * @param height in world coordinate units
402    * @pre The row rowIndex must exist.
403    */
404   void SetFixedHeight( unsigned int rowIndex, float height );
405
406   /**
407    * @brief Gets a row's fixed height.
408    * @SINCE_1_0.0
409    * @return height in world coordinate units.
410    * @pre The row rowIndex must exist.
411    * @note The returned value is valid if it has been set before.
412    */
413   float GetFixedHeight( unsigned int rowIndex ) const;
414
415   /**
416    * @brief Sets a row to have relative height. Relative height means percentage of
417    * the remainder of the table height after subtracting Padding and Fixed height rows
418    * Setting a relative height of 0 has no effect
419    * @SINCE_1_0.0
420    * @param rowIndex for row with relative height
421    * @param heightPercentage between 0.0f and 1.0f
422    * @pre The row rowIndex must exist.
423    */
424   void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
425
426   /**
427    * @brief Gets a row's relative height.
428    * @SINCE_1_0.0
429    * @return height in percentage units, between 0.0f and 1.0f.
430    * @pre The row rowIndex must exist.
431    * @note The returned value is valid if it has been set before.
432    */
433   float GetRelativeHeight( unsigned int rowIndex ) const;
434
435   /**
436    * @brief Sets a column to have fixed width
437    * Setting a fixed width of 0 has no effect
438    * @SINCE_1_0.0
439    * @param columnIndex for column with fixed width
440    * @param width in world coordinate units
441    * @pre The column columnIndex must exist.
442    */
443   void SetFixedWidth( unsigned int columnIndex, float width );
444
445   /**
446    * @brief Gets a column's fixed width.
447    * @SINCE_1_0.0
448    * @return width in world coordinate units.
449    * @pre The column columnIndex must exist.
450    * @note The returned value is valid if it has been set before.
451    */
452   float GetFixedWidth( unsigned int columnIndex ) const;
453
454   /**
455    * @brief Sets a column to have relative width. Relative width means percentage of
456    * the remainder of table width after subtracting Padding and Fixed width columns
457    * Setting a relative width of 0 has no effect
458    * @SINCE_1_0.0
459    * @param columnIndex for column with fixed width
460    * @param widthPercentage between 0.0f and 1.0f
461    * @pre The column columnIndex must exist.
462    */
463   void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
464
465   /**
466    * @brief Gets a column's relative width.
467    * @SINCE_1_0.0
468    * @return width in percentage units, between 0.0f and 1.0f.
469    * @pre The column columnIndex must exist.
470    * @note The returned value is valid if it has been set before.
471    */
472   float GetRelativeWidth( unsigned int columnIndex ) const;
473
474   /**
475    * @brief Gets the amount of rows in the table.
476    * @SINCE_1_0.0
477    * @return the amount of rows in the table
478    */
479   unsigned int GetRows();
480
481   /**
482    * @brief Gets the amount of columns in the table.
483    * @SINCE_1_0.0
484    * @return the amount of columns in the table
485    */
486   unsigned int GetColumns();
487
488   /**
489    * @brief Set the alignment on a cell.
490    *
491    * Cells without calling this function have the default values of LEFT and TOP respectively.
492    *
493    * @SINCE_1_0.0
494    * @param[in] position The cell to set alignment on.
495    * @param[in] horizontal The horizontal alignment.
496    * @param[in] vertical The vertical alignment.
497    */
498   void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
499
500 public: // Not intended for application developers
501
502   /**
503    * @brief Creates a handle using the Toolkit::Internal implementation.
504    * @SINCE_1_0.0
505    * @param[in]  implementation  The Control implementation.
506    */
507   DALI_INTERNAL TableView(Internal::TableView& implementation);
508
509   /**
510    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
511    * @SINCE_1_0.0
512    * @param[in]  internal  A pointer to the internal CustomActor.
513    */
514   explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
515 };
516
517 /**
518  * @}
519  */
520 } // namespace Toolkit
521
522 } // namespace Dali
523
524 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__