7fb7be298d1c8c12ca6197b76a658c9054f20cb5
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / custom-layout-impl.h
1 #ifndef TEST_INTERNAL_CUSTOM_LAYOUT_H
2 #define TEST_INTERNAL_CUSTOM_LAYOUT_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
23 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
24
25 // INTERNAL INCLUDES
26 #include "custom-layout.h"
27
28 namespace Test
29 {
30
31 namespace Internal
32 {
33
34 using Dali::Toolkit::MeasureSpec;
35 using Dali::Toolkit::LayoutLength;
36
37 class CustomLayout;
38 using CustomLayoutPtr = Dali::IntrusivePtr< CustomLayout >;
39
40 /**
41  * @brief The implementation of our custom layout.
42  *
43  * Here we will override the methods that we require to mimic a very simple horizontal layout.
44  */
45 class CustomLayout final : public Dali::Toolkit::Internal::LayoutGroup
46 {
47 public:
48
49   /**
50    * @brief Create a new CustomLayout object.
51    * @return An intrusive pointer to the created CustomLayout object
52    */
53   static CustomLayoutPtr New();
54
55   // Movable but not copyable
56   CustomLayout( const CustomLayout& other ) = delete;
57   CustomLayout& operator=( const CustomLayout& ) = delete;
58   CustomLayout( CustomLayout&& other ) = default;
59   CustomLayout& operator=( CustomLayout&& other ) = default;
60
61   /**
62    * @copydoc CustomLayout::SetCustomBehaviourFlag
63    */
64   void SetCustomBehaviourFlag( int flag );
65
66   /**
67    * @copydoc CustomLayout::GetCustomBehaviourFlags
68    */
69   bool GetCustomBehaviourFlags( int flagToCheck );
70
71   /**
72    * @copydoc CustomLayout::ClearPrivateFlag
73    */
74   void ClearPrivateFlag( int flag );
75
76 private:
77
78   /**
79    * @brief Default Constructor
80    */
81   CustomLayout();
82
83   /**
84    * Virtual Destructor
85    */
86   virtual ~CustomLayout() = default;
87
88   /**
89    * @copydoc LayoutItem::OnMeasure
90    *
91    * Overriding this method so that we can calculate the size we require using our children's sizes
92    */
93   virtual void OnMeasure( MeasureSpec widthMeasureSpec, Dali::Toolkit::MeasureSpec heightMeasureSpec ) override;
94
95   /**
96    * @copydoc LayoutItem::OnLayout
97    *
98    * Overriding this method so that we can layout our children as required.
99    */
100   virtual void OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) override;
101
102   /**
103    * Measure children with parent's measure spec unless BehaviourFlag set to use an unconstrained width or height.
104    * @param[in] childLayout child to measure
105    * @param[in] widthMeasureSpec default layout width measure spec
106    * @param[in] heightMeasureSpec default layout height measure spec
107    * @param[out] resultingWidth resulting width of layout after children are measured
108    * @param[out] resultingHeight resulting height of layout after children are measured
109    */
110   void MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, int resultingWidth, int resultingHeight );
111
112   private:
113
114   int mBehaviourFlags; // flags to alter behaviour of this custom layout
115
116 };
117
118 } // namespace Internal
119
120 inline Internal::CustomLayout& GetImplementation( Test::CustomLayout& handle )
121 {
122   DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
123   Dali::BaseObject& object = handle.GetBaseObject();
124   return static_cast<Internal::CustomLayout&>( object );
125 }
126
127 inline const Internal::CustomLayout& GetImplementation( const Test::CustomLayout& handle )
128 {
129   DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
130   const Dali::BaseObject& object = handle.GetBaseObject();
131   return static_cast<const Internal::CustomLayout&>( object );
132 }
133
134 } // namespace Test
135
136 #endif // TEST_INTERNAL_CUSTOM_LAYOUT_H