2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali-toolkit/dali-toolkit.h>
18 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
19 #include <dali-toolkit/internal/layouting/layout-controller-debug.h>
20 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
29 #if defined( DEBUG_ENABLED )
30 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT_TREE" );
33 void GetLayoutMeasureStateString( std::ostringstream& oss, LayoutItemPtr layout )
37 auto widthSizeAndState = layout->GetMeasuredWidthAndState();
38 auto heightSizeAndState = layout->GetMeasuredHeightAndState();
40 oss << "LayoutMeasureState:" <<
41 " w:" << widthSizeAndState.GetSize() << (widthSizeAndState.GetState()==MeasuredSize::MEASURED_SIZE_TOO_SMALL?"/TooSmall":"") <<
42 " h:" << heightSizeAndState.GetSize() << (heightSizeAndState.GetState()==MeasuredSize::MEASURED_SIZE_TOO_SMALL?"/TooSmall":"");
46 void LayoutDebugMeasureStateRecurseLayout( LayoutItemPtr layout, int depth );
48 void LayoutDebugMeasureStateRecurseActor( Actor root, int depth )
50 std::ostringstream oss;
51 for(int i=0;i<depth;++i) { oss << " "; };
52 oss << "Actor " << root.GetId() << ":" << root.GetName() << " ";
54 bool descendActor = true;
55 Toolkit::Control control = Toolkit::Control::DownCast( root );
58 Internal::Control& controlImpl = GetImplementation( control );
59 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
60 LayoutItemPtr layout = controlDataImpl.GetLayout();
62 if( layout != nullptr )
64 GetLayoutMeasureStateString( oss, layout );
66 DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
68 auto layoutGroup = LayoutGroupPtr( dynamic_cast< LayoutGroup* >( layout.Get() ) );
71 for( unsigned int i=0; i<layoutGroup->GetChildCount(); ++i )
73 auto layoutChild = layoutGroup->GetChildAt( i );
74 LayoutDebugMeasureStateRecurseLayout( layoutChild, depth+1 );
81 if( descendActor == true )
84 DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
86 // Depth first descent through actor children
87 for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
89 Actor child = root.GetChildAt( i );
90 LayoutDebugMeasureStateRecurseActor( child, depth+1 );
95 void LayoutDebugMeasureStateRecurseLayout( LayoutItemPtr layout, int depth )
97 std::ostringstream oss;
98 for(int i=0;i<depth;++i) { oss << " "; }; // indent
100 Actor actor = Actor::DownCast( layout->GetOwner() );
103 oss << "Actor " << actor.GetId() << ":" << actor.GetName() << " ";
107 oss << "Owner: " << layout->GetOwner().GetObjectPtr() << " ";
110 GetLayoutMeasureStateString( oss, layout );
112 DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
114 auto layoutGroup = LayoutGroupPtr( dynamic_cast< LayoutGroup* >( layout.Get() ) );
117 for( unsigned int i=0; i<layoutGroup->GetChildCount(); ++i )
119 auto layoutChild = layoutGroup->GetChildAt( i );
120 LayoutDebugMeasureStateRecurseLayout( layoutChild, depth+1 );
125 for( unsigned int i = 0, count = actor.GetChildCount(); i < count; ++i )
127 LayoutDebugMeasureStateRecurseActor( actor.GetChildAt( i ), depth + 1 );
133 void LayoutDebugMeasureState( Actor root )
135 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Layout tree after measure:\n\n" );
136 LayoutDebugMeasureStateRecurseActor( root, 0 );
140 void LayoutDebugAfterLayoutRecurse( Actor root, int depth )
142 std::ostringstream oss;
143 for(int i=0;i<depth;++i) { oss << " "; };
144 oss << "Actor " << root.GetId() << ":" << root.GetName() << " ";
145 Toolkit::Control control = Toolkit::Control::DownCast( root );
148 Internal::Control& controlImpl = GetImplementation( control );
149 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
150 LayoutItemPtr layout = controlDataImpl.GetLayout();
154 auto childOwner = layout->GetOwner();
155 auto widthMeasureSpec = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
156 auto heightMeasureSpec = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
158 oss << "LayoutData:" << "( " << widthMeasureSpec << ", " << heightMeasureSpec << ") ";
160 auto actorPos = root.GetProperty<Vector3>( Actor::Property::POSITION );
161 auto actorSize = root.GetProperty<Vector3>( Actor::Property::SIZE );
162 oss << " ActorPos: (" << actorPos.x << ", " << actorPos.y << ")";
163 oss << " ActorSize: (" << actorSize.width << ", " << actorSize.height << ")";
167 // Try getting layout data from parent control
172 DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
174 // Depth first descent through actor children
175 for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
177 Actor child = root.GetChildAt( i );
178 LayoutDebugAfterLayoutRecurse( child, depth+1 );
182 void LayoutDebugAfterLayout( Actor root )
184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Layout tree after layout:\n\n" );
185 LayoutDebugAfterLayoutRecurse( root, 0 );
191 } // namespace Internal
192 } // namespace Toolkit