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
47 * Structure to specify layout position for child actor
52 * Constructor to initialise values to defaults for convenience
54 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
55 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
56 : rowIndex( rowIndex ), columnIndex( columnIndex ),
57 rowSpan( rowSpan ), columnSpan( columnSpan )
60 unsigned int rowIndex;
61 unsigned int columnIndex;
63 unsigned int columnSpan;
67 * Create a TableView handle; this can be initialised with TableView::New()
68 * Calling member functions with an uninitialised handle is not allowed.
73 * Copy constructor. Creates another handle that points to the same real object
74 * @param handle to copy from
76 TableView( const TableView& handle );
79 * Assignment operator. Changes this handle to point to another real object
81 TableView& operator=( const TableView& handle );
85 * Dali::Object derived classes typically do not contain member data.
90 * Create the TableView control.
91 * @param[in] initialRows for the table
92 * @param[in] initialColumns for the table
93 * @return A handle to the TableView control.
95 static TableView New( unsigned int initialRows, unsigned int initialColumns );
98 * Downcast an Object handle to TableView. If handle points to a TableView the
99 * downcast produces valid handle. If not the returned handle is left uninitialized.
100 * @param[in] handle Handle to an object
101 * @return handle to a TableView or an uninitialized handle
103 static TableView DownCast( BaseHandle handle );
106 * Adds a child to the table
107 * If the row or column index is outside the table, the table gets resized bigger
108 * @pre The child actor has been initialized.
109 * @param[in] child to add
110 * @param[in] position for the child
111 * @return true if the addition succeeded, false if the cell is already occupied
113 bool AddChild( Actor child, CellPosition position );
116 * Returns a child from the given layout position
117 * Note! if there is no child in this position this method returns an uninitialized
119 * @param[in] position in the table
120 * @return child that was in the cell or an uninitialized handle
122 Actor GetChildAt( CellPosition position );
125 * Removes a child from the given layout position
126 * Note! if there is no child in this position this method does nothing
127 * @param[in] position for the child to remove
128 * @return child that was removed or an uninitialized handle
130 Actor RemoveChildAt( CellPosition position );
133 * Finds the childs layout position
134 * @param[in] child to search for
135 * @param[out] position for the child
136 * @return true if the child was included in this TableView
138 bool FindChildPosition( Actor child, CellPosition& position );
141 * Insert a new row to given index
142 * @param [in] rowIndex of the new row
144 void InsertRow( unsigned int rowIndex );
147 * Delete a row from given index
148 * Removed elements are deleted
149 * @param [in] rowIndex of the row to delete
151 void DeleteRow( unsigned int rowIndex );
154 * Delete a row from given index
155 * @param [in] rowIndex of the row to delete
156 * @param [out] removed elements
158 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
161 * Insert a new column to given index
162 * @param [in] columnIndex of the new column
164 void InsertColumn( unsigned int columnIndex );
167 * Delete a column from given index.
168 * Removed elements are deleted
169 * @param [in] columnIndex of the column to delete
171 void DeleteColumn( unsigned int columnIndex );
174 * Delete a column from given index
175 * @param [in] columnIndex of the column to delete
176 * @param [out] removed elements
178 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
181 * Resize the TableView. Note! if the new size is smaller than old,
182 * superfluous actors get removed. If you want to relayout removed children,
183 * use the variant that returns the removed Actors and reinsert them into the table
184 * If an actor spans to a removed row or column it gets removed from the table
185 * @param[in] rows for the table
186 * @param[in] columns for the table
188 void Resize( unsigned int rows, unsigned int columns );
191 * Resize the TableView. Note! if the new size is smaller than old,
192 * superfluous actors get removed.
193 * If an actor spans to a removed row or column it gets removed from the table
194 * @param[in] rows for the table
195 * @param[in] columns for the table
196 * @param[out] removed actor handles
198 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
201 * Set horizontal and vertical padding between cells
202 * @param[in] padding width and height
204 void SetCellPadding( Size padding );
207 * @return the current padding as width and height
209 Size GetCellPadding();
212 * Sets a row to have fixed height
213 * Setting a fixed height of 0 has no effect
214 * @pre The row rowIndex must exist.
215 * @param rowIndex for row with fixed height
216 * @param height in world coordinate units
218 void SetFixedHeight( unsigned int rowIndex, float height );
221 * Gets a row's fixed height.
222 * Note! The returned value is valid if it has been set before.
223 * @pre The row rowIndex must exist.
224 * @return height in world coordinate units.
226 float GetFixedHeight( unsigned int rowIndex ) const;
229 * Sets a row to have relative height. Relative height means percentage of
230 * the remainder of the table height after subtracting Padding and Fixed height rows
231 * Setting a relative height of 0 has no effect
232 * @pre The row rowIndex must exist.
233 * @param rowIndex for row with relative height
234 * @param heightPercentage between 0.0f and 1.0f
236 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
239 * Gets a row's relative height.
240 * Note! The returned value is valid if it has been set before.
241 * @pre The row rowIndex must exist.
242 * @return height in percentage units, between 0.0f and 1.0f.
244 float GetRelativeHeight( unsigned int rowIndex ) const;
247 * Sets a column to have fixed width
248 * Setting a fixed width of 0 has no effect
249 * @pre The column columnIndex must exist.
250 * @param columnIndex for column with fixed width
251 * @param width in world coordinate units
253 void SetFixedWidth( unsigned int columnIndex, float width );
256 * Gets a column's fixed width.
257 * Note! The returned value is valid if it has been set before.
258 * @pre The column columnIndex must exist.
259 * @return width in world coordinate units.
261 float GetFixedWidth( unsigned int columnIndex ) const;
264 * Sets a column to have relative width. Relative width means percentage of
265 * the remainder of table width after subtracting Padding and Fixed width columns
266 * Setting a relative width of 0 has no effect
267 * @pre The column columnIndex must exist.
268 * @param columnIndex for column with fixed width
269 * @param widthPercentage between 0.0f and 1.0f
271 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
274 * Gets a column's relative width.
275 * Note! The returned value is valid if it has been set before.
276 * @pre The column columnIndex must exist.
277 * @return width in percentage units, between 0.0f and 1.0f.
279 float GetRelativeWidth( unsigned int columnIndex ) const;
282 * Sets the layout animation duration for add, remove and relayout
283 * @param duration for the layout animations
284 * @note The default duration is 0.0f.
286 void SetLayoutAnimationDuration( float duration );
289 * Gets the layout animation duration for add, remove and relayout
290 * @return duration for the layout animations
292 float GetLayoutAnimationDuration();
295 * @return the amount of rows in the table
297 unsigned int GetRows();
300 * @return the amount of columns in the table
302 unsigned int GetColumns();
304 public: // Not intended for application developers
307 * Creates a handle using the Toolkit::Internal implementation.
308 * @param[in] implementation The Control implementation.
310 TableView(Internal::TableView& implementation);
313 * Allows the creation of this Control from an Internal::CustomActor pointer.
314 * @param[in] internal A pointer to the internal CustomActor.
316 TableView( Dali::Internal::CustomActor* internal );
319 } // namespace Toolkit
323 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__