New layouting classes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / layout-controller-debug.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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>
21
22 namespace Dali
23 {
24 namespace Toolkit
25 {
26 namespace Internal
27 {
28
29 #if defined( DEBUG_ENABLED )
30 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Verbose, false, "LOG_LAYOUT_TREE" );
31
32
33 void GetLayoutMeasureStateString( std::ostringstream& oss, LayoutBasePtr layout )
34 {
35   if( layout )
36   {
37     auto widthSizeAndState = layout->GetMeasuredWidthAndState();
38     auto heightSizeAndState = layout->GetMeasuredHeightAndState();
39
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":"");
43   }
44 }
45
46 void LayoutDebugMeasureStateRecurseLayout( LayoutBasePtr layout, int depth );
47
48 void LayoutDebugMeasureStateRecurseActor( Actor root, int depth )
49 {
50   std::ostringstream oss;
51   for(int i=0;i<depth;++i) { oss << "  "; };
52   oss << "Actor " << root.GetId() << ":" << root.GetName() << " ";
53
54   bool descendActor = true;
55   Toolkit::Control control = Toolkit::Control::DownCast( root );
56   if( control )
57   {
58     Internal::Control& controlImpl = GetImplementation( control );
59     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
60     LayoutBasePtr layout = controlDataImpl.GetLayout();
61
62     if( layout != nullptr )
63     {
64       GetLayoutMeasureStateString( oss, layout );
65       oss << std::endl;
66       DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
67
68       auto layoutGroup = LayoutGroupPtr( dynamic_cast< LayoutGroup* >( layout.Get() ) );
69       if( layoutGroup )
70       {
71         for( unsigned int i=0; i<layoutGroup->GetChildCount(); ++i )
72         {
73           auto layoutChild = layoutGroup->GetChildAt( i );
74           LayoutDebugMeasureStateRecurseLayout( layoutChild, depth+1 );
75         }
76       }
77       descendActor = false;
78     }
79   }
80
81   if( descendActor == true )
82   {
83     oss << std::endl;
84     DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
85
86     // Depth first descent through actor children
87     for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
88     {
89       Actor child = root.GetChildAt( i );
90       LayoutDebugMeasureStateRecurseActor( child, depth+1 );
91     }
92   }
93 }
94
95 void LayoutDebugMeasureStateRecurseLayout( LayoutBasePtr layout, int depth )
96 {
97   std::ostringstream oss;
98   for(int i=0;i<depth;++i) { oss << "  "; }; // indent
99
100   Actor actor = Actor::DownCast( layout->GetOwner() );
101   if( actor )
102   {
103     oss << "Actor " << actor.GetId() << ":" << actor.GetName() << " ";
104   }
105   else
106   {
107     oss << "Owner: " << layout->GetOwner().GetObjectPtr() << " ";
108   }
109
110   GetLayoutMeasureStateString( oss, layout );
111   oss << std::endl;
112   DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
113
114   auto layoutGroup = LayoutGroupPtr( dynamic_cast< LayoutGroup* >( layout.Get() ) );
115   if( layoutGroup )
116   {
117     for( unsigned int i=0; i<layoutGroup->GetChildCount(); ++i )
118     {
119       auto layoutChild = layoutGroup->GetChildAt( i );
120       LayoutDebugMeasureStateRecurseLayout( layoutChild, depth+1 );
121     }
122   }
123   else if( actor )
124   {
125     for( unsigned int i = 0, count = actor.GetChildCount(); i < count; ++i )
126     {
127       LayoutDebugMeasureStateRecurseActor( actor.GetChildAt( i ), depth + 1 );
128     }
129   }
130 }
131
132
133 void LayoutDebugMeasureState( Actor root )
134 {
135   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Layout tree after measure:\n\n" );
136   LayoutDebugMeasureStateRecurseActor( root, 0 );
137 }
138
139
140 void LayoutDebugAfterLayoutRecurse( Actor root, int depth )
141 {
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 );
146   if( control )
147   {
148     Internal::Control& controlImpl = GetImplementation( control );
149     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
150     LayoutBasePtr layout = controlDataImpl.GetLayout();
151
152     if( layout )
153     {
154       auto childOwner = layout->GetOwner();
155       auto widthMeasureSpec = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION );
156       auto heightMeasureSpec = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::HEIGHT_SPECIFICATION );
157
158       oss << "LayoutData:" << "( " << widthMeasureSpec << ", " << heightMeasureSpec << ") ";
159
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 << ")";
164     }
165     else
166     {
167       // Try getting layout data from parent control
168     }
169   }
170   oss << std::endl;
171
172   DALI_LOG_INFO( gLogFilter, Debug::Verbose, oss.str().c_str() );
173
174   // Depth first descent through actor children
175   for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
176   {
177     Actor child = root.GetChildAt( i );
178     LayoutDebugAfterLayoutRecurse( child, depth+1 );
179   }
180 }
181
182 void LayoutDebugAfterLayout( Actor root )
183 {
184   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Layout tree after layout:\n\n" );
185   LayoutDebugAfterLayoutRecurse( root, 0 );
186 }
187
188
189 #endif
190
191 } // namespace Internal
192 } // namespace Toolkit
193 } // namespace Dali