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