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