X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=6e9148bb24113198bed447c537c0bfbb24495d54;hb=0a0b9dc2df798519fa1f8d8bffff9c5c74e967b1;hp=31c1edf5973cfb1154307b69c366589205636b65;hpb=5e79f29ff3e9a6042eb44dc40130c0d648bc2a3b;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 31c1edf..6e9148b 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -2838,12 +2838,28 @@ bool Controller::DoRelayout( const Size& size, void Controller::CalculateVerticalOffset( const Size& controlSize ) { - Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize(); + ModelPtr& model = mImpl->mModel; + VisualModelPtr& visualModel = model->mVisualModel; + Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize(); + Size oldLayoutSize = layoutSize; + float offsetY = 0.f; + bool needRecalc = false; + float defaultFontLineHeight = mImpl->GetDefaultFontLineHeight(); if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 ) { // Get the line height of the default font. - layoutSize.height = mImpl->GetDefaultFontLineHeight(); + layoutSize.height = defaultFontLineHeight; + } + + // Whether the text control is editable + const bool isEditable = NULL != mImpl->mEventData; + if ( isEditable && layoutSize.height != defaultFontLineHeight ) + { + // This code prevents the wrong positioning of cursor when the layout size is bigger/smaller than defaultFontLineHeight. + // This situation occurs when the size of placeholder text is different from the default text. + layoutSize.height = defaultFontLineHeight; + needRecalc = true; } switch( mImpl->mModel->mVerticalAlignment ) @@ -2851,19 +2867,33 @@ void Controller::CalculateVerticalOffset( const Size& controlSize ) case VerticalAlignment::TOP: { mImpl->mModel->mScrollPosition.y = 0.f; + offsetY = 0.f; break; } case VerticalAlignment::CENTER: { mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment. + if ( needRecalc ) offsetY = floorf( 0.5f * ( layoutSize.height - oldLayoutSize.height ) ); break; } case VerticalAlignment::BOTTOM: { mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height; + if ( needRecalc ) offsetY = layoutSize.height - oldLayoutSize.height; break; } } + + if ( needRecalc ) + { + // Update glyphPositions according to recalculation. + const Length positionCount = visualModel->mGlyphPositions.Count(); + Vector& glyphPositions = visualModel->mGlyphPositions; + for( Length index = 0u; index < positionCount; index++ ) + { + glyphPositions[index].y += offsetY; + } + } } // private : Events.