1 #ifndef __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_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-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
36 * TableView is a custom control for laying out actors in a table layout
37 * @see Dali::Toolkit:TableView for more details
39 class TableView : public Control
44 * Structure for the layout data
50 Toolkit::TableView::CellPosition position;
54 * Create a new TableView.
55 * @return A smart-pointer to the newly allocated TableView.
57 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
60 * @copydoc Toolkit::TableView::AddChild
62 bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
65 * @copydoc Toolkit::TableView::GetChildAt
67 Actor GetChildAt( Toolkit::TableView::CellPosition position );
70 * @copydoc Toolkit::TableView::RemoveChildAt
72 Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
75 * @copydoc Toolkit::TableView::FindChildPosition
77 bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
80 * @copydoc Toolkit::TableView::InsertRow
82 void InsertRow( unsigned int rowIndex );
85 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
87 void DeleteRow( unsigned int rowIndex );
90 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
92 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
95 * @copydoc Toolkit::TableView::InsertColumn
97 void InsertColumn( unsigned int columnIndex );
100 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
102 void DeleteColumn( unsigned int columnIndex );
105 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
107 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
110 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
112 void Resize( unsigned int rows, unsigned int columns );
115 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
117 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
120 * @copydoc Toolkit::TableView::SetCellPadding
122 void SetCellPadding( Size padding );
125 * @copydoc Toolkit::TableView::GetCellPadding
127 Size GetCellPadding();
130 * @copydoc Toolkit::TableView::SetFixedHeight
132 void SetFixedHeight( unsigned int rowIndex, float height );
135 * @copydoc Toolkit::TableView::GetFixedHeight
137 float GetFixedHeight( unsigned int rowIndex ) const;
140 * @copydoc Toolkit::TableView::SetRelativeHeight
142 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
145 * @copydoc Toolkit::TableView::GetRelativeHeight
147 float GetRelativeHeight( unsigned int rowIndex ) const;
150 * @copydoc Toolkit::TableView::SetFixedWidth
152 void SetFixedWidth( unsigned int columnIndex, float width );
155 * @copydoc Toolkit::TableView::GetFixedWidth
157 float GetFixedWidth( unsigned int columnIndex ) const;
160 * @copydoc Toolkit::TableView::SetRelativeWidth
162 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
165 * @copydoc Toolkit::TableView::GetRelativeWidth
167 float GetRelativeWidth( unsigned int columnIndex ) const;
170 * @copydoc Toolkit::TableView::SetLayoutAnimationDuration
172 void SetLayoutAnimationDuration( float duration );
175 * @copydoc Toolkit::TableView::GetLayoutAnimationDuration
177 float GetLayoutAnimationDuration();
181 * @copydoc Toolkit::TableView::GetRows
183 unsigned int GetRows();
186 * @copydoc Toolkit::TableView::GetColumns
188 unsigned int GetColumns();
190 private: // From Control
193 * @copydoc Control::OnControlChildAdd(Actor& child)
195 virtual void OnControlChildAdd(Actor& child);
198 * @copydoc Control::OnControlChildRemove(Actor& child)
200 virtual void OnControlChildRemove(Actor& child);
203 * @copydoc Control::OnRelaidOut
205 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
208 * @copydoc Control::OnInitialize()
210 virtual void OnInitialize();
213 * @copydoc Control::GetNextKeyboardFocusableActor
215 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
217 private: // Implementation
220 * Construct a new TableView.
222 TableView( unsigned int initialRows, unsigned int initialColumns );
225 * Resizes the data containers to match the new size
226 * @param [in] rows in the table
227 * @param [in] columns in the table
229 void ResizeContainers( unsigned int rows, unsigned int columns );
232 * Resizes the data containers to match the new size
233 * @param [in] rows in the table
234 * @param [in] columns in the table
235 * @param [out] removed celldata
237 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
240 * Helper to get the list of lost actors in the case when table looses cells.
241 * Also handles the case when actors span multiple cells
243 * @param removed actors
244 * @param rowsRemoved from table
245 * @param columnsRemoved from table
247 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
248 unsigned int rowsRemoved, unsigned int columnsRemoved );
251 * Helper to remove all instances of the actor
252 * @param child actor to remove
253 * @return true if the actor was found
255 bool RemoveAllInstances( Actor child );
258 * Helper to update relative sizes
259 * @param fixedHeightsTotal sum of the fixed height rows
260 * @param fixedWidthsTotal sum of the fixed width columns
262 void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
265 * A reference counted object may only be deleted by calling Unreference()
267 virtual ~TableView();
270 * Helper class to prevent child adds and removes from causing relayout
271 * when we're already anyways going to do one in the end
273 class RelayoutingLock
278 * Constructor, sets the lock boolean
280 RelayoutingLock( TableView& parent )
281 : mLock( parent.mLayoutingChild )
287 * Destructor, releases lock boolean
292 // Note, we could also call Relayout here. This would save one line of code
293 // from each method that uses this lock but destructors are not meant to do
294 // big processing so better to not do it here. This destructor would also
295 // be called in case of an exception and we don't definitely want to do Relayout
305 // Undefined copy constructor and assignment operators
306 TableView(const TableView&);
307 TableView& operator=(const TableView& rhs);
311 Array2d<CellData> mCellData;
312 Array2d<Size> mRelativeSizes;
313 std::vector<float> mFixedHeights;
314 std::vector<float> mRelativeHeights;
315 std::vector<float> mFixedWidths;
316 std::vector<float> mRelativeWidths;
318 bool mLayoutingChild;
319 float mConstraintDuration;
323 } // namespace Internal
325 // Helpers for public-api forwarding methods
327 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
329 DALI_ASSERT_ALWAYS(tableView);
331 Dali::RefObject& handle = tableView.GetImplementation();
333 return static_cast<Toolkit::Internal::TableView&>(handle);
336 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
338 DALI_ASSERT_ALWAYS(tableView);
340 const Dali::RefObject& handle = tableView.GetImplementation();
342 return static_cast<const Toolkit::Internal::TableView&>(handle);
345 } // namespace Toolkit
349 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__