[dali_1.4.16] Merge branch 'devel/master'
[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) 2019 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/actors/actor-enumerations.h>
21 #include <dali-toolkit/devel-api/toolkit-property-index-ranges.h>
22 #include <dali-toolkit/devel-api/layouting/layout-item.h>
23 #include <dali-toolkit/devel-api/layouting/measure-spec.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32 class LayoutGroup;
33 }
34
35
36 /**
37  * A layout that has layout children. Implements LayoutItem.
38  * It can both layout it's children, and be laid out by a parent container.
39  *
40  * A layout group automatically handles adding a Control container's children to itself,
41  * both on startup and on child add/remove. If this functionality is not desired, this needs
42  * splitting into two classes; one that manages just the layout part, and the other which
43  * handles Actor hierarchy. (@todo Consider doing this anyway...)
44  *
45  * This handle class allows the application to set up layout properties for the layout group;
46  * it doesn't access measure/layout directly.
47  *
48  * To write a new layout, inherit from both LayoutGroup handle and Internal::LayoutGroup body.
49  *
50  */
51 class DALI_TOOLKIT_API LayoutGroup : public LayoutItem
52 {
53 public:
54   using LayoutId = unsigned int;
55   static const unsigned int UNKNOWN_ID = 0;
56
57   /**
58    * @brief Creates an uninitialized LayoutGroup handle.
59    *
60    * LayoutGroup is intended as a base class, and as such, does not have a New method.
61    *
62    * Calling member functions with an uninitialized handle is not allowed.
63    */
64   LayoutGroup();
65
66   /**
67    * @brief Default Destructor.
68    *
69    * This is non-virtual since derived Handle types must not contain data or virtual methods.
70    */
71   ~LayoutGroup() = default;
72
73   /**
74    * @brief Create an initialized LayoutGroup
75    *
76    * @param[in] handle A handle to the object that this layout for, e.g. a Control or a Visual::Base
77    */
78   static LayoutGroup New( Handle& handle );
79
80   /**
81    * @brief Copy constructor
82    */
83   LayoutGroup(const LayoutGroup& copy) = default;
84
85   /**
86    * @brief Assigment operator
87    */
88   LayoutGroup& operator=(const LayoutGroup& rhs) = default;
89
90   /**
91    * @brief Downcasts a handle to a LayoutGroup handle.
92    *
93    * If handle points to a LayoutGroup, the downcast produces a valid handle.
94    * If not, the returned handle is left uninitialized.
95
96    * @param[in] handle to an object
97    * @return Handle to a LayoutGroup or an uninitialized handle
98    */
99   static LayoutGroup DownCast( BaseHandle handle );
100
101   /**
102    * @brief Add a child layout to the layout group
103    *
104    * @param[in] childLayout The layout to add.
105    * @return an Id of the child.
106    */
107   LayoutId Add( LayoutItem& childLayout );
108
109   /**
110    * @brief Add a child layout to the layout group
111    *
112    * @param[in] childId the id of the child to remove
113    */
114   void Remove( LayoutId childId );
115
116   /**
117    * @brief Remove a child layout from the layout group
118    *
119    * @param[in] childLayout The layout to remove.
120    */
121   void Remove( LayoutItem& childLayout );
122
123   /**
124    * @brief Get the child at the given index.
125    *
126    * @param[in] index The index of the child.
127    */
128   LayoutItem GetChildAt( unsigned int index ) const;
129
130   /**
131    * @brief Get the count of the children of the layout
132    *
133    * @return the count of the children of the layout
134    */
135   unsigned int GetChildCount() const ;
136
137   /**
138    * @brief Get the child referenced by childId.
139    *
140    * @param[in] childId The id of the child to get
141    * @return A handle to the child layout, or empty if not found
142    */
143   LayoutItem GetChild( LayoutId childId ) const ;
144
145   /**
146    * Delete template method to remove implicit casting to integer types.
147    */
148   template <typename T>
149     LayoutItem GetChild( T childId ) = delete;
150
151 public:
152   /// @cond internal
153   /**
154    * @brief This constructor is used by LayoutGroup::New() methods.
155    *
156    * @param[in] actor A pointer to a newly allocated Dali resource
157    */
158   explicit LayoutGroup( Internal::LayoutGroup* layoutGroup );
159   /// @endcond
160 };
161
162
163 } // namespace Toolkit
164 } // namespace Dali
165
166 #endif // DALI_TOOLKIT_LAYOUTING_LAYOUT_GROUP_H