X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Flayouting%2Flayout-controller-impl.cpp;h=746e8e5509ea85c10c6035efda078e8e07efaa77;hp=17a75a66a244a441de2dcf5aad9921d901edccc7;hb=118f87dfe57967bfed8ccdf9143a078eaef1b119;hpb=259338bf01cb1d62350be74f4bcc3f43e40bcedb diff --git a/dali-toolkit/internal/layouting/layout-controller-impl.cpp b/dali-toolkit/internal/layouting/layout-controller-impl.cpp index 17a75a6..746e8e5 100644 --- a/dali-toolkit/internal/layouting/layout-controller-impl.cpp +++ b/dali-toolkit/internal/layouting/layout-controller-impl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace Dali; @@ -44,6 +45,7 @@ namespace Internal LayoutController::LayoutController() : mLayoutRequested( false ), + mFocusChangedFunctor( *this ), mSlotDelegate( this ) { } @@ -55,14 +57,32 @@ LayoutController::~LayoutController() void LayoutController::Initialize() { mAnimation = Animation::New( 0.0f ); + + Dali::Toolkit::KeyInputFocusManager manager = Dali::Toolkit::KeyInputFocusManager::Get(); + manager.KeyInputFocusChangedSignal().Connect( mSlotDelegate.GetConnectionTracker(), mFocusChangedFunctor ); +} + +void LayoutController::FocusChangedFunctor::operator() ( Dali::Toolkit::Control gainingControl, Dali::Toolkit::Control lostControl ) +{ + Toolkit::LayoutItem layoutItem = Toolkit::DevelControl::GetLayout( gainingControl ); + if( layoutItem ) + { + Toolkit::Internal::LayoutItem& layoutItemImpl = GetImplementation( layoutItem ); + LayoutParent* layoutParent = layoutItemImpl.GetParent(); + if( layoutParent ) + { + LayoutGroup* layoutGroup = static_cast< LayoutGroup* >( layoutParent ); + layoutController.RequestLayout( dynamic_cast< Toolkit::Internal::LayoutItem& >( *layoutGroup ), Dali::Toolkit::LayoutTransitionData::ON_CHILD_FOCUS, gainingControl, lostControl ); + } + } } -void LayoutController::RequestLayout( LayoutItem& layoutItem, int layoutTransitionType ) +void LayoutController::RequestLayout( LayoutItem& layoutItem, int layoutTransitionType, Actor gainedChild, Actor lostChild ) { auto actor = Actor::DownCast( layoutItem.GetOwner() ); if ( actor ) { - DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutController::RequestLayout owner[%s] layoutItem[%p] layoutAnimationType(%d)\n", actor.GetName().c_str(), &layoutItem, layoutTransitionType ); + DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutController::RequestLayout owner[%s] layoutItem[%p] layoutTransitionType(%d)\n", actor.GetName().c_str(), &layoutItem, layoutTransitionType ); } else { @@ -72,9 +92,10 @@ void LayoutController::RequestLayout( LayoutItem& layoutItem, int layoutTransiti mLayoutRequested = true; if( layoutTransitionType != -1 ) { - LayoutTransition layoutTransition = LayoutTransition( layoutItem, layoutTransitionType ); + LayoutTransition layoutTransition = LayoutTransition( layoutItem, layoutTransitionType, gainedChild, lostChild ); if( std::find( mLayoutTransitions.begin(), mLayoutTransitions.end(), layoutTransition ) == mLayoutTransitions.end() && layoutItem.GetTransitionData( layoutTransitionType ).Get() ) { + DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutController::RequestLayout Add transition layoutTransitionType(%d)\n", layoutTransitionType ); mLayoutTransitions.push_back( layoutTransition ); } } @@ -106,17 +127,11 @@ void LayoutController::Process() MeasureSpec widthSpec( stageWidth, MeasureSpec::Mode::EXACTLY ); MeasureSpec heightSpec( stageHeight, MeasureSpec::Mode::EXACTLY ); - // Test how to perform a measure on each control. - MeasureHierarchy( stage.GetRootLayer(), widthSpec, heightSpec ); - - LAYOUT_DEBUG_MEASURE_STATES( stage.GetRootLayer() ); - LayoutTransition layoutTransition; LayoutPositionDataArray layoutPositionDataArray; - LayoutDataArray layoutDataArray; LayoutAnimatorArray layoutAnimatorArray; - layoutAnimatorArray.push_back( LayoutDataAnimator() ); - PropertyAnimatorArray childrenPropertiesAnimators; + LayoutDataArray layoutDataArray; + LayoutDataArray childrenLayoutDataArray; if ( mLayoutTransitions.size() ) { @@ -129,8 +144,28 @@ void LayoutController::Process() mLayoutRequested = false; } - LayoutData layoutData( layoutTransition, layoutPositionDataArray, layoutDataArray, layoutAnimatorArray, childrenPropertiesAnimators ); + LayoutData layoutData( layoutTransition, layoutPositionDataArray, layoutAnimatorArray, layoutDataArray, childrenLayoutDataArray ); LayoutItem::Impl::sLayoutData = &layoutData; + + if( layoutTransition.layoutTransitionType != -1 ) + { + UpdateMeasureHierarchyForAnimation( layoutData ); + } + + // Test how to perform a measure on each control. + MeasureHierarchy( stage.GetRootLayer(), widthSpec, heightSpec ); + + LAYOUT_DEBUG_MEASURE_STATES( stage.GetRootLayer() ); + + if( layoutTransition.layoutTransitionType != -1 ) + { + RestoreActorsSpecs(); + } + + layoutAnimatorArray.clear(); + layoutDataArray.clear(); + childrenLayoutDataArray.clear(); + PerformLayout( stage.GetRootLayer(), 0, 0, stageWidth, stageHeight ); PerformLayoutPositioning( layoutPositionDataArray, false ); @@ -178,6 +213,93 @@ void LayoutController::MeasureHierarchy( Actor root, MeasureSpec widthSpec, Meas } } +void LayoutController::UpdateMeasureHierarchyForAnimation( LayoutData& layoutData ) +{ + LayoutTransition& layoutTransition = layoutData.layoutTransition; + Actor transitionOwner = Actor::DownCast( layoutTransition.layoutItem.Get()->GetOwner() ); + LayoutTransitionDataPtr layoutTransitionDataPtr = layoutTransition.layoutItem->GetTransitionData( layoutTransition.layoutTransitionType ); + + if( !layoutTransitionDataPtr->HasUpdateMeasuredSize() ) + { + return; + } + + layoutData.updateMeasuredSize = true; + layoutTransitionDataPtr->CollectLayoutDataElements( transitionOwner, layoutData ); + + UpdateMeasureHierarchyForAnimation( transitionOwner, layoutData ); + + for( auto layoutDataElement : layoutData.layoutDataArray ) + { + if( !layoutDataElement.updateMeasuredSize ) + { + continue; + } + + Actor actor = Actor::DownCast( layoutDataElement.handle ); + LayoutDataAnimator animator = layoutData.layoutAnimatorArray[ layoutDataElement.animatorIndex ]; + float width = actor.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + float height = actor.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + + if( layoutDataElement.AdjustMeasuredSize( width, height, animator.animatorType ) ) + { + mActorSizeSpecs.push_back( ActorSizeSpec( actor ) ); + actor.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, static_cast( width ) ); + actor.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, static_cast( height ) ); + } + } + + layoutData.updateMeasuredSize = false; +} + +void LayoutController::UpdateMeasureHierarchyForAnimation( Actor root, LayoutData& layoutData ) +{ + Toolkit::Control control = Toolkit::Control::DownCast( root ); + if( control ) + { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::UpdateMeasureHierarchyForAnimation control:%s\n", control.GetName().c_str() ); + Internal::Control& controlImpl = GetImplementation( control ); + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); + LayoutItemPtr layout = controlDataImpl.GetLayout(); + + if( layout ) + { + auto layoutGroup = Toolkit::LayoutGroup::DownCast( layout.Get() ); + if( layoutGroup ) + { + unsigned int childCount = layoutGroup.GetChildCount(); + for( unsigned int i=0; i= 0 ) + if( layoutDataElement.animatorIndex >= 0 ) { Actor actor = Actor::DownCast( layoutDataElement.handle ); if ( actor ) { LayoutDataAnimator animator = layoutAnimatorArray[ layoutDataElement.animatorIndex ]; TimePeriod timePeriod = TimePeriod( 0, animation.GetDuration() ); - if (animator.timePeriod.durationSeconds >= 0) + if( animator.timePeriod.durationSeconds >= 0 ) { timePeriod = animator.timePeriod; } @@ -246,7 +380,7 @@ void LayoutController::PerformLayoutAnimation( LayoutTransition& layoutTransitio // Other values are set to current actor ones. if( value.GetType() == Property::NONE ) { - if ( layoutDataElement.positionDataIndex < 0) + if( layoutDataElement.positionDataIndex < 0) { auto result = std::find_if( layoutPositionDataArray.begin(), layoutPositionDataArray.end(), [&actor](const LayoutPositionData& iter) { return iter.handle == actor; } ); @@ -254,10 +388,23 @@ void LayoutController::PerformLayoutAnimation( LayoutTransition& layoutTransitio { continue; } - layoutDataElement.positionDataIndex = std::distance(layoutPositionDataArray.begin(), result); + layoutDataElement.positionDataIndex = std::distance( layoutPositionDataArray.begin(), result ); } LayoutPositionData& positionData = layoutPositionDataArray[ layoutDataElement.positionDataIndex ]; + // with updated measured size scale animation the measured size includes scale, so we need to fit in the centre of the measured rectangle + // the real size child so that the all scale related animations placed correctly + if( positionData.updateWithCurrentSize ) + { + Vector3 size = actor.GetCurrentSize(); + float dX = ( ( positionData.right - positionData.left ) - size.width ) / 2; + float dY = ( ( positionData.bottom - positionData.top ) - size.height ) / 2; + positionData.left += dX; + positionData.top += dY; + positionData.right -= dX; + positionData.bottom -= dY; + positionData.updateWithCurrentSize = false; + } switch ( layoutDataElement.propertyIndex ) { @@ -284,7 +431,7 @@ void LayoutController::PerformLayoutAnimation( LayoutTransition& layoutTransitio } } - // Failed to get target value, just move the next one + // Failed to get target value, just move to the next one if( value.GetType() == Property::NONE ) { continue; @@ -298,29 +445,31 @@ void LayoutController::PerformLayoutAnimation( LayoutTransition& layoutTransitio } // Create an animator for the property - switch (animator.animatorType) - { - case LayoutDataAnimator::AnimatorType::ANIMATE_TO: + switch( animator.animatorType ) { - animation.AnimateTo( Property( actor, layoutDataElement.propertyIndex ), value, animator.alphaFunction, timePeriod ); - break; - } - case LayoutDataAnimator::AnimatorType::ANIMATE_BY: - { - animation.AnimateBy( Property( actor, layoutDataElement.propertyIndex ), value, animator.alphaFunction, timePeriod ); - break; - } - case LayoutDataAnimator::AnimatorType::ANIMATE_BETWEEN: - { - animation.AnimateBetween( Property( actor, layoutDataElement.propertyIndex ), animator.keyFrames, animator.alphaFunction, animator.interpolation ); - break; - } - case LayoutDataAnimator::AnimatorType::ANIMATE_PATH: - animation.Animate( actor, animator.path, animator.forward, animator.alphaFunction, timePeriod ); - break; + case Toolkit::LayoutTransitionData::Animator::ANIMATE_TO: + { + animation.AnimateTo( Property( actor, layoutDataElement.propertyIndex ), value, animator.alphaFunction, timePeriod ); + break; + } + case Toolkit::LayoutTransitionData::Animator::ANIMATE_BY: + { + animation.AnimateBy( Property( actor, layoutDataElement.propertyIndex ), value, animator.alphaFunction, timePeriod ); + break; + } + case Toolkit::LayoutTransitionData::Animator::ANIMATE_BETWEEN: + { + animation.AnimateBetween( Property( actor, layoutDataElement.propertyIndex ), animator.keyFrames, animator.alphaFunction, animator.interpolation ); + break; + } + case Toolkit::LayoutTransitionData::Animator::ANIMATE_PATH: + { + animation.Animate( actor, animator.path, animator.forward, animator.alphaFunction, timePeriod ); + break; + } } + isAnimatorAdded = true; } - isAnimatorAdded = true; } } @@ -328,13 +477,8 @@ void LayoutController::PerformLayoutAnimation( LayoutTransition& layoutTransitio { if( mAnimation.GetState() == Animation::PLAYING ) { - mAnimation.Clear(); - if( mAnimationFinishedFunctors.size() != 0 ) - { - mAnimationFinishedFunctors.front()( mAnimation ); - } + mAnimation.SetCurrentProgress( 1.0f ); } - mAnimation = animation; mAnimationFinishedFunctors.push_back( AnimationFinishedFunctor( *this, layoutTransition, layoutPositionDataArray ) ); mAnimation.FinishedSignal().Connect( mSlotDelegate.GetConnectionTracker(), mAnimationFinishedFunctors.back() );