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