From 8f1d77887f6584b9cf2804b0b56ae808028e1bbb Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 18 Jun 2014 00:35:45 +0100 Subject: [PATCH 1/1] TextInput PopUp now appears in between handles or at Grabhandle, improved Tail positioning Change-Id: Ic71a0a493bd46c531c2cd8c0bac84a9927dfb3be Signed-off-by: Adeel Kazmi --- .../controls/text-input/text-input-impl.cpp | 10 +++--- .../controls/text-input/text-input-popup-impl.cpp | 38 +++++++++++++--------- .../controls/text-input/text-input-popup-impl.h | 1 + 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp index fe7964c..25f898b 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-impl.cpp @@ -3712,10 +3712,10 @@ void TextInput::AddPopupOptions() mPopUpPanel.AddPopupOptions(); } -void TextInput::SetPopupPosition(const Vector3& position) +void TextInput::SetPopupPosition( const Vector3& position ) { - mPopUpPanel.Self().SetPosition( position ); mPopUpPanel.SetTailPosition( position ); + mPopUpPanel.Self().SetPosition( position ); } void TextInput::HidePopup(bool animate, bool signalFinished ) @@ -3738,25 +3738,25 @@ void TextInput::ShowPopup(bool animate) if(mHighlightMeshActor && mState == StateEdit) { Vector3 topHandle; + Vector3 bottomHandle; // referring to the bottom most point of the handle or the bottom line of selection. Size rowSize; // When text is selected, show popup above top handle (and text), or below bottom handle. // topHandle: referring to the top most point of the handle or the top line of selection. if ( mSelectionHandleTwoActualPosition.y > mSelectionHandleOneActualPosition.y ) { topHandle = mSelectionHandleOneActualPosition; + bottomHandle = mSelectionHandleTwoActualPosition; rowSize= GetRowRectFromCharacterPosition( mSelectionHandleOnePosition ); } else { topHandle = mSelectionHandleTwoActualPosition; + bottomHandle = mSelectionHandleOneActualPosition; rowSize = GetRowRectFromCharacterPosition( mSelectionHandleTwoPosition ); } topHandle.y += -mPopupOffsetFromText.y - rowSize.height; position = Vector3(topHandle.x, topHandle.y, 0.0f); - // bottomHandle: referring to the bottom most point of the handle or the bottom line of selection. - Vector3 bottomHandle; - bottomHandle.y = std::max ( mSelectionHandleTwoActualPosition.y , mSelectionHandleOneActualPosition.y ); bottomHandle.y += GetSelectionHandleSize().y + mPopupOffsetFromText.w; mPopUpPanel.SetAlternativeOffset(Vector2( mBoundingRectangleWorldCoordinates.x, bottomHandle.y - topHandle.y)); diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp index 79f49d3..c2d8640 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.cpp @@ -90,6 +90,7 @@ const char* DEFAULT_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all. // 2. For cursor: should be above top of cursor, or below bottom of cursor + grab handle. const std::string POPUP_ALTERNATIVE_OFFSET("popup-alternative-offset"); ///< Alternative offset property for confinenment constraint. +const std::string POPUP_REQUESTED_POSITION("popup-requested-position"); ///< Position the Popup was requested to be, for confinenment constraint. /** * Confine Actor to boundaries of reference actor (e.g. Parent) @@ -121,15 +122,17 @@ struct ConfinementConstraint const PropertyInput& parentOriginProperty, const PropertyInput& anchorPointProperty, const PropertyInput& referenceSizeProperty, - const PropertyInput& alternativeOffsetProperty) + const PropertyInput& alternativeOffsetProperty, + const PropertyInput& requestedPositionProperty ) { const Vector3& size = sizeProperty.GetVector3(); const Vector3& origin = parentOriginProperty.GetVector3(); const Vector3& anchor = anchorPointProperty.GetVector3(); const Vector3& referenceSize = referenceSizeProperty.GetVector3(); const Vector2& alternativeOffset = alternativeOffsetProperty.GetVector2(); + const Vector3& requestedPosition = requestedPositionProperty.GetVector3(); - Vector3 newPosition(constPosition); + Vector3 newPosition( requestedPosition ); // Get actual position of Actor relative to parent's Top-Left. Vector3 position(constPosition + origin * referenceSize); @@ -138,22 +141,21 @@ struct ConfinementConstraint Vector3 corner(position - size * anchor - mMinIndent); - newPosition.x -= std::max(corner.x, 0.0f); - if ( mFlipHorizontal ) { if( corner.x < mBoundingRect.x + POP_UP_SCREEN_EDGE_MARGIN ) { // Snap PopUp to left hand boundary so stays visible - corner.x = mBoundingRect.x + POP_UP_SCREEN_EDGE_MARGIN ; + corner.x = mBoundingRect.x + POP_UP_SCREEN_EDGE_MARGIN - ( origin.x * referenceSize.x ) + ( size.x * anchor.x ); + newPosition.x = corner.x; } else if ( ( corner.x + size.x ) > ( ( mBoundingRect.x + mBoundingRect.width ) - POP_UP_SCREEN_EDGE_MARGIN )) { // Calculate offset from left boundary PopUp must be placed at so it does not exceed right side boundary. float requiredOffSetFromLeftBoundaryToFit = mBoundingRect.width - POP_UP_SCREEN_EDGE_MARGIN - size.x; corner.x = mBoundingRect.x + requiredOffSetFromLeftBoundaryToFit - ( origin.x * referenceSize.x ) + ( size.x * anchor.x ); + newPosition.x = corner.x; } - newPosition.x = corner.x; } if(mFlipVertical && corner.y < 0.0f) @@ -197,14 +199,15 @@ struct ParentXAxisConstraint } float operator()( const float constXPosition, - const PropertyInput& localWidthProperty, + const PropertyInput& localSizeWidthProperty, + const PropertyInput& parentWidthProperty, const PropertyInput& anchorPointXProperty ) { - const float size = localWidthProperty.GetFloat(); - const float anchor = anchorPointXProperty.GetFloat(); - - float newPosition = Clamp( mHandlesMidPoint, constXPosition - size * anchor , constXPosition + size * anchor); + const float localSizeProperty = localSizeWidthProperty.GetFloat(); + const float size = parentWidthProperty.GetFloat(); + float newPosition = std::max( mHandlesMidPoint, -size/2 + localSizeProperty ); + newPosition = std::min( newPosition, size/2 - localSizeProperty ); return newPosition; } @@ -257,6 +260,7 @@ TextInputPopup::TextInputPopup() mShowFinishedSignal() { mAlternativeOffsetProperty = mRootActor.RegisterProperty( POPUP_ALTERNATIVE_OFFSET, Vector2::ZERO ); + mRequestionPositionProperty = mRootActor.RegisterProperty( POPUP_REQUESTED_POSITION, Vector3::ZERO ); mRootActor.SetParentOrigin( ParentOrigin::CENTER ); mRootActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); // constrain popup to size of parent. @@ -285,6 +289,7 @@ void TextInputPopup::ApplyConfinementConstraint() LocalSource( Actor::ANCHOR_POINT ), ParentSource( Actor::SIZE ), LocalSource( mAlternativeOffsetProperty ), + LocalSource( mRequestionPositionProperty), ConfinementConstraint( DEFAULT_POPUP_INDICATOR_OFFSET, Vector2::ZERO, true, @@ -297,8 +302,10 @@ void TextInputPopup::ApplyTailConstraint() mTail.RemoveConstraints(); Constraint constraint = Constraint::New( Actor::POSITION_X, LocalSource( Actor::SIZE_WIDTH ), - LocalSource( Actor::ANCHOR_POINT_X ), - ParentXAxisConstraint()); + ParentSource( Actor::SIZE_WIDTH ), + LocalSource( Actor::PARENT_ORIGIN_X ), + ParentXAxisConstraint( mPopupTailXPosition )); + mTail.ApplyConstraint( constraint ); } void TextInputPopup::CreateLayer( const Vector2& size ) @@ -426,6 +433,7 @@ void TextInputPopup::CreatePopUpBackground() mTail = ImageActor::New( tailImage ); mTail.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); mTail.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + mTail.SetPosition( 0.0f, TAIL_Y_POSITION ); // TODO: Make tail visible, and positioned in relation to original intended position of popup (i.e. before constrained effects) mTail.SetVisible(true); mTail.SetColor( mCutPasteButtonsColor ); @@ -679,8 +687,6 @@ void TextInputPopup::Show(bool animate) { mRootActor.SetSensitive( true ); - mTail.SetPosition(Vector3( mPopupTailXPosition, TAIL_Y_POSITION, 0.0f)); - if(mAnimation) { mAnimation.Clear(); @@ -938,7 +944,9 @@ void TextInputPopup::SetPopupBoundary( const Rect& boundingRectangle ) void TextInputPopup::SetTailPosition( const Vector3& position ) { + mRootActor.SetProperty( mRequestionPositionProperty, position ); mPopupTailXPosition = position.x; + ApplyConfinementConstraint(); ApplyTailConstraint(); } diff --git a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.h b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.h index 4dd701b..c4e9597 100644 --- a/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.h +++ b/base/dali-toolkit/internal/controls/text-input/text-input-popup-impl.h @@ -416,6 +416,7 @@ private: State mState; ///< Popup State. Actor mRootActor; ///< The actor which all popup content is added to (i.e. panel and buttons) Property::Index mAlternativeOffsetProperty; ///< Property [Vector3] how much to offset the popup if it goes out of the screen + Property::Index mRequestionPositionProperty; ///< Prperty [Vector3] Requested position to place popup ImageActor mBackground; ///< The background popup panel ImageActor mTail; ///< The tail for the popup ImageActor mTailOutline; ///< The border/outline around the tail -- 2.7.4