Merge "Apply the new doxygen tagging rule for @SINCE" 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 row-span or column span 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":"ImageActor",
73  * "image": {
74  *    "filename": "{DALI_IMAGE_DIR}gallery-small-1.jpg"
75  *  },
76  *  "customProperties": {
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
100   /**
101    * @brief An enumeration of properties belonging to the TableView class.
102    *
103    * LayoutRows: set the height of the rows.
104    * It has the format as follows in script:
105    * @code
106    * "layoutRows":
107    *       {
108    *         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedHight
109    *         "2": { "policy": "relative", "value": 0.33 },  //@see SetRelativeHeight
110    *         "3": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its height is decided by the children in this row
111    *       }
112    * @endcode
113    *
114    * LayoutColumns: set the height of the rows.
115    * It has the format as follows in script:
116    * @code
117    * "layoutColumns":
118    *       {
119    *         "0": { "policy": "fixed", "value": 40 },       //@see SetFixedWidth
120    *         "1": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its width is decided by the children in this column
121    *         "2": { "policy": "relative", "value": 0.33 }   //@see SetRelativeWidth
122    *       }
123    * @endcode
124    * @SINCE_1_0.0
125    */
126   struct Property
127   {
128     enum
129     {
130       ROWS = PROPERTY_START_INDEX, ///< name "rows",           type unsigned int @SINCE_1_0.0
131       COLUMNS,                     ///< name "columns",        type unsigned int @SINCE_1_0.0
132       CELL_PADDING,                ///< name "cellPadding",    type Vector2 @SINCE_1_0.0
133       LAYOUT_ROWS,                 ///< name "layoutRows",     type Map @SINCE_1_0.0
134       LAYOUT_COLUMNS,              ///< name "layoutColumns",  type Map @SINCE_1_0.0
135     };
136   };
137
138   /**
139    * @brief Describes how the size of a row / column been set
140    * @SINCE_1_0.0
141    */
142   enum LayoutPolicy
143   {
144     FIXED,      ///< Fixed with the given value. @SINCE_1_0.0
145     RELATIVE,   ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width @SINCE_1_0.0
146     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
147     FIT         ///< Fit around its children. @SINCE_1_0.0
148   };
149
150   /**
151    * @brief Structure to specify layout position for child actor
152    * @SINCE_1_0.0
153    */
154   struct CellPosition
155   {
156     /**
157      * @brief Constructor to initialise values to defaults for convenience
158      * @SINCE_1_0.0
159      */
160     CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
161                     unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
162     : rowIndex( rowIndex ), columnIndex( columnIndex ),
163       rowSpan( rowSpan ), columnSpan( columnSpan )
164     { }
165
166     unsigned int rowIndex;
167     unsigned int columnIndex;
168     unsigned int rowSpan;
169     unsigned int columnSpan;
170   };
171
172   /**
173    * @brief Create a TableView handle; this can be initialised with TableView::New()
174    * Calling member functions with an uninitialised handle is not allowed.
175    * @SINCE_1_0.0
176    */
177   TableView();
178
179   /**
180    * @brief Copy constructor. Creates another handle that points to the same real object
181    * @SINCE_1_0.0
182    * @param handle to copy from
183    */
184   TableView( const TableView& handle );
185
186   /**
187    * @brief Assignment operator. Changes this handle to point to another real object
188    * @SINCE_1_0.0
189    */
190   TableView& operator=( const TableView& handle );
191
192   /**
193    * @brief Destructor
194    *
195    * This is non-virtual since derived Handle types must not contain data or virtual methods.
196    * @SINCE_1_0.0
197    */
198   ~TableView();
199
200   /**
201    * @brief Create the TableView control.
202    * @SINCE_1_0.0
203    * @param[in] initialRows for the table
204    * @param[in] initialColumns for the table
205    * @return A handle to the TableView control.
206    */
207   static TableView New( unsigned int initialRows, unsigned int initialColumns );
208
209   /**
210    * @brief Downcast an Object handle to TableView. If handle points to a TableView the
211    * downcast produces valid handle. If not the returned handle is left uninitialized.
212    * @SINCE_1_0.0
213    * @param[in] handle Handle to an object
214    * @return handle to a TableView or an uninitialized handle
215    */
216   static TableView DownCast( BaseHandle handle );
217
218   /**
219    * @brief Adds a child to the table
220    * If the row or column index is outside the table, the table gets resized bigger
221    * @SINCE_1_0.0
222    * @param[in] child to add
223    * @param[in] position for the child
224    * @return true if the addition succeeded, false if the cell is already occupied
225    * @pre The child actor has been initialized.
226    */
227   bool AddChild( Actor child, CellPosition position );
228
229   /**
230    * @brief Returns a child from the given layout position
231    * Note! if there is no child in this position this method returns an uninitialized
232    * Actor handle
233    * @SINCE_1_0.0
234    * @param[in] position in the table
235    * @return child that was in the cell or an uninitialized handle
236    */
237   Actor GetChildAt( CellPosition position );
238
239   /**
240    * @brief Removes a child from the given layout position
241    * Note! if there is no child in this position this method does nothing
242    * @SINCE_1_0.0
243    * @param[in] position for the child to remove
244    * @return child that was removed or an uninitialized handle
245    */
246   Actor RemoveChildAt( CellPosition position );
247
248   /**
249    * @brief Finds the childs layout position
250    * @SINCE_1_0.0
251    * @param[in] child to search for
252    * @param[out] position for the child
253    * @return true if the child was included in this TableView
254    */
255   bool FindChildPosition( Actor child, CellPosition& position );
256
257   /**
258    * @brief Insert a new row to given index
259    * @SINCE_1_0.0
260    * @param [in] rowIndex of the new row
261    */
262   void InsertRow( unsigned int rowIndex );
263
264   /**
265    * @brief Delete a row from given index
266    * Removed elements are deleted
267    * @SINCE_1_0.0
268    * @param [in] rowIndex of the row to delete
269    */
270   void DeleteRow( unsigned int rowIndex );
271
272   /**
273    * @brief Delete a row from given index
274    * @SINCE_1_0.0
275    * @param [in] rowIndex of the row to delete
276    * @param [out] removed elements
277    */
278   void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
279
280   /**
281    * @brief Insert a new column to given index
282    * @SINCE_1_0.0
283    * @param [in] columnIndex of the new column
284    */
285   void InsertColumn( unsigned int columnIndex );
286
287   /**
288    * @brief Delete a column from given index.
289    * Removed elements are deleted
290    * @SINCE_1_0.0
291    * @param [in] columnIndex of the column to delete
292    */
293   void DeleteColumn( unsigned int columnIndex );
294
295   /**
296    * @brief Delete a column from given index
297    * @SINCE_1_0.0
298    * @param [in] columnIndex of the column to delete
299    * @param [out] removed elements
300    */
301   void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
302
303   /**
304    * @brief Resize the TableView. Note! if the new size is smaller than old,
305    * superfluous actors get removed. If you want to relayout removed children,
306    * use the variant that returns the removed Actors and reinsert them into the table
307    * If an actor spans to a removed row or column it gets removed from the table
308    * @SINCE_1_0.0
309    * @param[in] rows for the table
310    * @param[in] columns for the table
311    */
312   void Resize( unsigned int rows, unsigned int columns );
313
314   /**
315    * @brief Resize the TableView. Note! if the new size is smaller than old,
316    * superfluous actors get removed.
317    * If an actor spans to a removed row or column it gets removed from the table
318    * @SINCE_1_0.0
319    * @param[in] rows for the table
320    * @param[in] columns for the table
321    * @param[out] removed actor handles
322    */
323   void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
324
325   /**
326    * @brief Set horizontal and vertical padding between cells
327    * @SINCE_1_0.0
328    * @param[in] padding width and height
329    */
330   void SetCellPadding( Size padding );
331
332   /**
333    * @SINCE_1_0.0
334    * @return the current padding as width and height
335    */
336   Size GetCellPadding();
337
338   /**
339    * @brief Specify this row as fitting its height to its children
340    *
341    * @SINCE_1_0.0
342    * @param[in] rowIndex The row to set
343    */
344   void SetFitHeight( unsigned int rowIndex );
345
346   /**
347    * @brief Is the row a fit row
348    *
349    * @SINCE_1_0.0
350    * @param[in] rowIndex The row to check
351    * @return Return true if the row is fit
352    */
353   bool IsFitHeight( unsigned int rowIndex ) const;
354
355   /**
356    * @brief Specify this column as fitting its width to its children
357    *
358    * @SINCE_1_0.0
359    * @param[in] columnIndex The column to set
360    */
361   void SetFitWidth( unsigned int columnIndex );
362
363   /**
364    * @brief Is the column a fit column
365    *
366    * @SINCE_1_0.0
367    * @param[in] columnIndex The column to check
368    * @return Return true if the column is fit
369    */
370   bool IsFitWidth( unsigned int columnIndex ) const;
371
372   /**
373    * @brief Sets a row to have fixed height
374    * Setting a fixed height of 0 has no effect
375    * @SINCE_1_0.0
376    * @param rowIndex for row with fixed height
377    * @param height in world coordinate units
378    * @pre The row rowIndex must exist.
379    */
380   void SetFixedHeight( unsigned int rowIndex, float height );
381
382   /**
383    * @brief Gets a row's fixed height.
384    * Note! The returned value is valid if it has been set before.
385    * @SINCE_1_0.0
386    * @return height in world coordinate units.
387    * @pre The row rowIndex must exist.
388    */
389   float GetFixedHeight( unsigned int rowIndex ) const;
390
391   /**
392    * @brief Sets a row to have relative height. Relative height means percentage of
393    * the remainder of the table height after subtracting Padding and Fixed height rows
394    * Setting a relative height of 0 has no effect
395    * @SINCE_1_0.0
396    * @param rowIndex for row with relative height
397    * @param heightPercentage between 0.0f and 1.0f
398    * @pre The row rowIndex must exist.
399    */
400   void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
401
402   /**
403    * @brief Gets a row's relative height.
404    * Note! The returned value is valid if it has been set before.
405    * @SINCE_1_0.0
406    * @return height in percentage units, between 0.0f and 1.0f.
407    * @pre The row rowIndex must exist.
408    */
409   float GetRelativeHeight( unsigned int rowIndex ) const;
410
411   /**
412    * @brief Sets a column to have fixed width
413    * Setting a fixed width of 0 has no effect
414    * @SINCE_1_0.0
415    * @param columnIndex for column with fixed width
416    * @param width in world coordinate units
417    * @pre The column columnIndex must exist.
418    */
419   void SetFixedWidth( unsigned int columnIndex, float width );
420
421   /**
422    * @brief Gets a column's fixed width.
423    * Note! The returned value is valid if it has been set before.
424    * @SINCE_1_0.0
425    * @return width in world coordinate units.
426    * @pre The column columnIndex must exist.
427    */
428   float GetFixedWidth( unsigned int columnIndex ) const;
429
430   /**
431    * @brief Sets a column to have relative width. Relative width means percentage of
432    * the remainder of table width after subtracting Padding and Fixed width columns
433    * Setting a relative width of 0 has no effect
434    * @SINCE_1_0.0
435    * @param columnIndex for column with fixed width
436    * @param widthPercentage between 0.0f and 1.0f
437    * @pre The column columnIndex must exist.
438    */
439   void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
440
441   /**
442    * @brief Gets a column's relative width.
443    * Note! The returned value is valid if it has been set before.
444    * @SINCE_1_0.0
445    * @return width in percentage units, between 0.0f and 1.0f.
446    * @pre The column columnIndex must exist.
447    */
448   float GetRelativeWidth( unsigned int columnIndex ) const;
449
450   /**
451    * @SINCE_1_0.0
452    * @return the amount of rows in the table
453    */
454   unsigned int GetRows();
455
456   /**
457    * @SINCE_1_0.0
458    * @return the amount of columns in the table
459    */
460   unsigned int GetColumns();
461
462   /**
463    * @brief Set the alignment on a cell.
464    *
465    * Cells without calling this function have the default values of LEFT and TOP respectively.
466    *
467    * @SINCE_1_0.0
468    * @param[in] position The cell to set alignment on.
469    * @param[in] horizontal The horizontal alignment.
470    * @param[in] vertical The vertical alignment.
471    */
472   void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
473
474 public: // Not intended for application developers
475
476   /**
477    * @brief Creates a handle using the Toolkit::Internal implementation.
478    * @SINCE_1_0.0
479    * @param[in]  implementation  The Control implementation.
480    */
481   DALI_INTERNAL TableView(Internal::TableView& implementation);
482
483   /**
484    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
485    * @SINCE_1_0.0
486    * @param[in]  internal  A pointer to the internal CustomActor.
487    */
488   explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
489 };
490
491 /**
492  * @}
493  */
494 } // namespace Toolkit
495
496 } // namespace Dali
497
498 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__