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>
23 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali-toolkit/public-api/controls/control.h>
34 namespace Internal DALI_INTERNAL
40 * TableView is a layout container for aligning child actors in a grid like layout.
41 * TableView constrains the x and y position and width and height of the child actors.
42 * z position and depth are left intact so that 3D model actors can also be laid out
43 * in a grid without loosing their depth scaling.
45 class DALI_IMPORT_API TableView : public Control
50 * @brief The start and end property ranges for this control.
54 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
55 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices
59 * @brief An enumeration of properties belonging to the TableView class.
61 * LayoutRows: set the height of the rows.
62 * It has the format as follows in script:
66 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
67 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight
71 * LayoutColumns: set the height of the rows.
72 * It has the format as follows in script:
76 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
77 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
85 ROWS = PROPERTY_START_INDEX, ///< name "rows", type unsigned int
86 COLUMNS, ///< name "columns", type unsigned int
87 CELL_PADDING, ///< name "cell-padding", type Vector2
88 LAYOUT_ROWS, ///< name "layout-rows", type Map
89 LAYOUT_COLUMNS, ///< name "layout-columns", type Map
93 // Custom properties for where to put the actor, these properties should be registered to the child which would be added to the table
94 static const std::string CELL_INDICES_PROPERTY_NAME; ///< Property, name "cell-indices", type Vector2
95 static const std::string ROW_SPAN_PROPERTY_NAME; ///< Property, name "row-span", type float (Currently builder is unable to differentiate integer and float from Json string)
96 static const std::string COLUMN_SPAN_PROPERTY_NAME; ///< Property, name "column-span", type float (Currently builder is unable to differentiate integer and float from Json string)
99 * @brief Describes how the size of a row / column been set
103 FIXED, ///< Fixed with the given value.
104 RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width
105 FILL ///< Get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns
109 * Structure to specify layout position for child actor
114 * Constructor to initialise values to defaults for convenience
116 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
117 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
118 : rowIndex( rowIndex ), columnIndex( columnIndex ),
119 rowSpan( rowSpan ), columnSpan( columnSpan )
122 unsigned int rowIndex;
123 unsigned int columnIndex;
124 unsigned int rowSpan;
125 unsigned int columnSpan;
129 * Create a TableView handle; this can be initialised with TableView::New()
130 * Calling member functions with an uninitialised handle is not allowed.
135 * Copy constructor. Creates another handle that points to the same real object
136 * @param handle to copy from
138 TableView( const TableView& handle );
141 * Assignment operator. Changes this handle to point to another real object
143 TableView& operator=( const TableView& handle );
148 * This is non-virtual since derived Handle types must not contain data or virtual methods.
153 * Create the TableView control.
154 * @param[in] initialRows for the table
155 * @param[in] initialColumns for the table
156 * @return A handle to the TableView control.
158 static TableView New( unsigned int initialRows, unsigned int initialColumns );
161 * Downcast an Object handle to TableView. If handle points to a TableView the
162 * downcast produces valid handle. If not the returned handle is left uninitialized.
163 * @param[in] handle Handle to an object
164 * @return handle to a TableView or an uninitialized handle
166 static TableView DownCast( BaseHandle handle );
169 * Adds a child to the table
170 * If the row or column index is outside the table, the table gets resized bigger
171 * @pre The child actor has been initialized.
172 * @param[in] child to add
173 * @param[in] position for the child
174 * @return true if the addition succeeded, false if the cell is already occupied
176 bool AddChild( Actor child, CellPosition position );
179 * Returns a child from the given layout position
180 * Note! if there is no child in this position this method returns an uninitialized
182 * @param[in] position in the table
183 * @return child that was in the cell or an uninitialized handle
185 Actor GetChildAt( CellPosition position );
188 * Removes a child from the given layout position
189 * Note! if there is no child in this position this method does nothing
190 * @param[in] position for the child to remove
191 * @return child that was removed or an uninitialized handle
193 Actor RemoveChildAt( CellPosition position );
196 * Finds the childs layout position
197 * @param[in] child to search for
198 * @param[out] position for the child
199 * @return true if the child was included in this TableView
201 bool FindChildPosition( Actor child, CellPosition& position );
204 * Insert a new row to given index
205 * @param [in] rowIndex of the new row
207 void InsertRow( unsigned int rowIndex );
210 * Delete a row from given index
211 * Removed elements are deleted
212 * @param [in] rowIndex of the row to delete
214 void DeleteRow( unsigned int rowIndex );
217 * Delete a row from given index
218 * @param [in] rowIndex of the row to delete
219 * @param [out] removed elements
221 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
224 * Insert a new column to given index
225 * @param [in] columnIndex of the new column
227 void InsertColumn( unsigned int columnIndex );
230 * Delete a column from given index.
231 * Removed elements are deleted
232 * @param [in] columnIndex of the column to delete
234 void DeleteColumn( unsigned int columnIndex );
237 * Delete a column from given index
238 * @param [in] columnIndex of the column to delete
239 * @param [out] removed elements
241 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
244 * Resize the TableView. Note! if the new size is smaller than old,
245 * superfluous actors get removed. If you want to relayout removed children,
246 * use the variant that returns the removed Actors and reinsert them into the table
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
251 void Resize( unsigned int rows, unsigned int columns );
254 * Resize the TableView. Note! if the new size is smaller than old,
255 * superfluous actors get removed.
256 * If an actor spans to a removed row or column it gets removed from the table
257 * @param[in] rows for the table
258 * @param[in] columns for the table
259 * @param[out] removed actor handles
261 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
264 * Set horizontal and vertical padding between cells
265 * @param[in] padding width and height
267 void SetCellPadding( Size padding );
270 * @return the current padding as width and height
272 Size GetCellPadding();
275 * @brief Specify this row as fitting its height to its children
277 * @param[in] rowIndex The row to set
279 void SetFitHeight( unsigned int rowIndex );
282 * @brief Is the row a fit row
284 * @param[in] rowIndex The row to check
285 * @return Return true if the row is fit
287 bool IsFitHeight( unsigned int rowIndex ) const;
290 * @brief Specify this column as fitting its width to its children
292 * @param[in] columnIndex The column to set
294 void SetFitWidth( unsigned int columnIndex );
297 * @brief Is the column a fit column
299 * @param[in] columnIndex The column to check
300 * @return Return true if the column is fit
302 bool IsFitWidth( unsigned int columnIndex ) const;
305 * Sets a row to have fixed height
306 * Setting a fixed height of 0 has no effect
307 * @pre The row rowIndex must exist.
308 * @param rowIndex for row with fixed height
309 * @param height in world coordinate units
311 void SetFixedHeight( unsigned int rowIndex, float height );
314 * Gets a row's fixed height.
315 * Note! The returned value is valid if it has been set before.
316 * @pre The row rowIndex must exist.
317 * @return height in world coordinate units.
319 float GetFixedHeight( unsigned int rowIndex ) const;
322 * Sets a row to have relative height. Relative height means percentage of
323 * the remainder of the table height after subtracting Padding and Fixed height rows
324 * Setting a relative height of 0 has no effect
325 * @pre The row rowIndex must exist.
326 * @param rowIndex for row with relative height
327 * @param heightPercentage between 0.0f and 1.0f
329 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
332 * Gets a row's relative height.
333 * Note! The returned value is valid if it has been set before.
334 * @pre The row rowIndex must exist.
335 * @return height in percentage units, between 0.0f and 1.0f.
337 float GetRelativeHeight( unsigned int rowIndex ) const;
340 * Sets a column to have fixed width
341 * Setting a fixed width of 0 has no effect
342 * @pre The column columnIndex must exist.
343 * @param columnIndex for column with fixed width
344 * @param width in world coordinate units
346 void SetFixedWidth( unsigned int columnIndex, float width );
349 * Gets a column's fixed width.
350 * Note! The returned value is valid if it has been set before.
351 * @pre The column columnIndex must exist.
352 * @return width in world coordinate units.
354 float GetFixedWidth( unsigned int columnIndex ) const;
357 * Sets a column to have relative width. Relative width means percentage of
358 * the remainder of table width after subtracting Padding and Fixed width columns
359 * Setting a relative width of 0 has no effect
360 * @pre The column columnIndex must exist.
361 * @param columnIndex for column with fixed width
362 * @param widthPercentage between 0.0f and 1.0f
364 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
367 * Gets a column's relative width.
368 * Note! The returned value is valid if it has been set before.
369 * @pre The column columnIndex must exist.
370 * @return width in percentage units, between 0.0f and 1.0f.
372 float GetRelativeWidth( unsigned int columnIndex ) const;
375 * @return the amount of rows in the table
377 unsigned int GetRows();
380 * @return the amount of columns in the table
382 unsigned int GetColumns();
385 * @brief Set the alignment on a cell
387 * @param[in] position The cell to set alignment on
388 * @param[in] horizontal The horizontal alignment
389 * @param[in] vertical The vertical alignment
391 void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
393 public: // Not intended for application developers
396 * Creates a handle using the Toolkit::Internal implementation.
397 * @param[in] implementation The Control implementation.
399 DALI_INTERNAL TableView(Internal::TableView& implementation);
402 * Allows the creation of this Control from an Internal::CustomActor pointer.
403 * @param[in] internal A pointer to the internal CustomActor.
405 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
408 } // namespace Toolkit
412 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__