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/vector-wrapper.h>
25 #include <dali-toolkit/public-api/controls/control.h>
33 namespace Internal DALI_INTERNAL
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.
44 class DALI_IMPORT_API TableView : public Control
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
56 * PROPERTY_LAYOUT_ROWS set the height of the rows
57 * It has the format as follows in script:
61 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
62 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight
66 static const Property::Index PROPERTY_LAYOUT_ROWS; ///< name "layout-rows", type MAP
69 * PROPERTY_LAYOUT_COLUMNS set the height of the rows
70 * It has the format as follows in script:
74 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
75 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
79 static const Property::Index PROPERTY_LAYOUT_COLUMNS; ///< name "layout-columns", type MAP
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)
90 * @brief Describes how the size of a row / column been set
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
100 * Structure to specify layout position for child actor
105 * Constructor to initialise values to defaults for convenience
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 )
113 unsigned int rowIndex;
114 unsigned int columnIndex;
115 unsigned int rowSpan;
116 unsigned int columnSpan;
120 * Create a TableView handle; this can be initialised with TableView::New()
121 * Calling member functions with an uninitialised handle is not allowed.
126 * Copy constructor. Creates another handle that points to the same real object
127 * @param handle to copy from
129 TableView( const TableView& handle );
132 * Assignment operator. Changes this handle to point to another real object
134 TableView& operator=( const TableView& handle );
139 * This is non-virtual since derived Handle types must not contain data or virtual methods.
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.
149 static TableView New( unsigned int initialRows, unsigned int initialColumns );
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
157 static TableView DownCast( BaseHandle handle );
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
167 bool AddChild( Actor child, CellPosition position );
170 * Returns a child from the given layout position
171 * Note! if there is no child in this position this method returns an uninitialized
173 * @param[in] position in the table
174 * @return child that was in the cell or an uninitialized handle
176 Actor GetChildAt( CellPosition position );
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
184 Actor RemoveChildAt( CellPosition position );
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
192 bool FindChildPosition( Actor child, CellPosition& position );
195 * Insert a new row to given index
196 * @param [in] rowIndex of the new row
198 void InsertRow( unsigned int rowIndex );
201 * Delete a row from given index
202 * Removed elements are deleted
203 * @param [in] rowIndex of the row to delete
205 void DeleteRow( unsigned int rowIndex );
208 * Delete a row from given index
209 * @param [in] rowIndex of the row to delete
210 * @param [out] removed elements
212 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
215 * Insert a new column to given index
216 * @param [in] columnIndex of the new column
218 void InsertColumn( unsigned int columnIndex );
221 * Delete a column from given index.
222 * Removed elements are deleted
223 * @param [in] columnIndex of the column to delete
225 void DeleteColumn( unsigned int columnIndex );
228 * Delete a column from given index
229 * @param [in] columnIndex of the column to delete
230 * @param [out] removed elements
232 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
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
242 void Resize( unsigned int rows, unsigned int columns );
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
252 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
255 * Set horizontal and vertical padding between cells
256 * @param[in] padding width and height
258 void SetCellPadding( Size padding );
261 * @return the current padding as width and height
263 Size GetCellPadding();
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
272 void SetFixedHeight( unsigned int rowIndex, float height );
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.
280 float GetFixedHeight( unsigned int rowIndex ) const;
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
290 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
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.
298 float GetRelativeHeight( unsigned int rowIndex ) const;
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
307 void SetFixedWidth( unsigned int columnIndex, float width );
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.
315 float GetFixedWidth( unsigned int columnIndex ) const;
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
325 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
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.
333 float GetRelativeWidth( unsigned int columnIndex ) const;
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.
340 void SetLayoutAnimationDuration( float duration );
343 * Gets the layout animation duration for add, remove and relayout
344 * @return duration for the layout animations
346 float GetLayoutAnimationDuration();
349 * @return the amount of rows in the table
351 unsigned int GetRows();
354 * @return the amount of columns in the table
356 unsigned int GetColumns();
358 public: // Not intended for application developers
361 * Creates a handle using the Toolkit::Internal implementation.
362 * @param[in] implementation The Control implementation.
364 DALI_INTERNAL TableView(Internal::TableView& implementation);
367 * Allows the creation of this Control from an Internal::CustomActor pointer.
368 * @param[in] internal A pointer to the internal CustomActor.
370 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
373 } // namespace Toolkit
377 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__