From: Seoyeon Kim Date: Mon, 4 Sep 2017 09:45:51 +0000 (+0900) Subject: Add Placeholder Ellipsis in TextField X-Git-Tag: dali_1.2.59~7^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=96f01f71e6eb54c86089d9b4e5979a4ba4ce93c2 Add Placeholder Ellipsis in TextField - Added Ellipsis in TextField normal text and placeholder text Change-Id: I11dd1aca040e3d9dacdfd955d6ef2a53981f1637 Signed-off-by: Seoyeon Kim --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 08b194f..b4bd556 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -100,6 +100,7 @@ const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS = "hiddenIn const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; +const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -513,6 +514,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextField::Property::PIXEL_SIZE ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == DevelTextField::Property::ENABLE_SELECTION ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == DevelTextField::Property::PLACEHOLDER ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == DevelTextField::Property::ELLIPSIS ); END_TEST; } @@ -864,6 +866,7 @@ int UtcDaliTextFieldSetPropertyP(void) placeholderPixelSizeMapSet["placeholderColor"] = Color::BLUE; placeholderPixelSizeMapSet["placeholderFontFamily"] = "Arial"; placeholderPixelSizeMapSet["placeholderPixelSize"] = 15.0f; + placeholderPixelSizeMapSet["placeholderEllipsis"] = true; placeholderFontstyleMap.Insert( "weight", "bold" ); placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap; @@ -881,6 +884,7 @@ int UtcDaliTextFieldSetPropertyP(void) placeholderMapSet["placeholderColor"] = Color::RED; placeholderMapSet["placeholderFontFamily"] = "Arial"; placeholderMapSet["placeholderPointSize"] = 12.0f; + placeholderMapSet["placeholderEllipsis"] = false; // Check the placeholder font style property placeholderFontstyleMap.Clear(); @@ -921,6 +925,11 @@ int UtcDaliTextFieldSetPropertyP(void) DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + // Check the ellipsis property + DALI_TEST_CHECK( !field.GetProperty( DevelTextField::Property::ELLIPSIS ) ); + field.SetProperty( DevelTextField::Property::ELLIPSIS, true ); + DALI_TEST_CHECK( field.GetProperty( DevelTextField::Property::ELLIPSIS ) ); + END_TEST; } diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index bc199ad..4369126 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -116,6 +116,7 @@ namespace Property * propertyMap["placeholderColor"] = Color::RED; * propertyMap["placeholderFontFamily"] = "Arial"; * propertyMap["placeholderPointSize"] = 12.0f; + * propertyMap["placeholderEllipsis"] = true; * * Property::Map fontStyleMap; * fontStyleMap.Insert( "weight", "bold" ); @@ -128,7 +129,14 @@ namespace Property * * @details name "placeholder", type MAP */ - PLACEHOLDER = INPUT_OUTLINE + 4 + PLACEHOLDER = INPUT_OUTLINE + 4, + + /** + * @brief Enable or disable the ellipsis. + * @details name "ellipsis", type Property::BOOLEAN. + * @note PLACEHOLDER map is used to add ellipsis to placeholder text. + */ + ELLIPSIS = INPUT_OUTLINE + 5 }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index d5ea993..25273f1 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -142,6 +142,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -772,6 +773,17 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextField::Property::ELLIPSIS: + { + if( impl.mController ) + { + const bool ellipsis = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis ); + + impl.mController->SetTextElideEnabled( ellipsis ); + } + break; + } } // switch } // textfield } @@ -1165,6 +1177,14 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde value = map; break; } + case Toolkit::DevelTextField::Property::ELLIPSIS: + { + if( impl.mController ) + { + value = impl.mController->IsTextElideEnabled(); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index fef0f70..0101616 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -106,7 +106,9 @@ EventData::EventData( DecoratorPtr decorator ) mAllTextSelected( false ), mUpdateInputStyle( false ), mPasswordInput( false ), - mIsPlaceholderPixelSize( false ) + mIsPlaceholderPixelSize( false ), + mIsPlaceholderElideEnabled( false ), + mPlaceholderEllipsisFlag( false ) { mImfManager = ImfManager::Get(); } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 898e2c6..23188f5 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -159,6 +159,8 @@ struct EventData bool mPasswordInput : 1; ///< True if password input is enabled. bool mCheckScrollAmount : 1; ///< Whether to check scrolled amount after updating the position bool mIsPlaceholderPixelSize : 1; ///< True if the placeholder font size is set as pixel size. + bool mIsPlaceholderElideEnabled : 1; ///< True if the placeholder text's elide is enabled. + bool mPlaceholderEllipsisFlag : 1; ///< True if the text controller sets the placeholder ellipsis. }; struct ModifyEvent diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 258fea7..4ca2d9a 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -54,6 +54,7 @@ const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily"; const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle"; const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize"; const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize"; +const char * const PLACEHOLDER_ELLIPSIS = "placeholderEllipsis"; float ConvertToEven( float value ) { @@ -430,6 +431,24 @@ bool Controller::IsTextElideEnabled() const return mImpl->mModel->mElideEnabled; } +void Controller::SetPlaceholderTextElideEnabled( bool enabled ) +{ + mImpl->mEventData->mIsPlaceholderElideEnabled = enabled; + mImpl->mEventData->mPlaceholderEllipsisFlag = true; + + // Update placeholder if there is no text + if( mImpl->IsShowingPlaceholderText() || + ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) ) + { + ShowPlaceholderText(); + } +} + +bool Controller::IsPlaceholderTextElideEnabled() const +{ + return mImpl->mEventData->mIsPlaceholderElideEnabled; +} + void Controller::SetSelectionEnabled( bool enabled ) { mImpl->mEventData->mSelectionEnabled = enabled; @@ -1982,6 +2001,12 @@ void Controller::SetPlaceholderProperty( const Property::Map& map ) SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE ); } } + else if( key == PLACEHOLDER_ELLIPSIS ) + { + bool ellipsis; + value.Get( ellipsis ); + SetPlaceholderTextElideEnabled( ellipsis ); + } } } @@ -2014,6 +2039,11 @@ void Controller::GetPlaceholderProperty( Property::Map& map ) { map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ); } + + if( mImpl->mEventData->mPlaceholderEllipsisFlag ) + { + map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled(); + } } } @@ -2071,6 +2101,20 @@ Controller::UpdateTextType Controller::Relayout( const Size& size ) COLOR ); } + // Set the update info to elide the text. + if( mImpl->mModel->mElideEnabled || + ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) ) + { + // Update Text layout for applying elided + mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | + ALIGN | + LAYOUT | + UPDATE_LAYOUT_SIZE | + REORDER ); + mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true; + mImpl->mTextUpdateInfo.mCharacterIndex = 0u; + } + // Make sure the model is up-to-date before layouting. ProcessModifyEvents(); bool updated = mImpl->UpdateModel( mImpl->mOperationsPending ); @@ -3255,13 +3299,35 @@ bool Controller::DoRelayout( const Size& size, layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex; layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines; + // Update the ellipsis + bool elideTextEnabled = mImpl->mModel->mElideEnabled; + + if( NULL != mImpl->mEventData ) + { + if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() ) + { + elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled; + } + else if( EventData::INACTIVE != mImpl->mEventData->mState ) + { + // Disable ellipsis when editing + elideTextEnabled = false; + } + + // Reset the scroll position in inactive state + if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) ) + { + ResetScrollPosition(); + } + } + // Update the visual model. Size newLayoutSize; viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters, glyphPositions, mImpl->mModel->mVisualModel->mLines, newLayoutSize, - mImpl->mModel->mElideEnabled ); + elideTextEnabled ); viewUpdated = viewUpdated || ( newLayoutSize != layoutSize ); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 9e193c7..609fe7a 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -369,6 +369,18 @@ public: // Configure the text controller. bool IsTextElideEnabled() const; /** + * @brief Enable or disable the placeholder text elide. + * @param enabled Whether to enable the placeholder text elide. + */ + void SetPlaceholderTextElideEnabled( bool enabled ); + + /** + * @brief Whether the placeholder text elide property is enabled. + * @return True if the placeholder text elide property is enabled, false otherwise. + */ + bool IsPlaceholderTextElideEnabled() const; + + /** * @brief Enable or disable the text selection. * @param[in] enabled Whether to enable the text selection. */