From: Seoyeon Kim Date: Fri, 9 Jun 2017 10:01:16 +0000 (+0900) Subject: Implement Placeholder additional property X-Git-Tag: submit/tizen/20170705.113121~1^2~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F133248%2F20;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Implement Placeholder additional property - PLACEHOLDER property type is MAP : Text, Color, Font Family, Font Style, Point Size, and Pixel Size Change-Id: If6d8d941865ebb0e21aa70830c3ac1981907bafb Signed-off-by: Seoyeon Kim --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 66805ccfc6..e09f7cec39 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -97,6 +97,7 @@ const char* const PROPERTY_NAME_LINE_COUNT = "lineCoun const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText"; const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor"; const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; +const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -467,6 +468,7 @@ int UtcDaliTextEditorGetPropertyP(void) 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 ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == DevelTextEditor::Property::ENABLE_SELECTION ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == DevelTextEditor::Property::PLACEHOLDER ); END_TEST; } @@ -773,9 +775,74 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR, Color::RED ); DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION ); + // Check the enable selection property editor.SetProperty( DevelTextEditor::Property::ENABLE_SELECTION, false ); DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::ENABLE_SELECTION ), false, TEST_LOCATION ); + // Check the placeholder property with pixel size + Property::Map placeholderPixelSizeMapSet; + Property::Map placeholderPixelSizeMapGet; + Property::Map placeholderFontstyleMap; + placeholderPixelSizeMapSet["placeholderText"] = "Setting Placeholder Text"; + placeholderPixelSizeMapSet["placeholderColor"] = Color::BLUE; + placeholderPixelSizeMapSet["placeholderFontFamily"] = "Arial"; + placeholderPixelSizeMapSet["placeholderPixelSize"] = 15.0f; + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, placeholderPixelSizeMapSet ); + + placeholderPixelSizeMapGet = editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION ); + + // Check the placeholder property with point size + Property::Map placeholderMapSet; + Property::Map placeholderMapGet; + placeholderMapSet["placeholderText"] = "Setting Placeholder Text"; + placeholderMapSet["placeholderColor"] = Color::RED; + placeholderMapSet["placeholderFontFamily"] = "Arial"; + placeholderMapSet["placeholderPointSize"] = 12.0f; + + // Check the placeholder font style property + placeholderFontstyleMap.Clear(); + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderFontstyleMap.Insert( "width", "condensed" ); + placeholderFontstyleMap.Insert( "slant", "italic" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + // Reset font style. + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "weight", "normal" ); + placeholderFontstyleMap.Insert( "slant", "oblique" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "slant", "roman" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER ); + + placeholderFontstyleMap.Clear(); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + + editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, placeholderMapSet ); + placeholderMapGet = editor.GetProperty( DevelTextEditor::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 38bd841f81..10af18a43a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -99,6 +99,7 @@ const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOut const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS = "hiddenInputSettings"; const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize"; const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; +const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -509,6 +510,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == DevelTextField::Property::HIDDEN_INPUT_SETTINGS ); 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 ); END_TEST; } @@ -847,9 +849,74 @@ int UtcDaliTextFieldSetPropertyP(void) field.SetProperty( DevelTextField::Property::PIXEL_SIZE, 20.f ); DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + // Check the enable selection property field.SetProperty( DevelTextField::Property::ENABLE_SELECTION, false ); DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION ); + // Check the placeholder property with pixel size + Property::Map placeholderPixelSizeMapSet; + Property::Map placeholderPixelSizeMapGet; + Property::Map placeholderFontstyleMap; + placeholderPixelSizeMapSet["placeholderText"] = "Setting Placeholder Text"; + placeholderPixelSizeMapSet["placeholderColor"] = Color::BLUE; + placeholderPixelSizeMapSet["placeholderFontFamily"] = "Arial"; + placeholderPixelSizeMapSet["placeholderPixelSize"] = 15.0f; + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + field.SetProperty( DevelTextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet ); + + placeholderPixelSizeMapGet = field.GetProperty( DevelTextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION ); + + // Check the placeholder property with point size + Property::Map placeholderMapSet; + Property::Map placeholderMapGet; + placeholderMapSet["placeholderText"] = "Setting Placeholder Text"; + placeholderMapSet["placeholderColor"] = Color::RED; + placeholderMapSet["placeholderFontFamily"] = "Arial"; + placeholderMapSet["placeholderPointSize"] = 12.0f; + + // Check the placeholder font style property + placeholderFontstyleMap.Clear(); + + placeholderFontstyleMap.Insert( "weight", "bold" ); + placeholderFontstyleMap.Insert( "width", "condensed" ); + placeholderFontstyleMap.Insert( "slant", "italic" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + field.SetProperty( DevelTextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( DevelTextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + // Reset font style. + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "weight", "normal" ); + placeholderFontstyleMap.Insert( "slant", "oblique" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + field.SetProperty( DevelTextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( DevelTextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION ); + + placeholderFontstyleMap.Clear(); + placeholderFontstyleMap.Insert( "slant", "roman" ); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + field.SetProperty( DevelTextField::Property::PLACEHOLDER, placeholderMapSet ); + + placeholderMapGet = field.GetProperty( DevelTextField::Property::PLACEHOLDER ); + + placeholderFontstyleMap.Clear(); + placeholderMapSet["placeholderFontStyle"] = placeholderFontstyleMap; + + field.SetProperty( DevelTextField::Property::PLACEHOLDER, placeholderMapSet ); + placeholderMapGet = field.GetProperty( DevelTextField::Property::PLACEHOLDER ); + DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION ); + DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, 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 6acc30b019..e09207cac4 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 @@ -137,7 +137,30 @@ namespace Property * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color. * @details name "enableSelection", type bool */ - ENABLE_SELECTION + ENABLE_SELECTION, + + /** + * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size. + * + * @code + * Property::Map propertyMap; + * propertyMap["placeholderText"] = "Setting Placeholder Text"; + * propertyMap["placeholderColor"] = Color::RED; + * propertyMap["placeholderFontFamily"] = "Arial"; + * propertyMap["placeholderPointSize"] = 12.0f; + * + * Property::Map fontStyleMap; + * fontstyleMap.Insert( "weight", "bold" ); + * fontstyleMap.Insert( "width", "condensed" ); + * fontstyleMap.Insert( "slant", "italic" ); + * propertyMap["placeholderFontStyle"] = fontStyleMap; + * + * editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER, propertyMap ); + * @endcode + * + * @details name "placeholder", type MAP + */ + PLACEHOLDER }; } // namespace Property 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 f98ea63cd9..b67850809e 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 @@ -103,7 +103,30 @@ namespace Property * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color. * @details name "enableSelection", type bool */ - ENABLE_SELECTION = INPUT_OUTLINE + 3 + ENABLE_SELECTION = INPUT_OUTLINE + 3, + + /** + * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size. + * + * @code + * Property::Map propertyMap; + * propertyMap["placeholderText"] = "Setting Placeholder Text"; + * propertyMap["placeholderColor"] = Color::RED; + * propertyMap["placeholderFontFamily"] = "Arial"; + * propertyMap["placeholderPointSize"] = 12.0f; + * + * Property::Map fontStyleMap; + * fontstyleMap.Insert( "weight", "bold" ); + * fontstyleMap.Insert( "width", "condensed" ); + * fontstyleMap.Insert( "slant", "italic" ); + * propertyMap["placeholderFontStyle"] = fontStyleMap; + * + * field.SetProperty( DevelTextField::Property::PLACEHOLDER, propertyMap ); + * @endcode + * + * @details name "placeholder", type MAP + */ + PLACEHOLDER = INPUT_OUTLINE + 4 }; } // 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 0f4f0e2dd8..53b068322d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -140,6 +140,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -702,6 +703,15 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER: + { + const Property::Map* map = value.GetMap(); + if( map ) + { + impl.mController->SetPlaceholderProperty( *map ); + } + break; + } } // switch } // texteditor } @@ -1071,6 +1081,13 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::PLACEHOLDER: + { + Property::Map map; + impl.mController->GetPlaceholderProperty( map ); + value = map; + break; + } } //switch } 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 134d144ebf..1faa17fdc7 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -141,6 +141,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS ) 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_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -762,6 +763,15 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextField::Property::PLACEHOLDER: + { + const Property::Map* map = value.GetMap(); + if( map ) + { + impl.mController->SetPlaceholderProperty( *map ); + } + break; + } } // switch } // textfield } @@ -1148,6 +1158,13 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextField::Property::PLACEHOLDER: + { + Property::Map map; + impl.mController->GetPlaceholderProperty( map ); + value = map; + break; + } } //switch } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 58893d41ae..6a90595738 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(), + mPlaceholderFont( NULL ), mPlaceholderText(), mPlaceholderTextActive(), mPlaceholderTextInactive(), @@ -105,7 +106,8 @@ EventData::EventData( DecoratorPtr decorator ) mScrollAfterDelete( false ), mAllTextSelected( false ), mUpdateInputStyle( false ), - mPasswordInput( false ) + mPasswordInput( false ), + mIsPlaceholderPixelSize( false ) { mImfManager = ImfManager::Get(); } @@ -884,8 +886,19 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) // Get the default font's description. TextAbstraction::FontDescription defaultFontDescription; TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE; - if( NULL != mFontDefaults ) + + if( IsShowingPlaceholderText() && ( NULL != mEventData->mPlaceholderFont ) ) + { + // If the placeholder font is set specifically, only placeholder font is changed. + defaultFontDescription = mEventData->mPlaceholderFont->mFontDescription; + if( mEventData->mPlaceholderFont->sizeDefined ) + { + defaultPointSize = mEventData->mPlaceholderFont->mDefaultPointSize * 64u; + } + } + else if( NULL != mFontDefaults ) { + // Set the normal font and the placeholder font. defaultFontDescription = mFontDefaults->mFontDescription; defaultPointSize = mFontDefaults->mDefaultPointSize * 64u; } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index e9d99f1fe4..f48ce13002 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -39,6 +39,7 @@ namespace Text //Forward declarations struct CursorInfo; +struct FontDefaults; struct Event { @@ -104,6 +105,7 @@ struct EventData DecoratorPtr mDecorator; ///< Pointer to the decorator. ImfManager mImfManager; ///< The Input Method Framework Manager. + FontDefaults* mPlaceholderFont; ///< The placeholder default font. 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. @@ -155,6 +157,7 @@ struct EventData bool mUpdateInputStyle : 1; ///< Whether to update the input style after moving the cursor. 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. }; struct ModifyEvent diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index c472fe694a..b94ff3ac87 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -31,8 +31,10 @@ #include #include #include +#include #include #include +#include namespace { @@ -45,6 +47,13 @@ const float MAX_FLOAT = std::numeric_limits::max(); const std::string EMPTY_STRING(""); +const char * const PLACEHOLDER_TEXT = "placeholderText"; +const char * const PLACEHOLDER_COLOR = "placeholderColor"; +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"; + float ConvertToEven( float value ) { int intValue(static_cast( value )); @@ -628,6 +637,33 @@ const std::string& Controller::GetDefaultFontFamily() const return EMPTY_STRING; } +void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily ) +{ + if( NULL != mImpl->mEventData ) + { + if( NULL == mImpl->mEventData->mPlaceholderFont ) + { + mImpl->mEventData->mPlaceholderFont = new FontDefaults(); + } + + mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily; + DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str()); + mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty(); + + mImpl->RequestRelayout(); + } +} + +const std::string& Controller::GetPlaceholderFontFamily() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->mFontDescription.family; + } + + return EMPTY_STRING; +} + void Controller::SetDefaultFontWeight( FontWeight weight ) { if( NULL == mImpl->mFontDefaults ) @@ -659,6 +695,41 @@ FontWeight Controller::GetDefaultFontWeight() const return TextAbstraction::FontWeight::NORMAL; } +void Controller::SetPlaceholderTextFontWeight( FontWeight weight ) +{ + if( NULL != mImpl->mEventData ) + { + if( NULL == mImpl->mEventData->mPlaceholderFont ) + { + mImpl->mEventData->mPlaceholderFont = new FontDefaults(); + } + + mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight; + mImpl->mEventData->mPlaceholderFont->weightDefined = true; + + mImpl->RequestRelayout(); + } +} + +bool Controller::IsPlaceholderTextFontWeightDefined() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->weightDefined; + } + return false; +} + +FontWeight Controller::GetPlaceholderTextFontWeight() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight; + } + + return TextAbstraction::FontWeight::NORMAL; +} + void Controller::SetDefaultFontWidth( FontWidth width ) { if( NULL == mImpl->mFontDefaults ) @@ -690,6 +761,41 @@ FontWidth Controller::GetDefaultFontWidth() const return TextAbstraction::FontWidth::NORMAL; } +void Controller::SetPlaceholderTextFontWidth( FontWidth width ) +{ + if( NULL != mImpl->mEventData ) + { + if( NULL == mImpl->mEventData->mPlaceholderFont ) + { + mImpl->mEventData->mPlaceholderFont = new FontDefaults(); + } + + mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width; + mImpl->mEventData->mPlaceholderFont->widthDefined = true; + + mImpl->RequestRelayout(); + } +} + +bool Controller::IsPlaceholderTextFontWidthDefined() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->widthDefined; + } + return false; +} + +FontWidth Controller::GetPlaceholderTextFontWidth() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->mFontDescription.width; + } + + return TextAbstraction::FontWidth::NORMAL; +} + void Controller::SetDefaultFontSlant( FontSlant slant ) { if( NULL == mImpl->mFontDefaults ) @@ -721,6 +827,41 @@ FontSlant Controller::GetDefaultFontSlant() const return TextAbstraction::FontSlant::NORMAL; } +void Controller::SetPlaceholderTextFontSlant( FontSlant slant ) +{ + if( NULL != mImpl->mEventData ) + { + if( NULL == mImpl->mEventData->mPlaceholderFont ) + { + mImpl->mEventData->mPlaceholderFont = new FontDefaults(); + } + + mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant; + mImpl->mEventData->mPlaceholderFont->slantDefined = true; + + mImpl->RequestRelayout(); + } +} + +bool Controller::IsPlaceholderTextFontSlantDefined() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->slantDefined; + } + return false; +} + +FontSlant Controller::GetPlaceholderTextFontSlant() const +{ + if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) ) + { + return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant; + } + + return TextAbstraction::FontSlant::NORMAL; +} + void Controller::SetDefaultFontSize( float fontSize, FontSizeType type ) { if( NULL == mImpl->mFontDefaults ) @@ -738,20 +879,16 @@ void Controller::SetDefaultFontSize( float fontSize, FontSizeType type ) } case PIXEL_SIZE: { - // Point size = Pixel size * 72 / DPI + // Point size = Pixel size * 72.f / DPI unsigned int horizontalDpi = 0u; unsigned int verticalDpi = 0u; TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); fontClient.GetDpi( horizontalDpi, verticalDpi ); - mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72 ) / horizontalDpi; + mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi ); mImpl->mFontDefaults->sizeDefined = true; break; } - default: - { - DALI_ASSERT_ALWAYS( false ); - } } // Clear the font-specific data @@ -774,18 +911,97 @@ float Controller::GetDefaultFontSize( FontSizeType type ) const } case PIXEL_SIZE: { - // Pixel size = Point size * DPI / 72 + // Pixel size = Point size * DPI / 72.f + unsigned int horizontalDpi = 0u; + unsigned int verticalDpi = 0u; + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetDpi( horizontalDpi, verticalDpi ); + + value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f; + break; + } + } + return value; + } + + return value; +} + +void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type ) +{ + if( NULL != mImpl->mEventData ) + { + if( NULL == mImpl->mEventData->mPlaceholderFont ) + { + mImpl->mEventData->mPlaceholderFont = new FontDefaults(); + } + + switch( type ) + { + case POINT_SIZE: + { + mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize; + mImpl->mEventData->mPlaceholderFont->sizeDefined = true; + mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag + break; + } + case PIXEL_SIZE: + { + // Point size = Pixel size * 72.f / DPI unsigned int horizontalDpi = 0u; unsigned int verticalDpi = 0u; TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); fontClient.GetDpi( horizontalDpi, verticalDpi ); - value = mImpl->mFontDefaults->mDefaultPointSize * horizontalDpi / 72; + mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi ); + mImpl->mEventData->mPlaceholderFont->sizeDefined = true; + mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag + break; + } + } + + mImpl->RequestRelayout(); + } +} + +float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const +{ + float value = 0.0f; + if( NULL != mImpl->mEventData ) + { + switch( type ) + { + case POINT_SIZE: + { + if( NULL != mImpl->mEventData->mPlaceholderFont ) + { + value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize; + } + else + { + // If the placeholder text font size is not set, then return the default font size. + value = GetDefaultFontSize( POINT_SIZE ); + } break; } - default: + case PIXEL_SIZE: { - DALI_ASSERT_ALWAYS( false ); + if( NULL != mImpl->mEventData->mPlaceholderFont ) + { + // Pixel size = Point size * DPI / 72.f + unsigned int horizontalDpi = 0u; + unsigned int verticalDpi = 0u; + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + fontClient.GetDpi( horizontalDpi, verticalDpi ); + + value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f; + } + else + { + // If the placeholder text font size is not set, then return the default font size. + value = GetDefaultFontSize( PIXEL_SIZE ); + } + break; } } return value; @@ -1687,6 +1903,86 @@ void Controller::GetHiddenInputOption(Property::Map& options ) } } +void Controller::SetPlaceholderProperty( const Property::Map& map ) +{ + const Property::Map::SizeType count = map.Count(); + + for( Property::Map::SizeType position = 0; position < count; ++position ) + { + KeyValuePair keyValue = map.GetKeyValue( position ); + Property::Key& key = keyValue.first; + Property::Value& value = keyValue.second; + + if( key == PLACEHOLDER_TEXT ) + { + std::string text = ""; + value.Get( text ); + SetPlaceholderText( text ); + } + else if( key == PLACEHOLDER_COLOR ) + { + Vector4 textColor; + value.Get( textColor ); + if( GetPlaceholderTextColor() != textColor ) + { + SetPlaceholderTextColor( textColor ); + } + } + else if( key == PLACEHOLDER_FONT_FAMILY ) + { + std::string fontFamily = ""; + value.Get( fontFamily ); + SetPlaceholderFontFamily( fontFamily ); + } + else if( key == PLACEHOLDER_FONT_STYLE ) + { + SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER ); + } + else if( key == PLACEHOLDER_POINT_SIZE ) + { + float pointSize; + value.Get( pointSize ); + if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) ) + { + SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE ); + } + } + else if( key == PLACEHOLDER_PIXEL_SIZE ) + { + float pixelSize; + value.Get( pixelSize ); + if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) ) + { + SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE ); + } + } + } +} + +void Controller::GetPlaceholderProperty( Property::Map& map ) +{ + if( NULL != mImpl->mEventData ) + { + map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderText; + map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor; + map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily(); + + Property::Value fontStyleMapGet; + GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER ); + map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet; + + // Choose font size : POINT_SIZE or PIXEL_SIZE + if( !mImpl->mEventData->mIsPlaceholderPixelSize ) + { + map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ); + } + else + { + map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ); + } + } +} + // public : Relayout. Controller::UpdateTextType Controller::Relayout( const Size& size ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index efd6d1a4ea..9c80fc7c75 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -515,6 +515,19 @@ public: // Default style & Input style */ const std::string& GetDefaultFontFamily() const; + /** + * @brief Sets the placeholder text font family. + * @param[in] placeholderTextFontFamily The placeholder text font family. + */ + void SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily ); + + /** + * @brief Retrieves the placeholder text font family. + * + * @return The placeholder text font family + */ + const std::string& GetPlaceholderFontFamily() const; + /** * @brief Sets the default font weight. * @@ -534,6 +547,27 @@ public: // Default style & Input style */ FontWeight GetDefaultFontWeight() const; + /** + * @brief Sets the placeholder text font weight. + * + * @param[in] weight The font weight + */ + void SetPlaceholderTextFontWeight( FontWeight weight ); + + /** + * @brief Whether the font's weight has been defined. + * + * @return True if the placeholder text font weight is defined + */ + bool IsPlaceholderTextFontWeightDefined() const; + + /** + * @brief Retrieves the placeholder text font weight. + * + * @return The placeholder text font weight + */ + FontWeight GetPlaceholderTextFontWeight() const; + /** * @brief Sets the default font width. * @@ -553,6 +587,27 @@ public: // Default style & Input style */ FontWidth GetDefaultFontWidth() const; + /** + * @brief Sets the placeholder text font width. + * + * @param[in] width The font width + */ + void SetPlaceholderTextFontWidth( FontWidth width ); + + /** + * @brief Whether the font's width has been defined. + * + * @return True if the placeholder text font width is defined + */ + bool IsPlaceholderTextFontWidthDefined() const; + + /** + * @brief Retrieves the placeholder text font width. + * + * @return The placeholder text font width + */ + FontWidth GetPlaceholderTextFontWidth() const; + /** * @brief Sets the default font slant. * @@ -572,10 +627,31 @@ public: // Default style & Input style */ FontSlant GetDefaultFontSlant() const; + /** + * @brief Sets the placeholder text font slant. + * + * @param[in] slant The font slant + */ + void SetPlaceholderTextFontSlant( FontSlant slant ); + + /** + * @brief Whether the font's slant has been defined. + * + * @return True if the placeholder text font slant is defined + */ + bool IsPlaceholderTextFontSlantDefined() const; + + /** + * @brief Retrieves the placeholder text font slant. + * + * @return The placeholder text font slant + */ + FontSlant GetPlaceholderTextFontSlant() const; + /** * @brief Set the default font size. * - * @param[in] size The default font size. + * @param[in] fontSize The default font size * @param[in] type The font size type is point size or pixel size */ void SetDefaultFontSize( float fontSize, FontSizeType type ); @@ -588,6 +664,20 @@ public: // Default style & Input style */ float GetDefaultFontSize( FontSizeType type ) const; + /** + * @brief Sets the Placeholder text font size. + * @param[in] fontSize The placeholder text font size + * @param[in] type The font size type is point size or pixel size + */ + void SetPlaceholderTextFontSize( float fontSize, FontSizeType type ); + + /** + * @brief Retrieves the Placeholder text font size. + * @param[in] type The font size type + * @return The placeholder font size + */ + float GetPlaceholderTextFontSize( FontSizeType type ) const; + /** * @brief Sets the text's default color. * @@ -978,6 +1068,20 @@ public: // Queries & retrieves. */ void GetHiddenInputOption( Property::Map& options ); + /** + * @brief Sets the Placeholder Properties. + * + * @param[in] map The placeholder property map + */ + void SetPlaceholderProperty( const Property::Map& map ); + + /** + * @brief Retrieves the Placeholder Property map. + * + * @param[out] map The property map + */ + void GetPlaceholderProperty( Property::Map& map ); + public: // Relayout. /** diff --git a/dali-toolkit/internal/text/text-font-style.cpp b/dali-toolkit/internal/text/text-font-style.cpp index 249157e356..8978beb88e 100644 --- a/dali-toolkit/internal/text/text-font-style.cpp +++ b/dali-toolkit/internal/text/text-font-style.cpp @@ -216,6 +216,28 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu } break; } + case FontStyle::PLACEHOLDER: + { + // Sets the placeholder text font's style values. + if( !weightDefined || + ( weightDefined && ( controller->GetPlaceholderTextFontWeight() != weight ) ) ) + { + controller->SetPlaceholderTextFontWeight( weight ); + } + + if( !widthDefined || + ( widthDefined && ( controller->GetPlaceholderTextFontWidth() != width ) ) ) + { + controller->SetPlaceholderTextFontWidth( width ); + } + + if( !slantDefined || + ( slantDefined && ( controller->GetPlaceholderTextFontSlant() != slant ) ) ) + { + controller->SetPlaceholderTextFontSlant( slant ); + } + break; + } } // switch } // map not empty else @@ -236,6 +258,13 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu controller->SetInputFontSlant( TextAbstraction::FontSlant::NONE ); break; } + case FontStyle::PLACEHOLDER: + { + controller->SetPlaceholderTextFontWeight( TextAbstraction::FontWeight::NONE ); + controller->SetPlaceholderTextFontWidth( TextAbstraction::FontWidth::NONE ); + controller->SetPlaceholderTextFontSlant( TextAbstraction::FontSlant::NONE ); + break; + } } // switch } // map.Empty() } // controller @@ -245,7 +274,6 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon { if( controller ) { - const bool isDefaultStyle = FontStyle::DEFAULT == type; const bool isSetbyString = controller->IsFontStyleSetByString(); bool weightDefined = false; @@ -255,46 +283,74 @@ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, Fon FontWidth width = TextAbstraction::FontWidth::NONE; FontSlant slant = TextAbstraction::FontSlant::NONE; - if( isDefaultStyle ) + switch( type ) { - weightDefined = controller->IsDefaultFontWeightDefined(); - widthDefined = controller->IsDefaultFontWidthDefined(); - slantDefined = controller->IsDefaultFontSlantDefined(); - - if( weightDefined ) + case FontStyle::DEFAULT: { - weight = controller->GetDefaultFontWeight(); - } + weightDefined = controller->IsDefaultFontWeightDefined(); + widthDefined = controller->IsDefaultFontWidthDefined(); + slantDefined = controller->IsDefaultFontSlantDefined(); - if( widthDefined ) - { - width = controller->GetDefaultFontWidth(); - } + if( weightDefined ) + { + weight = controller->GetDefaultFontWeight(); + } - if( slantDefined ) - { - slant = controller->GetDefaultFontSlant(); - } - } - else - { - weightDefined = controller->IsInputFontWeightDefined(); - widthDefined = controller->IsInputFontWidthDefined(); - slantDefined = controller->IsInputFontSlantDefined(); + if( widthDefined ) + { + width = controller->GetDefaultFontWidth(); + } - if( weightDefined ) - { - weight = controller->GetInputFontWeight(); + if( slantDefined ) + { + slant = controller->GetDefaultFontSlant(); + } + break; } - - if( widthDefined ) + case FontStyle::INPUT: { - width = controller->GetInputFontWidth(); - } + weightDefined = controller->IsInputFontWeightDefined(); + widthDefined = controller->IsInputFontWidthDefined(); + slantDefined = controller->IsInputFontSlantDefined(); - if( slantDefined ) + if( weightDefined ) + { + weight = controller->GetInputFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetInputFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetInputFontSlant(); + } + break; + } + case FontStyle::PLACEHOLDER: { - slant = controller->GetInputFontSlant(); + // The type is FontStyle::PLACEHOLDER + weightDefined = controller->IsPlaceholderTextFontWeightDefined(); + widthDefined = controller->IsPlaceholderTextFontWidthDefined(); + slantDefined = controller->IsPlaceholderTextFontSlantDefined(); + + if( weightDefined ) + { + weight = controller->GetPlaceholderTextFontWeight(); + } + + if( widthDefined ) + { + width = controller->GetPlaceholderTextFontWidth(); + } + + if( slantDefined ) + { + slant = controller->GetPlaceholderTextFontSlant(); + } + break; } } diff --git a/dali-toolkit/internal/text/text-font-style.h b/dali-toolkit/internal/text/text-font-style.h index e74bcfbc24..4a01d32a51 100644 --- a/dali-toolkit/internal/text/text-font-style.h +++ b/dali-toolkit/internal/text/text-font-style.h @@ -83,8 +83,9 @@ namespace FontStyle { enum Type { - DEFAULT, ///< The default font's style. - INPUT ///< The input font's style. + DEFAULT, ///< The default font's style. + INPUT, ///< The input font's style. + PLACEHOLDER ///< The placeholder text font's style. }; }; @@ -101,7 +102,7 @@ void SetFontFamilyProperty( ControllerPtr controller, const Property::Value& val * * @param[in] controller The text's controller. * @param[in] value The value of the font's style. - * @param[in] type Whether the property is for the default font's style or the input font's style. + * @param[in] type Whether the property is for the default font's style, the input font's style or the placeholder font's style. * */ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value, FontStyle::Type type ); @@ -111,7 +112,7 @@ void SetFontStyleProperty( ControllerPtr controller, const Property::Value& valu * * @param[in] controller The text's controller. * @param[out] value The value of the font's style. - * @param[in] type Whether the property is for the default font's style or the input font's style. + * @param[in] type Whether the property is for the default font's style, the input font's style or the placeholder font's style. */ void GetFontStyleProperty( ControllerPtr controller, Property::Value& value, FontStyle::Type type );