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
55 * PROPERTY_LAYOUT_ROWS set the height of the rows
56 * It has the format as follows in script:
60 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
61 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight
65 static const Property::Index PROPERTY_LAYOUT_ROWS; ///< name "layout-rows", type MAP
68 * PROPERTY_LAYOUT_COLUMNS set the height of the rows
69 * It has the format as follows in script:
73 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
74 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
78 static const Property::Index PROPERTY_LAYOUT_COLUMNS; ///< name "layout-columns", type MAP
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)
89 * @brief Describes how the size of a row / column been set
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
99 * Structure to specify layout position for child actor
104 * Constructor to initialise values to defaults for convenience
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 )
112 unsigned int rowIndex;
113 unsigned int columnIndex;
114 unsigned int rowSpan;
115 unsigned int columnSpan;
119 * Create a TableView handle; this can be initialised with TableView::New()
120 * Calling member functions with an uninitialised handle is not allowed.
125 * Copy constructor. Creates another handle that points to the same real object
126 * @param handle to copy from
128 TableView( const TableView& handle );
131 * Assignment operator. Changes this handle to point to another real object
133 TableView& operator=( const TableView& handle );
138 * This is non-virtual since derived Handle types must not contain data or virtual methods.
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.
148 static TableView New( unsigned int initialRows, unsigned int initialColumns );
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
156 static TableView DownCast( BaseHandle handle );
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
166 bool AddChild( Actor child, CellPosition position );
169 * Returns a child from the given layout position
170 * Note! if there is no child in this position this method returns an uninitialized
172 * @param[in] position in the table
173 * @return child that was in the cell or an uninitialized handle
175 Actor GetChildAt( CellPosition position );
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
183 Actor RemoveChildAt( CellPosition position );
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
191 bool FindChildPosition( Actor child, CellPosition& position );
194 * Insert a new row to given index
195 * @param [in] rowIndex of the new row
197 void InsertRow( unsigned int rowIndex );
200 * Delete a row from given index
201 * Removed elements are deleted
202 * @param [in] rowIndex of the row to delete
204 void DeleteRow( unsigned int rowIndex );
207 * Delete a row from given index
208 * @param [in] rowIndex of the row to delete
209 * @param [out] removed elements
211 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
214 * Insert a new column to given index
215 * @param [in] columnIndex of the new column
217 void InsertColumn( unsigned int columnIndex );
220 * Delete a column from given index.
221 * Removed elements are deleted
222 * @param [in] columnIndex of the column to delete
224 void DeleteColumn( unsigned int columnIndex );
227 * Delete a column from given index
228 * @param [in] columnIndex of the column to delete
229 * @param [out] removed elements
231 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
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
241 void Resize( unsigned int rows, unsigned int columns );
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
251 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
254 * Set horizontal and vertical padding between cells
255 * @param[in] padding width and height
257 void SetCellPadding( Size padding );
260 * @return the current padding as width and height
262 Size GetCellPadding();
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
271 void SetFixedHeight( unsigned int rowIndex, float height );
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.
279 float GetFixedHeight( unsigned int rowIndex ) const;
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
289 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
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.
297 float GetRelativeHeight( unsigned int rowIndex ) const;
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
306 void SetFixedWidth( unsigned int columnIndex, float width );
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.
314 float GetFixedWidth( unsigned int columnIndex ) const;
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
324 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
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.
332 float GetRelativeWidth( unsigned int columnIndex ) const;
335 * @return the amount of rows in the table
337 unsigned int GetRows();
340 * @return the amount of columns in the table
342 unsigned int GetColumns();
344 public: // Not intended for application developers
347 * Creates a handle using the Toolkit::Internal implementation.
348 * @param[in] implementation The Control implementation.
350 DALI_INTERNAL TableView(Internal::TableView& implementation);
353 * Allows the creation of this Control from an Internal::CustomActor pointer.
354 * @param[in] internal A pointer to the internal CustomActor.
356 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
359 } // namespace Toolkit
363 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__