From 52bf7f299f84eb2a64e744f2b9183d560689caf2 Mon Sep 17 00:00:00 2001 From: Seoyeon Kim Date: Wed, 24 May 2017 16:53:01 +0900 Subject: [PATCH] Add PLACEHOLDER properties to TextEditor - PLACEHOLDER_TEXT and PLACEHOLDER_TEXT_COLOR Change-Id: I137217a863ab1c70a555981b7ea6d6e7778fe91d Signed-off-by: Seoyeon Kim --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 20 +++++++++ .../controls/text-controls/text-editor-devel.h | 14 ++++++- .../controls/text-controls/text-editor-impl.cpp | 47 +++++++++++++++++++++ .../internal/text/text-controller-impl.cpp | 1 + dali-toolkit/internal/text/text-controller-impl.h | 11 ++--- dali-toolkit/internal/text/text-controller.cpp | 49 ++++++++++++++++++---- dali-toolkit/internal/text/text-controller.h | 14 +++++++ 7 files changed, 143 insertions(+), 13 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index b1ffcff..9fd6789 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include using namespace Dali; @@ -94,9 +95,12 @@ const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBa const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration"; const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; const char* const PROPERTY_NAME_LINE_COUNT = "lineCount"; +const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText"; +const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; +const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval @@ -435,6 +439,8 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextEditor::Property::PIXEL_SIZE ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == DevelTextEditor::Property::LINE_COUNT ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == DevelTextEditor::Property::PLACEHOLDER_TEXT ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ); END_TEST; } @@ -727,6 +733,20 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty( DevelTextEditor::Property::PIXEL_SIZE, 20.f ); DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Check placeholder text properties. + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION ); + + // Check placeholder text properties when focused. + editor.SetProperty( DevelControl::Property::STATE, "FOCUSED" ); + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT, "Setting Focused Placeholder Text" ); + DALI_TEST_EQUALS( editor.GetProperty( DevelControl::Property::STATE ), (int)DevelControl::FOCUSED, TEST_LOCATION ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT ), std::string("Setting Focused Placeholder Text"), TEST_LOCATION ); + + // Check placeholder text's color property. + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR, Color::RED ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION ); + END_TEST; } diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 5bc2654..473adba 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -116,7 +116,19 @@ namespace Property * @details name "lineCount", type int * @note this property is read-only. */ - LINE_COUNT + LINE_COUNT, + + /** + * @brief The text to display when the TextEditor is empty and inactive. + * @details name "placeholderText", type string + */ + PLACEHOLDER_TEXT, + + /** + * @brief The placeholder-text color. + * @details name "placeholderTextColor", type vector4 + */ + PLACEHOLDER_TEXT_COLOR }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 47ee359..e103702 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -32,6 +32,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -135,6 +136,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE ) DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -661,6 +664,32 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT: + { + if( impl.mController ) + { + const std::string& text = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() ); + + impl.mController->SetPlaceholderText( text ); + } + break; + } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR: + { + if( impl.mController ) + { + const Vector4& textColor = value.Get< Vector4 >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a ); + + if( impl.mController->GetPlaceholderTextColor() != textColor ) + { + impl.mController->SetPlaceholderTextColor( textColor ); + impl.mRenderer.Reset(); + } + } + break; + } } // switch } // texteditor } @@ -1004,6 +1033,24 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT: + { + if( impl.mController ) + { + std::string text; + impl.mController->GetPlaceholderText( text ); + value = text; + } + break; + } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR: + { + if( impl.mController ) + { + value = impl.mController->GetPlaceholderTextColor(); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index d09e1ed..f119650 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -70,6 +70,7 @@ namespace Text EventData::EventData( DecoratorPtr decorator ) : mDecorator( decorator ), mImfManager(), + mPlaceholderText(), mPlaceholderTextActive(), mPlaceholderTextInactive(), mPlaceholderTextColor( 0.8f, 0.8f, 0.8f, 0.8f ), diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 3014edb..e9d99f1 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -104,6 +104,7 @@ struct EventData DecoratorPtr mDecorator; ///< Pointer to the decorator. ImfManager mImfManager; ///< The Input Method Framework Manager. + std::string mPlaceholderText; ///< The text to display when the TextField is empty. std::string mPlaceholderTextActive; ///< The text to display when the TextField is empty with key-input focus. std::string mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive. Vector4 mPlaceholderTextColor; ///< The in/active placeholder text color. @@ -383,10 +384,9 @@ struct Controller::Impl */ bool IsPlaceholderAvailable() const { - return ( mEventData && - ( !mEventData->mPlaceholderTextInactive.empty() || - !mEventData->mPlaceholderTextActive.empty() ) - ); + return ( mEventData && ( !mEventData->mPlaceholderText.empty() || + !mEventData->mPlaceholderTextInactive.empty() || + !mEventData->mPlaceholderTextActive.empty() ) ); } bool IsShowingPlaceholderText() const @@ -399,7 +399,8 @@ struct Controller::Impl */ bool IsFocusedPlaceholderAvailable() const { - return ( mEventData && !mEventData->mPlaceholderTextActive.empty() ); + return ( mEventData && ( !mEventData->mPlaceholderTextActive.empty() || + !mEventData->mPlaceholderText.empty() ) ); } bool IsShowingRealText() const diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 7596b51..f9445b5 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -512,6 +512,22 @@ void Controller::GetText( std::string& text ) const } } +void Controller::SetPlaceholderText( const std::string& text ) +{ + if( NULL != mImpl->mEventData ) + { + mImpl->mEventData->mPlaceholderText = text; + + // Update placeholder if there is no text + if( mImpl->IsShowingPlaceholderText() || + ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) ) + { + ShowPlaceholderText(); + } + } +} + +// This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text ) { if( NULL != mImpl->mEventData ) @@ -534,6 +550,15 @@ void Controller::SetPlaceholderText( PlaceholderType type, const std::string& te } } +void Controller::GetPlaceholderText( std::string& text ) const +{ + if( NULL != mImpl->mEventData ) + { + text = mImpl->mEventData->mPlaceholderText; + } +} + +// This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const { if( NULL != mImpl->mEventData ) @@ -3202,17 +3227,27 @@ void Controller::ShowPlaceholderText() const char* text( NULL ); size_t size( 0 ); - // TODO - Switch placeholder text styles when changing state - if( ( EventData::INACTIVE != mImpl->mEventData->mState ) && - ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) ) + if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() ) { - text = mImpl->mEventData->mPlaceholderTextActive.c_str(); - size = mImpl->mEventData->mPlaceholderTextActive.size(); + if( ( EventData::INACTIVE != mImpl->mEventData->mState ) && + ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) ) + { + text = mImpl->mEventData->mPlaceholderTextActive.c_str(); + size = mImpl->mEventData->mPlaceholderTextActive.size(); + } + else + { + text = mImpl->mEventData->mPlaceholderTextInactive.c_str(); + size = mImpl->mEventData->mPlaceholderTextInactive.size(); + } } else { - text = mImpl->mEventData->mPlaceholderTextInactive.c_str(); - size = mImpl->mEventData->mPlaceholderTextInactive.size(); + if( 0u != mImpl->mEventData->mPlaceholderText.c_str() ) + { + text = mImpl->mEventData->mPlaceholderText.c_str(); + size = mImpl->mEventData->mPlaceholderText.size(); + } } mImpl->mTextUpdateInfo.mCharacterIndex = 0u; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index e3a7427..c6b01a4 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -454,6 +454,13 @@ public: // Update. /** * @brief Replaces any placeholder text previously set. * + * @param[in] text A string of UTF-8 characters. + */ + void SetPlaceholderText( const std::string& text ); + + /** + * @brief Replaces any placeholder text previously set. + * * @param[in] type Different placeholder-text can be shown when the control is active/inactive. * @param[in] text A string of UTF-8 characters. */ @@ -462,6 +469,13 @@ public: // Update. /** * @brief Retrieve any placeholder text previously set. * + * @param[out] A string of UTF-8 characters. + */ + void GetPlaceholderText( std::string& text ) const; + + /** + * @brief Retrieve any placeholder text previously set. + * * @param[in] type Different placeholder-text can be shown when the control is active/inactive. * @param[out] A string of UTF-8 characters. */ -- 2.7.4