1 #ifndef __DALI_TOOLKIT_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_TABLE_VIEW_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali-toolkit/public-api/controls/control.h>
25 namespace Dali DALI_IMPORT_API
31 namespace Internal DALI_INTERNAL
37 * TableView is a layout container for aligning child actors in a grid like layout.
38 * TableView constrains the x and y position and width and height of the child actors.
39 * z position and depth are left intact so that 3D model actors can also be laid out
40 * in a grid without loosing their depth scaling.
42 class TableView : public Control
48 static const Property::Index PROPERTY_ROWS; ///< name "rows", type UNSIGNED_INTEGER
49 static const Property::Index PROPERTY_COLUMNS; ///< name "columns", type UNSIGNED_INTEGER
50 static const Property::Index PROPERTY_CELL_PADDING; ///< name "cell-padding", type VECTOR2
51 static const Property::Index PROPERTY_LAYOUT_ANIMATION_DURATION; ///< name "layout-animation-duration", type FLOAT
54 * PROPERTY_LAYOUT_ROWS set the height of the rows
55 * It has the format as follows in script:
59 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
60 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight
64 static const Property::Index PROPERTY_LAYOUT_ROWS; ///< name "layout-rows", type MAP
67 * PROPERTY_LAYOUT_COLUMNS set the height of the rows
68 * It has the format as follows in script:
72 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
73 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
77 static const Property::Index PROPERTY_LAYOUT_COLUMNS; ///< name "layout-columns", type MAP
81 // Custom properties for where to put the actor, these properties should be registered to the child which would be added to the table
82 static const std::string CELL_INDICES_PROPERTY_NAME; ///< Property, name "cell-indices", type VECTOR2
83 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)
84 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)
88 * @brief Describes how the size of a row / column been set
92 Fixed, ///< Fixed with the given value.
93 Relative, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width
94 Fill ///< Get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns
98 * Structure to specify layout position for child actor
103 * Constructor to initialise values to defaults for convenience
105 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
106 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
107 : rowIndex( rowIndex ), columnIndex( columnIndex ),
108 rowSpan( rowSpan ), columnSpan( columnSpan )
111 unsigned int rowIndex;
112 unsigned int columnIndex;
113 unsigned int rowSpan;
114 unsigned int columnSpan;
118 * Create a TableView handle; this can be initialised with TableView::New()
119 * Calling member functions with an uninitialised handle is not allowed.
124 * Copy constructor. Creates another handle that points to the same real object
125 * @param handle to copy from
127 TableView( const TableView& handle );
130 * Assignment operator. Changes this handle to point to another real object
132 TableView& operator=( const TableView& handle );
137 * This is non-virtual since derived Handle types must not contain data or virtual methods.
142 * Create the TableView control.
143 * @param[in] initialRows for the table
144 * @param[in] initialColumns for the table
145 * @return A handle to the TableView control.
147 static TableView New( unsigned int initialRows, unsigned int initialColumns );
150 * Downcast an Object handle to TableView. If handle points to a TableView the
151 * downcast produces valid handle. If not the returned handle is left uninitialized.
152 * @param[in] handle Handle to an object
153 * @return handle to a TableView or an uninitialized handle
155 static TableView DownCast( BaseHandle handle );
158 * Adds a child to the table
159 * If the row or column index is outside the table, the table gets resized bigger
160 * @pre The child actor has been initialized.
161 * @param[in] child to add
162 * @param[in] position for the child
163 * @return true if the addition succeeded, false if the cell is already occupied
165 bool AddChild( Actor child, CellPosition position );
168 * Returns a child from the given layout position
169 * Note! if there is no child in this position this method returns an uninitialized
171 * @param[in] position in the table
172 * @return child that was in the cell or an uninitialized handle
174 Actor GetChildAt( CellPosition position );
177 * Removes a child from the given layout position
178 * Note! if there is no child in this position this method does nothing
179 * @param[in] position for the child to remove
180 * @return child that was removed or an uninitialized handle
182 Actor RemoveChildAt( CellPosition position );
185 * Finds the childs layout position
186 * @param[in] child to search for
187 * @param[out] position for the child
188 * @return true if the child was included in this TableView
190 bool FindChildPosition( Actor child, CellPosition& position );
193 * Insert a new row to given index
194 * @param [in] rowIndex of the new row
196 void InsertRow( unsigned int rowIndex );
199 * Delete a row from given index
200 * Removed elements are deleted
201 * @param [in] rowIndex of the row to delete
203 void DeleteRow( unsigned int rowIndex );
206 * Delete a row from given index
207 * @param [in] rowIndex of the row to delete
208 * @param [out] removed elements
210 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
213 * Insert a new column to given index
214 * @param [in] columnIndex of the new column
216 void InsertColumn( unsigned int columnIndex );
219 * Delete a column from given index.
220 * Removed elements are deleted
221 * @param [in] columnIndex of the column to delete
223 void DeleteColumn( unsigned int columnIndex );
226 * Delete a column from given index
227 * @param [in] columnIndex of the column to delete
228 * @param [out] removed elements
230 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
233 * Resize the TableView. Note! if the new size is smaller than old,
234 * superfluous actors get removed. If you want to relayout removed children,
235 * use the variant that returns the removed Actors and reinsert them into the table
236 * If an actor spans to a removed row or column it gets removed from the table
237 * @param[in] rows for the table
238 * @param[in] columns for the table
240 void Resize( unsigned int rows, unsigned int columns );
243 * Resize the TableView. Note! if the new size is smaller than old,
244 * superfluous actors get removed.
245 * If an actor spans to a removed row or column it gets removed from the table
246 * @param[in] rows for the table
247 * @param[in] columns for the table
248 * @param[out] removed actor handles
250 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
253 * Set horizontal and vertical padding between cells
254 * @param[in] padding width and height
256 void SetCellPadding( Size padding );
259 * @return the current padding as width and height
261 Size GetCellPadding();
264 * Sets a row to have fixed height
265 * Setting a fixed height of 0 has no effect
266 * @pre The row rowIndex must exist.
267 * @param rowIndex for row with fixed height
268 * @param height in world coordinate units
270 void SetFixedHeight( unsigned int rowIndex, float height );
273 * Gets a row's fixed height.
274 * Note! The returned value is valid if it has been set before.
275 * @pre The row rowIndex must exist.
276 * @return height in world coordinate units.
278 float GetFixedHeight( unsigned int rowIndex ) const;
281 * Sets a row to have relative height. Relative height means percentage of
282 * the remainder of the table height after subtracting Padding and Fixed height rows
283 * Setting a relative height of 0 has no effect
284 * @pre The row rowIndex must exist.
285 * @param rowIndex for row with relative height
286 * @param heightPercentage between 0.0f and 1.0f
288 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
291 * Gets a row's relative height.
292 * Note! The returned value is valid if it has been set before.
293 * @pre The row rowIndex must exist.
294 * @return height in percentage units, between 0.0f and 1.0f.
296 float GetRelativeHeight( unsigned int rowIndex ) const;
299 * Sets a column to have fixed width
300 * Setting a fixed width of 0 has no effect
301 * @pre The column columnIndex must exist.
302 * @param columnIndex for column with fixed width
303 * @param width in world coordinate units
305 void SetFixedWidth( unsigned int columnIndex, float width );
308 * Gets a column's fixed width.
309 * Note! The returned value is valid if it has been set before.
310 * @pre The column columnIndex must exist.
311 * @return width in world coordinate units.
313 float GetFixedWidth( unsigned int columnIndex ) const;
316 * Sets a column to have relative width. Relative width means percentage of
317 * the remainder of table width after subtracting Padding and Fixed width columns
318 * Setting a relative width of 0 has no effect
319 * @pre The column columnIndex must exist.
320 * @param columnIndex for column with fixed width
321 * @param widthPercentage between 0.0f and 1.0f
323 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
326 * Gets a column's relative width.
327 * Note! The returned value is valid if it has been set before.
328 * @pre The column columnIndex must exist.
329 * @return width in percentage units, between 0.0f and 1.0f.
331 float GetRelativeWidth( unsigned int columnIndex ) const;
334 * Sets the layout animation duration for add, remove and relayout
335 * @param duration for the layout animations
336 * @note The default duration is 0.0f.
338 void SetLayoutAnimationDuration( float duration );
341 * Gets the layout animation duration for add, remove and relayout
342 * @return duration for the layout animations
344 float GetLayoutAnimationDuration();
347 * @return the amount of rows in the table
349 unsigned int GetRows();
352 * @return the amount of columns in the table
354 unsigned int GetColumns();
356 public: // Not intended for application developers
359 * Creates a handle using the Toolkit::Internal implementation.
360 * @param[in] implementation The Control implementation.
362 TableView(Internal::TableView& implementation);
365 * Allows the creation of this Control from an Internal::CustomActor pointer.
366 * @param[in] internal A pointer to the internal CustomActor.
368 TableView( Dali::Internal::CustomActor* internal );
371 } // namespace Toolkit
375 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__