From 8e4860da0bed4e33e1d248ce40d5e5e5f8d28347 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Tue, 14 Apr 2015 16:49:01 +0100 Subject: [PATCH] Text Selection Popup to use bounding box and table views Change-Id: I0ff7776a5cd8c5f9ad49f2d11d7c930b96f1ed24 Signed-off-by: Agnelo Vaz --- .../text-controls/text-selection-popup-impl.cpp | 222 +++++++++------------ .../text-controls/text-selection-popup-impl.h | 11 +- .../internal/text/decorator/text-decorator.cpp | 182 ++++++++++++++++- 3 files changed, 269 insertions(+), 146 deletions(-) diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 01ede36..7347fd3 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include // todo Move this to adaptor?? #define GET_LOCALE_TEXT(string) dgettext("elementary", string) @@ -48,7 +49,7 @@ const Dali::Vector4 DEFAULT_POPUP_BACKGROUND( Dali::Vector4( .20f, 0.29f, 0.44f, const Dali::Vector4 DEFAULT_POPUP_BACKGROUND_PRESSED( Dali::Vector4( 0.07f, 0.10f, 0.17f, 1.0f ) ); const Dali::Vector4 DEFAULT_POPUP_LINE_COLOR( Dali::Vector4( 0.36f, 0.45f, 0.59f, 1.0f ) ); const Dali::Vector4 DEFAULT_OPTION_ICON( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); -const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); +const Dali::Vector4 DEFAULT_OPTION_ICON_PRESSED( Dali::Vector4( 0.5f, 1.0f, 1.0f, 1.0f ) ); const Dali::Vector4 DEFAULT_OPTION_TEXT( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); const Dali::Vector4 DEFAULT_OPTION_TEXT_PRESSED( Dali::Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); @@ -60,16 +61,13 @@ const std::string OPTION_ICON_PASTE( DALI_IMAGE_DIR "copy_paste_icon_paste.png" const std::string OPTION_ICON_SELECT( DALI_IMAGE_DIR "copy_paste_icon_select.png" ); const std::string OPTION_ICON_SELECT_ALL( DALI_IMAGE_DIR "copy_paste_icon_select_all.png" ); -const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 470.0f, 120.0f ); ///< The maximum size of the popup. +const Dali::Vector2 DEFAULT_POPUP_MAX_SIZE( 450.0f, 100.0f ); ///< The maximum size of the popup. -const float OPTION_TEXT_LINE_HEIGHT( 32.0f ); ///< The line height of the text. -const Dali::Vector2 OPTION_ICON_SIZE( 0.f, 0.f ); ///< The size of the icon. -const float OPTION_GAP_ICON_TEXT( 6.f ); ///< The gap between the icon and the text +const Dali::Vector2 OPTION_ICON_SIZE( 65.0f, 65.0f ); ///< The size of the icon. const float OPTION_MARGIN_WIDTH( 10.f ); ///< The margin between the right or lefts edge and the text or icon. -const float OPTION_MAX_WIDTH( DEFAULT_POPUP_MAX_SIZE.width / 6 ); ///< The maximum width of the option (currently set to the max) -const float OPTION_MIN_WIDTH( 86.0f ); ///< The minimum width of the option. - -const float POPUP_DIVIDER_WIDTH( 1.f ); ///< The size of the divider. +const float OPTION_MAX_WIDTH( 110.0f ); ///< The maximum width of the option //todo Make Property +const float OPTION_MIN_WIDTH( 86.0f ); ///< The minimum width of the option. //todo Make Property +const float POPUP_DIVIDER_WIDTH( 3.f ); ///< The size of the divider. const Dali::Vector2 POPUP_TAIL_SIZE( 20.0f, 16.0f ); ///< The size of the tail. const float POPUP_TAIL_Y_OFFSET( 5.f ); ///< The y offset of the tail (when its position is on the bottom). @@ -411,183 +409,142 @@ Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part ) void TextSelectionPopup::CreateBackground() { - if ( !mBackgroundImage ) - { - mBackgroundImage = ResourceImage::New( DEFAULT_POPUP_BACKGROUND_IMAGE ); - } - - NinePatchImage backgroundImageNinePatch = NinePatchImage::DownCast( mBackgroundImage ); - if( backgroundImageNinePatch ) + if ( mBackgroundImage ) { - const Size ninePatchImageSize = Size( static_cast( mBackgroundImage.GetWidth() ), static_cast( mBackgroundImage.GetHeight() ) ); - Rect childRect = backgroundImageNinePatch.GetChildRectangle(); - - // -1u because of the cropping. - mNinePatchMargins.x = childRect.x - 1u; - mNinePatchMargins.y = ninePatchImageSize.width - ( childRect.x + childRect.width ) - 1u; - mNinePatchMargins.z = childRect.y - 1u; - mNinePatchMargins.w = ninePatchImageSize.height - ( childRect.y + childRect.height ) - 1u; + SetBackgroundImage ( mBackgroundImage ); } - SetBackgroundImage( mBackgroundImage ); SetBackgroundColor( mBackgroundColor ); } - void TextSelectionPopup::AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons ) + void TextSelectionPopup::AddOption( Dali::Toolkit::TableView& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons, bool showCaption, std::size_t& indexInTable ) { // 1. Create the backgrounds for the popup option both normal and pressed. // Both containers will be added to a button. - Actor optionContainer = Actor::New(); - optionContainer.SetRelayoutEnabled( true ); + + Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons)?2:1 , 1 ); optionContainer.SetDrawMode( DrawMode::OVERLAY ); - optionContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + optionContainer.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + optionContainer.SetMinimumSize( Vector2( OPTION_MIN_WIDTH, 0 ) ); + optionContainer.SetFitWidth( 0 ); - ImageActor optionPressedContainer = Toolkit::CreateSolidColorActor( mBackgroundPressedColor ); + Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons)?2:1 , 1 ); optionPressedContainer.SetDrawMode( DrawMode::OVERLAY ); - optionPressedContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - + optionPressedContainer.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + optionPressedContainer.SetMinimumSize( Vector2( OPTION_MIN_WIDTH, 0 ) ); + optionPressedContainer.SetFitWidth( 0 ); +#ifdef DECORATOR_DEBUG + optionContainer.SetName("optionContainer"); + optionPressedContainer.SetName("optionPressedContainer"); +#endif // 2. Add text. + + if ( showCaption ) + { Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New(); captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption ); - // optionContainer.Add( captionTextLabel ); Temporary removed. + optionContainer.SetFitHeight( 0 ); Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New(); pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption ); - // optionPressedContainer.Add( pressedCaptionTextLabel ); Temporary removed. + optionPressedContainer.SetFitHeight( 0 ); + + captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); + captionTextLabel.SetMaximumSize( Vector2( OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH , FLT_MAX ) ); //todo FLT_MAX Size negotiation feature needed - // Calculates the icon/text position. - float iconTextOffsetY = 0.0f; + pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); + pressedCaptionTextLabel.SetMaximumSize( Vector2( OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH , FLT_MAX) ); //todo FLT_MAX Size negotiation feature needed + + optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition( 1, 0 ) ); // todo Labels need ellipsis or similar + optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition( 1, 0 ) ); // todo Labels need ellipsis or similar + } if ( showIcons ) { // 3. Create the icons ImageActor pressedIcon = ImageActor::New( iconImage ); ImageActor icon = ImageActor::New( iconImage ); - - optionContainer.Add( icon ); - optionPressedContainer.Add( pressedIcon ); - - iconTextOffsetY = 0.5f * ( ( DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w ) - ( OPTION_ICON_SIZE.height + OPTION_GAP_ICON_TEXT + OPTION_TEXT_LINE_HEIGHT ) ); - - icon.SetParentOrigin( ParentOrigin::TOP_CENTER ); - icon.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - icon.SetY( iconTextOffsetY ); - - pressedIcon.SetParentOrigin( ParentOrigin::TOP_CENTER ); - pressedIcon.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - pressedIcon.SetY( iconTextOffsetY ); - - // Layout icon + gap + text - captionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - captionTextLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - pressedCaptionTextLabel.SetY( -iconTextOffsetY ); - captionTextLabel.SetY( -iconTextOffsetY ); + icon.SetName("image-icon-2014"); + icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + pressedIcon.SetColor( mIconPressedColor ); + optionContainer.SetFitHeight( 0 ); + optionPressedContainer.SetFitHeight( 0 ); + optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) ); + optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) ); + icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) ); + pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) ); } - else - { - // Centre option text - captionTextLabel.SetAnchorPoint( AnchorPoint::CENTER ); - captionTextLabel.SetParentOrigin( ParentOrigin::CENTER ); - pressedCaptionTextLabel.SetAnchorPoint( AnchorPoint::CENTER ); - pressedCaptionTextLabel.SetParentOrigin( ParentOrigin::CENTER ); - } - - // Calculate the size of the text. - Vector3 textSize = captionTextLabel.GetNaturalSize(); - textSize.width = std::min( textSize.width, OPTION_MAX_WIDTH - 2.f * OPTION_MARGIN_WIDTH ); - - // Set the size to the text. Text will be ellipsized if exceeds the max width. - captionTextLabel.SetSize( textSize.GetVectorXY() ); - pressedCaptionTextLabel.SetSize( textSize.GetVectorXY() ); - - // 4. Calculate the size of option. - - // The width is the max size of the text or the icon plus the margins clamped between the option min and max size. - // The height is the whole popup height minus the ninepatch margins. - const Vector2 optionSize( std::min( OPTION_MAX_WIDTH, std::max( OPTION_MIN_WIDTH, std::max( textSize.width, OPTION_ICON_SIZE.width ) + 2.f * OPTION_MARGIN_WIDTH ) ), - DEFAULT_POPUP_MAX_SIZE.height - mNinePatchMargins.z - mNinePatchMargins.w ); - - optionContainer.SetSize( optionSize ); - optionPressedContainer.SetSize( optionSize ); // 5. Create a option. Toolkit::PushButton option = Toolkit::PushButton::New(); - option.SetSize( optionSize ); - option.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - option.SetX( mContentSize.width ); option.SetName( name ); option.SetAnimationTime( 0.0f ); + option.SetSize( OPTION_ICON_SIZE ); + option.SetRelayoutEnabled( false ); //option.ClickedSignal().Connect( this, &TextInputPopup::OnButtonPressed ); - parent.Add( option ); - // 6. Set the normal option image. option.SetButtonImage( optionContainer ); // 7. Set the pressed option image option.SetSelectedImage( optionPressedContainer ); - // 8. Update the content size. - mContentSize.width += optionSize.width; - mContentSize.height = std::max ( optionSize.height, mContentSize.height ); + // 9 Add option to table view + parent.SetFitWidth( indexInTable ); + parent.AddChild( option, Toolkit::TableView::CellPosition( 0, indexInTable ) ); + indexInTable++; - // 9. Add the divider + // 10. Add the divider if( !finalOption ) { - const Size size( POPUP_DIVIDER_WIDTH, mContentSize.height ); + const Size size( POPUP_DIVIDER_WIDTH, 0.0f ); // Height FILL_TO_PARENT + + ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE ); - ImageActor divider = Toolkit::CreateSolidColorActor( Color::WHITE ); divider.SetSize( size ); - divider.SetParentOrigin( ParentOrigin::TOP_LEFT ); - divider.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - divider.SetPosition( mContentSize.width - POPUP_DIVIDER_WIDTH, 0.0f ); - parent.Add( divider ); + divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + parent.SetFitWidth( indexInTable ); + parent.AddChild( divider, Toolkit::TableView::CellPosition( 0, indexInTable ) ); + indexInTable++; } } - void TextSelectionPopup::SetUpPopup( Size& size ) + void TextSelectionPopup::SetUpPopup() { Actor self = Self(); + self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); // Create Layer and Stencil. mStencilLayer = Layer::New(); + mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + mStencilLayer.SetParentOrigin( ParentOrigin::CENTER ); + ImageActor stencil = CreateSolidColorActor( Color::RED ); stencil.SetDrawMode( DrawMode::STENCIL ); stencil.SetVisible( true ); - Actor scrollview = Actor::New(); //todo make a scrollview - stencil.SetRelayoutEnabled( true ); - - self.SetSize( mRequiredPopUpSize ); // control matches stencil size - - mStencilLayer.SetSize( size ); // matches stencil size + stencil.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + stencil.SetParentOrigin( ParentOrigin::CENTER ); - stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - scrollview.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mButtons.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - mStencilLayer.SetAnchorPoint(AnchorPoint::TOP_LEFT); - scrollview.SetAnchorPoint(AnchorPoint::TOP_LEFT); - mButtons.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Actor scrollview = Actor::New(); //todo make a scrollview + scrollview.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + scrollview.SetParentOrigin( ParentOrigin::CENTER ); + scrollview.SetRelayoutEnabled( true ); - mStencilLayer.SetPosition( mNinePatchMargins.x, mNinePatchMargins.y ); + mTableOfButtons.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mTableOfButtons.SetFitHeight( 0 ); + mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER ); - self.Add( mStencilLayer ); mStencilLayer.Add( stencil ); mStencilLayer.Add( scrollview ); - scrollview.Add( mButtons ); + scrollview.Add( mTableOfButtons ); + self.Add( mStencilLayer ); + //self.Add ( mTableOfButtons ); } - void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons ) + void TextSelectionPopup::AddPopupOptions( bool createTail, bool showIcons, bool showCaptions ) { - mShowIcons = showIcons; - mContentSize = Vector2::ZERO; - - mButtons = Actor::New(); - mButtons.SetRelayoutEnabled( true ); - // Add the options into the buttons container. // 1. Determine how many buttons are active and should be added to container. @@ -603,21 +560,19 @@ Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part ) // 2. Iterate list of buttons and add active ones. std::size_t optionsAdded = 0u; + + numberOfOptions = ( numberOfOptions*2 ) - 1 ; // Last Option does not get a divider so -1 or if only one option then also no divider + + mTableOfButtons = Dali::Toolkit::TableView::New( 1, numberOfOptions ); + for( std::vector::const_iterator it = mOrderListOfButtons.begin(), endIt = mOrderListOfButtons.end(); ( it != endIt ); ++it ) { const ButtonRequirement& button( *it ); if ( button.enabled ) { - ++optionsAdded; - AddOption( mButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions, mShowIcons ); + AddOption( mTableOfButtons, button.name, button.caption, button.icon, optionsAdded == numberOfOptions - 1, showIcons, showCaptions, optionsAdded ); // -1 to ignore the last divider } } - - // Calculate the size of the whole popup which may not be all visible. - mRequiredPopUpSize = Size( std::min( mMaxSize.width, mContentSize.width + mNinePatchMargins.x + mNinePatchMargins.y ), DEFAULT_POPUP_MAX_SIZE.height ); - - // Size of the contents within the popup - mVisiblePopUpSize = Size( mRequiredPopUpSize.width - mNinePatchMargins.x - mNinePatchMargins.y, mRequiredPopUpSize.height - mNinePatchMargins.z - mNinePatchMargins.w ); } void TextSelectionPopup::CreatePopup() @@ -626,8 +581,8 @@ Dali::Image TextSelectionPopup::GetPopupImage( PopupParts part ) { CreateOrderedListOfPopupOptions(); //todo Currently causes all options to be shown CreateBackground(); - AddPopupOptions( true, true ); - SetUpPopup( mVisiblePopUpSize ); + AddPopupOptions( true, true, false ); // todo false so not to show Labels until ellipses or similar possible. + SetUpPopup(); } mStencilLayer.RaiseToTop(); @@ -651,7 +606,8 @@ TextSelectionPopup::TextSelectionPopup() mCopyOptionPriority ( 4 ), mPasteOptionPriority ( 5 ), mClipboardOptionPriority( 6 ), - mShowIcons( true ) + mShowIcons( true ), + mShowCaptions( false ) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h index ffca9dd..0753579 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include // EXTERNAL INCLUDES @@ -119,7 +120,6 @@ public: /** * @brief Called when a property of an object of this type is set. - * * @param[in] object The object whose property is set. * @param[in] index The property index. * @param[in] value The new property value. @@ -203,11 +203,11 @@ private: // From Control void CreateBackground(); - void AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons ); + void AddOption( Dali::Toolkit::TableView& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons, bool showCaption, std::size_t& indexInTable ); - void SetUpPopup( Size& size ); + void SetUpPopup(); - void AddPopupOptions( bool createTail, bool showIcons ); + void AddPopupOptions( bool createTail, bool showIcons, bool showCaptions ); private: // Implementation @@ -229,7 +229,7 @@ private: private: // Data - Actor mButtons; // Actor which holds all the buttons, sensitivity can be set oActor buttons via this actor + Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor Layer mStencilLayer; // Layer to enable clipping when buttons exceed popup // Images to be used by the Popup @@ -274,6 +274,7 @@ private: // Data std::size_t mClipboardOptionPriority; // Position of Clipboard button bool mShowIcons; // Flag to show icons + bool mShowCaptions; // Flag to show text captions }; diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 67ae642..3a6d7da 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -19,12 +19,15 @@ #include // EXTERNAL INCLUDES +#include #include #include #include #include #include +#include #include +#include #include #include #include @@ -32,9 +35,10 @@ #include #include #include +#include #include #include -//#include +#include #include // INTERNAL INCLUDES @@ -47,8 +51,24 @@ #ifdef DEBUG_ENABLED #define DECORATOR_DEBUG + #endif + +namespace Dali +{ +namespace Internal +{ +namespace +{ +#ifdef DECORATOR_DEBUG +Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") ); +#endif +} +} +} + + // Local Data namespace { @@ -98,6 +118,26 @@ struct QuadCoordinates typedef std::vector QuadContainer; +/** + * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box. + * @param[in] boundingRectangle local bounding + * @param[out] Vector4 World coordinate bounding Box. + */ +void LocalToWorldCoordinatesBoundingBox( const Dali::Rect& boundingRectangle, Dali::Vector4& boundingBox ) +{ + // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications. + Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + + const float originX = boundingRectangle.x - 0.5f * stageSize.width; + const float originY = boundingRectangle.y - 0.5f * stageSize.height; + + boundingBox = Dali::Vector4( originX, + originY, + originX + boundingRectangle.width, + originY + boundingRectangle.height ); +} + + } // end of namespace namespace Dali @@ -238,9 +278,13 @@ struct Decorator::Impl : public ConnectionTracker if ( !mCopyPastePopup ) { mCopyPastePopup = TextSelectionPopup::New(); +#ifdef DECORATOR_DEBUG + mCopyPastePopup.SetName("mCopyPastePopup"); +#endif + mCopyPastePopup.SetAnchorPoint( AnchorPoint::CENTER ); + mCopyPastePopup.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopUpRelayoutComplete ); // Position popup after size negotiation mActiveLayer.Add ( mCopyPastePopup ); } - mCopyPastePopup.SetPosition( Vector3( 200.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle positions to be used } else { @@ -251,6 +295,23 @@ struct Decorator::Impl : public ConnectionTracker } } + void PopUpRelayoutComplete( Actor actor ) + { + // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box. + + mCopyPastePopup.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopUpRelayoutComplete ); + + Vector3 popupPosition( mCursor[PRIMARY_CURSOR].x, mCursor[PRIMARY_CURSOR].y -100.0f , 0.0f); //todo 100 to be an offset Property + + Vector3 popupSize = Vector3( mCopyPastePopup.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT ), 0.0f ); + + GetConstrainedPopupPosition( popupPosition, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox ); + + SetUpPopUpPositionNotifications(); + + mCopyPastePopup.SetPosition( popupPosition ); //todo grabhandle(cursor) or selection handle positions to be used + } + void CreateCursor( ImageActor& cursor ) { cursor = CreateSolidColorActor( Color::WHITE ); @@ -364,19 +425,27 @@ struct Decorator::Impl : public ConnectionTracker } mGrabHandle = ImageActor::New( mGrabHandleImage ); -#ifdef DECORATOR_DEBUG - mGrabHandle.SetName( "GrabHandleActor" ); -#endif mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mGrabHandle.SetDrawMode( DrawMode::OVERLAY ); // Area that Grab handle responds to, larger than actual handle so easier to move #ifdef DECORATOR_DEBUG - mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 ); - mGrabArea.SetName( "GrabArea" ); + mGrabHandle.SetName( "GrabHandleActor" ); + if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) ) + { + mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 ); + mGrabArea.SetName( "GrabArea" ); + } + else + { + mGrabArea = Actor::New(); + mGrabArea.SetRelayoutEnabled( true ); + mGrabArea.SetName( "GrabArea" ); + } #else mGrabArea = Actor::New(); mGrabArea.SetRelayoutEnabled( true ); #endif + mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER ); mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mGrabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); @@ -386,7 +455,7 @@ struct Decorator::Impl : public ConnectionTracker mTapDetector.Attach( mGrabArea ); mPanGestureDetector.Attach( mGrabArea ); - mActiveLayer.Add(mGrabHandle); + mActiveLayer.Add( mGrabHandle ); } } @@ -625,6 +694,103 @@ struct Decorator::Impl : public ConnectionTracker return false; } + // Popup + + float AlternatePopUpPositionRelativeToCursor() + { + float alternativePosition=0.0f;; + + if ( mPrimaryCursor ) // Secondary cursor not used for paste + { + Cursor cursor = PRIMARY_CURSOR; + alternativePosition = mCursor[cursor].y; + } + + const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class. + + if ( mActiveGrabHandle ) + { + // If grab handle enabled then position pop-up below the grab handle. + const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo + const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property + alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ; + } + else + { + alternativePosition += popupHeight; + } + + return alternativePosition; + } + + void PopUpLeavesVerticalBoundary( PropertyNotification& source ) + { + float alternativeYPosition=0.0f; + // todo + // if( mHighlightMeshActor ) // Text Selection mode + // { + // alternativePosition = AlternatePopUpPositionRelativeToSelectionHandles(); + // } + // else // Not in Text Selection mode + // { + // if can't be positioned above, then position below row. + alternativeYPosition = AlternatePopUpPositionRelativeToCursor(); + // } + mCopyPastePopup.SetY( alternativeYPosition ); + } + + + void SetUpPopUpPositionNotifications( ) + { + // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left. + + // Exceeding vertical boundary + + Vector4 worldCoordinatesBoundingBox; + LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox ); + + float popupHeight = mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT); + + PropertyNotification verticalExceedNotification = mCopyPastePopup.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight/2, + worldCoordinatesBoundingBox.w - popupHeight/2 ) ); + + verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary ); + } + + void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect& boundingBox ) + { + DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() ) + + // Parent must already by added to Stage for these Get calls to work + Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint(); + Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint; + Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position + Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint; + + // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates. + Vector4 boundingRectangleWorld; + LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld ); + + // Calculate distance to move popup (in local space) so fits within the boundary + float xOffSetToKeepWithinBounds = 0.0f; + if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x ) + { + xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x ); + } + else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z ) + { + xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x ); + } + + // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind. + if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y ) + { + requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor(); + } + + requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds; + } Internal::Control& mTextControlParent; Observer& mObserver; -- 2.7.4