1 #ifndef TEST_INTERNAL_CUSTOM_LAYOUT_H
2 #define TEST_INTERNAL_CUSTOM_LAYOUT_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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/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>
26 #include "custom-layout.h"
34 using Dali::Toolkit::MeasureSpec;
35 using Dali::Toolkit::LayoutLength;
38 using CustomLayoutPtr = Dali::IntrusivePtr< CustomLayout >;
41 * @brief The implementation of our custom layout.
43 * Here we will override the methods that we require to mimic a very simple horizontal layout.
45 class CustomLayout final : public Dali::Toolkit::Internal::LayoutGroup
50 * @brief Create a new CustomLayout object.
51 * @return An intrusive pointer to the created CustomLayout object
53 static CustomLayoutPtr New();
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;
62 * @copydoc CustomLayout::SetCustomBehaviourFlag
64 void SetCustomBehaviourFlag( int flag );
67 * @copydoc CustomLayout::GetCustomBehaviourFlags
69 bool GetCustomBehaviourFlags( int flagToCheck );
72 * @copydoc CustomLayout::ClearPrivateFlag
74 void ClearPrivateFlag( int flag );
79 * @brief Default Constructor
86 virtual ~CustomLayout() = default;
89 * @copydoc LayoutItem::OnMeasure
91 * Overriding this method so that we can calculate the size we require using our children's sizes
93 virtual void OnMeasure( MeasureSpec widthMeasureSpec, Dali::Toolkit::MeasureSpec heightMeasureSpec ) override;
96 * @copydoc LayoutItem::OnLayout
98 * Overriding this method so that we can layout our children as required.
100 virtual void OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) override;
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
110 void MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, LayoutLength resultingWidth, LayoutLength resultingHeight );
112 using Dali::Toolkit::Internal::LayoutGroup::MeasureChildren; ///< To tell the compiler that we really do want to overload MeasureChildren in this class & were not trying to override it
116 int mBehaviourFlags; // flags to alter behaviour of this custom layout
120 } // namespace Internal
122 inline Internal::CustomLayout& GetImplementation( Test::CustomLayout& handle )
124 DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
125 Dali::BaseObject& object = handle.GetBaseObject();
126 return static_cast<Internal::CustomLayout&>( object );
129 inline const Internal::CustomLayout& GetImplementation( const Test::CustomLayout& handle )
131 DALI_ASSERT_ALWAYS( handle && "CustomLayout handle is empty" );
132 const Dali::BaseObject& object = handle.GetBaseObject();
133 return static_cast<const Internal::CustomLayout&>( object );
138 #endif // TEST_INTERNAL_CUSTOM_LAYOUT_H