b2dcb9948dfaee12f28aceef35851a18616b0735
[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
24 // INTERNAL INCLUDES
25 #include "custom-layout.h"
26
27 namespace Test
28 {
29
30 namespace Internal
31 {
32
33 using Dali::Toolkit::MeasureSpec;
34 using Dali::Toolkit::LayoutLength;
35
36 class CustomLayout;
37 using CustomLayoutPtr = Dali::IntrusivePtr< CustomLayout >;
38
39 /**
40  * @brief The implementation of our custom layout.
41  *
42  * Here we will override the methods that we require to mimic a very simple horizontal layout.
43  */
44 class CustomLayout final : public Dali::Toolkit::Internal::LayoutGroup
45 {
46 public:
47
48   /**
49    * @brief Create a new CustomLayout object.
50    * @return An intrusive pointer to the created CustomLayout object
51    */
52   static CustomLayoutPtr New();
53
54   // Movable but not copyable
55   CustomLayout( const CustomLayout& other ) = delete;
56   CustomLayout& operator=( const CustomLayout& ) = delete;
57   CustomLayout( CustomLayout&& other ) = default;
58   CustomLayout& operator=( CustomLayout&& other ) = default;
59
60 private:
61
62   /**
63    * @brief Default Constructor
64    */
65   CustomLayout() = default;
66
67   /**
68    * Virtual Destructor
69    */
70   virtual ~CustomLayout() = default;
71
72   /**
73    * @copydoc LayoutItem::OnMeasure
74    *
75    * Overriding this method so that we can calculate the size we require using our children's sizes
76    */
77   virtual void OnMeasure( MeasureSpec widthMeasureSpec, Dali::Toolkit::MeasureSpec heightMeasureSpec ) override;
78
79   /**
80    * @copydoc LayoutItem::OnLayout
81    *
82    * Overriding this method so that we can layout our children as required.
83    */
84   virtual void OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) override;
85
86 };
87
88 } // namespace Internal
89
90 inline Internal::CustomLayout& GetImplementation( Test::CustomLayout& handle )
91 {
92   DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
93   Dali::BaseObject& object = handle.GetBaseObject();
94   return static_cast<Internal::CustomLayout&>( object );
95 }
96
97 inline const Internal::CustomLayout& GetImplementation( const Test::CustomLayout& handle )
98 {
99   DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
100   const Dali::BaseObject& object = handle.GetBaseObject();
101   return static_cast<const Internal::CustomLayout&>( object );
102 }
103
104 } // namespace Test
105
106 #endif // TEST_INTERNAL_CUSTOM_LAYOUT_H