1d9ad5d2cde4b4ce4a1ebd92ad3a8f5add926f89
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-group.h
1 #ifndef DALI_TOOLKIT_LAYOUTING_LAYOUT_GROUP_H
2 #define DALI_TOOLKIT_LAYOUTING_LAYOUT_GROUP_H
3 /*
4  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <memory>
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/actors/actor-enumerations.h>
22 #include <dali-toolkit/devel-api/toolkit-property-index-ranges.h>
23 #include <dali-toolkit/devel-api/layouting/layout-item.h>
24 #include <dali-toolkit/devel-api/layouting/measure-spec.h>
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33 class LayoutGroup;
34 }
35
36
37 /**
38  * A layout that has layout children. Implements LayoutItem.
39  * It can both layout it's children, and be laid out by a parent container.
40  *
41  * A layout group automatically handles adding a Control container's children to itself,
42  * both on startup and on child add/remove. If this functionality is not desired, this needs
43  * splitting into two classes; one that manages just the layout part, and the other which
44  * handles Actor hierarchy. (@todo Consider doing this anyway...)
45  *
46  * This handle class allows the application to set up layout properties for the layout group;
47  * it doesn't access measure/layout directly.
48  *
49  * To write a new layout, inherit from both LayoutGroup handle and Internal::LayoutGroup body.
50  *
51  */
52 class DALI_TOOLKIT_API LayoutGroup : public LayoutItem
53 {
54 public:
55   using LayoutId = unsigned int;
56   static const unsigned int UNKNOWN_ID = 0;
57
58   struct ChildProperty
59   {
60     enum
61     {
62     };
63   };
64
65
66   /**
67    * @brief Creates an uninitialized LayoutGroup handle.
68    *
69    * LayoutGroup is intended as a base class, and as such, does not have a New method.
70    *
71    * Calling member functions with an uninitialized handle is not allowed.
72    */
73   LayoutGroup();
74
75   /**
76    * @brief Default Destructor.
77    *
78    * This is non-virtual since derived Handle types must not contain data or virtual methods.
79    */
80   ~LayoutGroup() = default;
81
82   /**
83    * @brief Copy constructor
84    */
85   LayoutGroup(const LayoutGroup& copy) = default;
86
87   /**
88    * @brief Assigment operator
89    */
90   LayoutGroup& operator=(const LayoutGroup& rhs) = default;
91
92   /**
93    * @brief Downcasts a handle to a LayoutGroup handle.
94    *
95    * If handle points to a LayoutGroup, the downcast produces a valid handle.
96    * If not, the returned handle is left uninitialized.
97
98    * @param[in] handle to an object
99    * @return Handle to a LayoutGroup or an uninitialized handle
100    */
101   static LayoutGroup DownCast( BaseHandle handle );
102
103   /**
104    * @brief Add a child layout to the layout group
105    *
106    * @param[in] childLayout The layout to add.
107    * @return an Id of the child.
108    */
109   LayoutId Add( LayoutItem& childLayout );
110
111   /**
112    * @brief Add a child layout to the layout group
113    *
114    * @param[in] childId the id of the child to remove
115    */
116   void Remove( LayoutId childId );
117
118   /**
119    * @brief Remove a child layout from the layout group
120    *
121    * @param[in] childLayout The layout to remove.
122    */
123   void Remove( LayoutItem& childLayout );
124
125   /**
126    * @brief Get the child at the given index.
127    *
128    * @param[in] index The index of the child.
129    */
130   LayoutItem GetChildAt( unsigned int index ) const;
131
132   /**
133    * @brief Get the count of the children of the layout
134    *
135    * @return the count of the children of the layout
136    */
137   unsigned int GetChildCount() const ;
138
139   /**
140    * @brief Get the child referenced by childId.
141    *
142    * @param[in] childId The id of the child to get
143    * @return A handle to the child layout, or empty if not found
144    */
145   LayoutItem GetChild( LayoutId childId ) const ;
146
147   /**
148    * Delete template method to remove implicit casting to integer types.
149    */
150   template <typename T>
151     LayoutItem GetChild( T childId ) = delete;
152
153 public:
154   /// @cond internal
155   /**
156    * @brief This constructor is used by LayoutGroup::New() methods.
157    *
158    * @param[in] actor A pointer to a newly allocated Dali resource
159    */
160   explicit LayoutGroup( Internal::LayoutGroup* layoutGroup );
161   /// @endcond
162 };
163
164
165 } // namespace Toolkit
166 } // namespace Dali
167
168 #endif // DALI_TOOLKIT_LAYOUTING_LAYOUT_GROUP_H