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.
18 #include <dali-toolkit/internal/layouting/absolute-layout-impl.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/common/extents.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/devel-api/actors/actor-devel.h>
25 #include <dali-toolkit/devel-api/layouting/layout-item.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
31 #if defined(DEBUG_ENABLED)
32 static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" );
43 AbsoluteLayoutPtr AbsoluteLayout::New()
45 AbsoluteLayoutPtr layout( new AbsoluteLayout() );
49 AbsoluteLayout::AbsoluteLayout()
54 AbsoluteLayout::~AbsoluteLayout()
58 void AbsoluteLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
60 #if defined(DEBUG_ENABLED)
61 auto actor = Actor::DownCast(GetOwner());
63 std::ostringstream oss;
64 oss << "AbsoluteLayout::OnMeasure ";
67 oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " ";
69 oss << "widthMeasureSpec:" << widthMeasureSpec << " heightMeasureSpec:" << heightMeasureSpec << std::endl;
70 DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() );
73 LayoutLength totalHeight( 0 );
74 LayoutLength totalWidth( 0 );
78 MeasuredSize::State widthState;
79 MeasuredSize::State heightState;
80 } childState = { MeasuredSize::State::MEASURED_SIZE_OK, MeasuredSize::State::MEASURED_SIZE_OK };
82 LayoutLength minPositionX( 0 );
83 LayoutLength minPositionY( 0 );
84 LayoutLength maxPositionX( 0 );
85 LayoutLength maxPositionY( 0 );
88 for( unsigned int i=0; i<GetChildCount(); ++i )
90 auto childLayout = GetChildAt( i );
93 auto childOwner = childLayout->GetOwner();
96 MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
97 LayoutLength childWidth = childLayout->GetMeasuredWidth();
98 LayoutLength childHeight = childLayout->GetMeasuredHeight();
100 // Determine the width and height needed by the children using their given position and size.
101 // Children could overlap so find the left most and right most child.
102 auto childPosition = childOwner.GetProperty< Vector3 >( Actor::Property::POSITION );
103 LayoutLength childLeft = childPosition.x;
104 LayoutLength childTop = childPosition.y;
106 minPositionX = std::min( minPositionX, childLeft );
107 maxPositionX = std::max( maxPositionX, childLeft + childWidth );
108 // Children could overlap so find the highest and lowest child.
109 minPositionY = std::min( minPositionY, childTop );
110 maxPositionY = std::max( maxPositionY, childTop + childHeight );
112 // Store current width and height needed to contain all children.
113 totalWidth = maxPositionX - minPositionX;
114 totalHeight = maxPositionY - minPositionY;
115 DALI_LOG_INFO( gLogFilter, Debug::Concise, "AbsoluteLayout::OnMeasure child width(%f) height(%f) \n", totalWidth.AsDecimal(), totalHeight.AsDecimal() );
117 if( childLayout->GetMeasuredWidthAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL )
119 childState.widthState = MeasuredSize::State::MEASURED_SIZE_TOO_SMALL;
121 if( childLayout->GetMeasuredHeightAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL )
123 childState.heightState = MeasuredSize::State::MEASURED_SIZE_TOO_SMALL;
128 MeasuredSize widthSizeAndState = ResolveSizeAndState( totalWidth, widthMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK);
129 MeasuredSize heightSizeAndState = ResolveSizeAndState( totalHeight, heightMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK);
130 totalWidth = widthSizeAndState.GetSize();
131 totalHeight = heightSizeAndState.GetSize();
133 // Ensure layout respects it's given minimum size
134 totalWidth = std::max( totalWidth, GetSuggestedMinimumWidth() );
135 totalHeight = std::max( totalHeight, GetSuggestedMinimumHeight() );
137 widthSizeAndState.SetState( childState.widthState );
138 heightSizeAndState.SetState( childState.heightState );
140 SetMeasuredDimensions( ResolveSizeAndState( totalWidth, widthMeasureSpec, childState.widthState ),
141 ResolveSizeAndState( totalHeight, heightMeasureSpec, childState.heightState ) );
145 void AbsoluteLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
147 // Absolute layout positions it's children at their Actor positions.
148 // Children could overlap or spill outside the parent, as is the nature of absolute positions.
149 auto count = GetChildCount();
150 DALI_LOG_INFO( gLogFilter, Debug::Concise, "AbsoluteLayout::OnLayout child count(%d)\n", count );
152 for( unsigned int i = 0; i < count; i++)
154 LayoutItemPtr childLayout = GetChildAt( i );
155 if( childLayout != nullptr )
157 auto childOwner = childLayout->GetOwner();
158 LayoutLength childWidth = childLayout->GetMeasuredWidth();
159 LayoutLength childHeight = childLayout->GetMeasuredHeight();
161 auto childPosition = childOwner.GetProperty< Vector3 >( Actor::Property::POSITION );
162 // Check if there on going position or size animation and skip it to avoid legacy application regressions
163 if( DevelActor::IsPositionOrSizeCurrentlyAnimating( Actor::DownCast( childOwner ) ) &&
164 !childLayout->IsLayoutAnimated() )
169 LayoutLength childTop = childPosition.y;
170 LayoutLength childLeft = childPosition.x;
172 DALI_LOG_STREAM( gLogFilter, Debug::General,
173 "AbsoluteLayout::OnLayout child[" << Toolkit::Control::DownCast( childOwner ).GetName().c_str() <<
174 "] position(" << childPosition << ") child width[" << childWidth << "] height[" << childHeight << "]\n" );
176 childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
181 } // namespace Internal
182 } // namespace Toolkit