From 2d2a58472a7d20b0e25909266af490b2c6336bbd Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 27 Nov 2015 13:42:12 +0000 Subject: [PATCH] (TextLabel Example) Fixed Pan gesture handling Problem: When we are resizing and go past the minimum size of the container and then release, we have to move the distance we moved from the minimum size to the our release point again in order to make the container resize again. Reason: This was because we kept on changing mLayoutSize but did not reset it when the pan starts. Solution: Reset mLayoutSize when the pan starts. Change-Id: I3ded29691e8f1c405847f971d9a89d50aa448fdf --- examples/text-label/text-label-example.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp index c7e8555..0636177 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -142,15 +142,29 @@ public: // Resize the text-label with pan gesture void OnPan( Actor actor, const PanGesture& gesture ) { + // Reset mLayoutSize when the pan starts + if( gesture.state == Gesture::Started ) + { + if( mLayoutSize.x < 2.0f ) + { + mLayoutSize.x = 2.0f; + } + + if( mLayoutSize.y < 2.0f ) + { + mLayoutSize.y = 2.0f; + } + } + mLayoutSize.x += gesture.displacement.x * 2.0f; mLayoutSize.y += gesture.displacement.y * 2.0f; - if( mLayoutSize.x >= 2.0f && + if( mLayoutSize.x >= 2.0f || mLayoutSize.y >= 2.0f ) { // Avoid pixel mis-alignment issue - Vector2 clampedSize = Vector2( ConvertToEven(static_cast(mLayoutSize.x)), - ConvertToEven(static_cast(mLayoutSize.y)) ); + Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast( mLayoutSize.x )), 2 ), + std::max( ConvertToEven( static_cast( mLayoutSize.y )), 2 ) ); mContainer.SetSize( clampedSize ); } -- 2.7.4