X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-label-impl.cpp;h=2fddac33ee001ce4c50aaae37d84395f23109465;hp=bb40d0044af9f085db3b670855732204cdebfadc;hb=dd0935960c1acaf63d2b4f560b39236b871135b7;hpb=259267e944a0215c92b3955695b9b4bc610660db diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp old mode 100644 new mode 100755 index bb40d00..2fddac3 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include #include #include #include @@ -73,6 +74,12 @@ namespace 0.5f, // VerticalAlignment::CENTER 1.0f // VerticalAlignment::BOTTOM }; + + const std::string TEXT_FIT_ENABLE_KEY( "enable" ); + const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" ); + const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" ); + const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" ); + const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" ); } namespace @@ -107,11 +114,11 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty01", STRING, RESERVED_PROPERTY_01 ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty02", STRING, RESERVED_PROPERTY_02 ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty03", STRING, RESERVED_PROPERTY_03 ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty04", STRING, RESERVED_PROPERTY_04 ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty05", STRING, RESERVED_PROPERTY_05 ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED ) @@ -132,6 +139,9 @@ DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE ) DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR ) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 ) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 ) @@ -267,73 +277,6 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr impl.mTextUpdateNeeded = true; break; } - - case Toolkit::TextLabel::Property::SHADOW_OFFSET: - { - if( impl.mController ) - { - const Vector2& shadowOffset = value.Get< Vector2 >(); - if ( impl.mController->GetShadowOffset() != shadowOffset ) - { - impl.mController->SetShadowOffset( shadowOffset ); - impl.mTextUpdateNeeded = true; - } - } - break; - } - case Toolkit::TextLabel::Property::SHADOW_COLOR: - { - if( impl.mController ) - { - const Vector4& shadowColor = value.Get< Vector4 >(); - if ( impl.mController->GetShadowColor() != shadowColor ) - { - impl.mController->SetShadowColor( shadowColor ); - impl.mTextUpdateNeeded = true; - } - } - break; - } - case Toolkit::TextLabel::Property::UNDERLINE_COLOR: - { - if( impl.mController ) - { - const Vector4& color = value.Get< Vector4 >(); - if ( impl.mController->GetUnderlineColor() != color ) - { - impl.mController->SetUnderlineColor( color ); - impl.mTextUpdateNeeded = true; - } - } - break; - } - case Toolkit::TextLabel::Property::UNDERLINE_ENABLED: - { - if( impl.mController ) - { - const bool enabled = value.Get< bool >(); - if ( impl.mController->IsUnderlineEnabled() != enabled ) - { - impl.mController->SetUnderlineEnabled( enabled ); - impl.mTextUpdateNeeded = true; - } - } - break; - } - - case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT: - { - if( impl.mController ) - { - float height = value.Get< float >(); - if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) - { - impl.mController->SetUnderlineHeight( height ); - impl.mTextUpdateNeeded = true; - } - } - break; - } case Toolkit::TextLabel::Property::ENABLE_MARKUP: { if( impl.mController ) @@ -362,7 +305,6 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr // If request is enable (true) then start autoscroll as not already running else { - impl.mController->SetTextElideEnabled( false ); impl.mController->SetAutoScrollEnabled( enableAutoScroll ); } } @@ -539,6 +481,92 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >()); break; } + case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); + break; + } + case Toolkit::DevelTextLabel::Property::TEXT_FIT: + { + const Property::Map& propertiesMap = value.Get(); + + bool enabled = false; + float minSize = 0.f; + float maxSize = 0.f; + float stepSize = 0.f; + bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false; + Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE; + + if ( !propertiesMap.Empty() ) + { + const unsigned int numberOfItems = propertiesMap.Count(); + + // Parses and applies + for( unsigned int index = 0u; index < numberOfItems; ++index ) + { + const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index ); + + if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) ) + { + /// Enable key. + enabled = valueGet.second.Get< bool >(); + } + else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) ) + { + /// min size. + minSize = valueGet.second.Get< float >(); + isMinSizeSet = true; + } + else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) ) + { + /// max size. + maxSize = valueGet.second.Get< float >(); + isMaxSizeSet = true; + } + else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) ) + { + /// step size. + stepSize = valueGet.second.Get< float >(); + isStepSizeSet = true; + } + else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) ) + { + if( "pixelSize" == valueGet.second.Get< std::string >() ) + { + type = Controller::FontSizeType::PIXEL_SIZE; + } + } + } + + impl.mController->SetTextFitEnabled( enabled ); + if( isMinSizeSet ) + { + impl.mController->SetTextFitMinSize( minSize, type ); + } + if( isMaxSizeSet ) + { + impl.mController->SetTextFitMaxSize( maxSize, type ); + } + if( isStepSizeSet ) + { + impl.mController->SetTextFitStepSize( stepSize, type ); + } + } + break; + } + case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE: + { + if( impl.mController ) + { + const float lineSize = value.Get(); + + if( impl.mController->SetDefaultLineSize( lineSize ) ) + { + impl.mTextUpdateNeeded = true; + } + } + break; + } } // Request relayout when text update is needed. It's necessary to call it @@ -550,10 +578,6 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr impl.RequestTextRelayout(); } } - - - - } Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index ) @@ -643,46 +667,6 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR ); break; } - case Toolkit::TextLabel::Property::SHADOW_OFFSET: - { - if ( impl.mController ) - { - value = impl.mController->GetShadowOffset(); - } - break; - } - case Toolkit::TextLabel::Property::SHADOW_COLOR: - { - if ( impl.mController ) - { - value = impl.mController->GetShadowColor(); - } - break; - } - case Toolkit::TextLabel::Property::UNDERLINE_COLOR: - { - if ( impl.mController ) - { - value = impl.mController->GetUnderlineColor(); - } - break; - } - case Toolkit::TextLabel::Property::UNDERLINE_ENABLED: - { - if ( impl.mController ) - { - value = impl.mController->IsUnderlineEnabled(); - } - break; - } - case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT: - { - if ( impl.mController ) - { - value = impl.mController->GetUnderlineHeight(); - } - break; - } case Toolkit::TextLabel::Property::ENABLE_MARKUP: { if( impl.mController ) @@ -842,6 +826,36 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde value = impl.mController->IsIgnoreSpacesAfterText(); break; } + case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + value = impl.mController->IsMatchSystemLanguageDirection(); + break; + } + case Toolkit::DevelTextLabel::Property::TEXT_FIT: + { + const bool enabled = impl.mController->IsTextFitEnabled(); + const float minSize = impl.mController->GetTextFitMinSize(); + const float maxSize = impl.mController->GetTextFitMaxSize(); + const float stepSize = impl.mController->GetTextFitStepSize(); + + Property::Map map; + map.Insert( TEXT_FIT_ENABLE_KEY, enabled ); + map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize ); + map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize ); + map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize ); + map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" ); + + value = map; + break; + } + case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE: + { + if( impl.mController ) + { + value = impl.mController->GetDefaultLineSize(); + } + break; + } } } @@ -873,6 +887,11 @@ void TextLabel::OnInitialize() // Enable the text ellipsis. mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow + // Sets layoutDirection value + Dali::Stage stage = Dali::Stage::GetCurrent(); + Dali::LayoutDirection::Type layoutDirection = static_cast( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + mController->SetLayoutDirection( layoutDirection ); + Layout::Engine& engine = mController->GetLayoutEngine(); engine.SetCursorWidth( 0u ); // Do not layout space for the cursor. } @@ -962,7 +981,16 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) ); - const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize ); + if( mController->IsTextFitEnabled() ) + { + mController->FitPointSizeforLayout( contentSize ); + mController->SetTextFitContentSize( contentSize ); + } + + // Support Right-To-Left + Dali::LayoutDirection::Type layoutDirection = static_cast( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + + const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection ); if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) || mTextUpdateNeeded ) @@ -973,7 +1001,6 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) TextVisual::EnableRendererUpdate( mVisual ); // Support Right-To-Left of padding - Dali::LayoutDirection::Type layoutDirection = static_cast( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) { std::swap( padding.start, padding.end ); @@ -1019,7 +1046,7 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) void TextLabel::RequestTextRelayout() { RelayoutRequest(); - Toolkit::DevelControl::RequestLayout( *this ); + // Signal that a Relayout may be needed } void TextLabel::SetUpAutoScrolling()