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 Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
35 * TableView is a custom control for laying out actors in a table layout
36 * @see Dali::Toolkit:TableView for more details
38 class TableView : public ControlImpl
43 * Structure for the layout data
49 Toolkit::TableView::CellPosition position;
53 * Create a new TableView.
54 * @return A smart-pointer to the newly allocated TableView.
56 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
59 * @copydoc Toolkit::TableView::AddChild
61 bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
64 * @copydoc Toolkit::TableView::GetChildAt
66 Actor GetChildAt( Toolkit::TableView::CellPosition position );
69 * @copydoc Toolkit::TableView::RemoveChildAt
71 Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
74 * @copydoc Toolkit::TableView::FindChildPosition
76 bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
79 * @copydoc Toolkit::TableView::InsertRow
81 void InsertRow( unsigned int rowIndex );
84 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
86 void DeleteRow( unsigned int rowIndex );
89 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
91 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
94 * @copydoc Toolkit::TableView::InsertColumn
96 void InsertColumn( unsigned int columnIndex );
99 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
101 void DeleteColumn( unsigned int columnIndex );
104 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
106 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
109 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
111 void Resize( unsigned int rows, unsigned int columns );
114 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
116 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
119 * @copydoc Toolkit::TableView::SetCellPadding
121 void SetCellPadding( Size padding );
124 * @copydoc Toolkit::TableView::GetCellPadding
126 Size GetCellPadding();
129 * @copydoc Toolkit::TableView::SetFixedHeight
131 void SetFixedHeight( unsigned int rowIndex, float height );
134 * @copydoc Toolkit::TableView::GetFixedHeight
136 float GetFixedHeight( unsigned int rowIndex ) const;
139 * @copydoc Toolkit::TableView::SetRelativeHeight
141 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
144 * @copydoc Toolkit::TableView::GetRelativeHeight
146 float GetRelativeHeight( unsigned int rowIndex ) const;
149 * @copydoc Toolkit::TableView::SetFixedWidth
151 void SetFixedWidth( unsigned int columnIndex, float width );
154 * @copydoc Toolkit::TableView::GetFixedWidth
156 float GetFixedWidth( unsigned int columnIndex ) const;
159 * @copydoc Toolkit::TableView::SetRelativeWidth
161 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
164 * @copydoc Toolkit::TableView::GetRelativeWidth
166 float GetRelativeWidth( unsigned int columnIndex ) const;
169 * @copydoc Toolkit::TableView::SetLayoutAnimationDuration
171 void SetLayoutAnimationDuration( float duration );
174 * @copydoc Toolkit::TableView::GetLayoutAnimationDuration
176 float GetLayoutAnimationDuration();
180 * @copydoc Toolkit::TableView::GetRows
182 unsigned int GetRows();
185 * @copydoc Toolkit::TableView::GetColumns
187 unsigned int GetColumns();
189 private: // From ControlImpl
192 * @copydoc Toolkit::ControlImpl::OnControlChildAdd(Actor& child)
194 virtual void OnControlChildAdd(Actor& child);
197 * @copydoc Toolkit::ControlImpl::OnControlChildRemove(Actor& child)
199 virtual void OnControlChildRemove(Actor& child);
202 * @copydoc Toolkit::ControlImpl::OnRelaidOut
204 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
207 * @copydoc Toolkit::ControlImpl::OnInitialize()
209 virtual void OnInitialize();
212 * @copydoc Toolkit::ControlImpl::GetNextKeyboardFocusableActor
214 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
216 private: // Implementation
219 * Construct a new TableView.
221 TableView( unsigned int initialRows, unsigned int initialColumns );
224 * Resizes the data containers to match the new size
225 * @param [in] rows in the table
226 * @param [in] columns in the table
228 void ResizeContainers( unsigned int rows, unsigned int columns );
231 * Resizes the data containers to match the new size
232 * @param [in] rows in the table
233 * @param [in] columns in the table
234 * @param [out] removed celldata
236 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
239 * Helper to get the list of lost actors in the case when table looses cells.
240 * Also handles the case when actors span multiple cells
242 * @param removed actors
243 * @param rowsRemoved from table
244 * @param columnsRemoved from table
246 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
247 unsigned int rowsRemoved, unsigned int columnsRemoved );
250 * Helper to remove all instances of the actor
251 * @param child actor to remove
252 * @return true if the actor was found
254 bool RemoveAllInstances( Actor child );
257 * Helper to update relative sizes
258 * @param fixedHeightsTotal sum of the fixed height rows
259 * @param fixedWidthsTotal sum of the fixed width columns
261 void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
264 * A reference counted object may only be deleted by calling Unreference()
266 virtual ~TableView();
269 * Helper class to prevent child adds and removes from causing relayout
270 * when we're already anyways going to do one in the end
272 class RelayoutingLock
277 * Constructor, sets the lock boolean
279 RelayoutingLock( TableView& parent )
280 : mLock( parent.mLayoutingChild )
286 * Destructor, releases lock boolean
291 // Note, we could also call Relayout here. This would save one line of code
292 // from each method that uses this lock but destructors are not meant to do
293 // big processing so better to not do it here. This destructor would also
294 // be called in case of an exception and we don't definitely want to do Relayout
304 // Undefined copy constructor and assignment operators
305 TableView(const TableView&);
306 TableView& operator=(const TableView& rhs);
310 Array2d<CellData> mCellData;
311 Array2d<Size> mRelativeSizes;
312 std::vector<float> mFixedHeights;
313 std::vector<float> mRelativeHeights;
314 std::vector<float> mFixedWidths;
315 std::vector<float> mRelativeWidths;
317 bool mLayoutingChild;
318 float mConstraintDuration;
322 } // namespace Internal
324 // Helpers for public-api forwarding methods
326 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
328 DALI_ASSERT_ALWAYS(tableView);
330 Dali::RefObject& handle = tableView.GetImplementation();
332 return static_cast<Toolkit::Internal::TableView&>(handle);
335 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
337 DALI_ASSERT_ALWAYS(tableView);
339 const Dali::RefObject& handle = tableView.GetImplementation();
341 return static_cast<const Toolkit::Internal::TableView&>(handle);
344 } // namespace Toolkit
348 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__