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=bb40d0044af9f085db3b670855732204cdebfadc;hp=148462a189cb42eb9e47b58761ab77480bdee516;hb=9346cf33ef49063185d54fbbfc186864d96c51ca;hpb=182df666bc90e1a752537bdf933941aceef37304 diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 148462a..bb40d00 100644 --- 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) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -44,6 +44,8 @@ #include #include +#include + using namespace Dali::Toolkit::Text; namespace Dali @@ -58,6 +60,19 @@ namespace Internal namespace { const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; + + /** + * @brief How the text visual should be aligned vertically inside the control. + * + * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom. + * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations). + */ + const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] = + { + 0.0f, // VerticalAlignment::TOP + 0.5f, // VerticalAlignment::CENTER + 1.0f // VerticalAlignment::BOTTOM + }; } namespace @@ -113,6 +128,10 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE ) DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION ) +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_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 ) @@ -407,8 +426,12 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController ) { const float lineSpacing = value.Get(); - impl.mController->SetDefaultLineSpacing( lineSpacing ); - impl.mTextUpdateNeeded = true; + + // Don't trigger anything if the line spacing didn't change + if( impl.mController->SetDefaultLineSpacing( lineSpacing ) ) + { + impl.mTextUpdateNeeded = true; + } } break; } @@ -486,8 +509,51 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT: + { + if( impl.mController && impl.mController->GetTextModel() ) + { + DevelText::VerticalLineAlignment::Type alignment = static_cast( value.Get() ); + + impl.mController->SetVerticalLineAlignment( alignment ); + + // Property doesn't affect the layout, only Visual must be updated + TextVisual::EnableRendererUpdate( impl.mVisual ); + + // No need to trigger full re-layout. Instead call UpdateRenderer() directly + TextVisual::UpdateRenderer( impl.mVisual ); + } + break; + } + case Toolkit::DevelTextLabel::Property::BACKGROUND: + { + const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT ); + if( update ) + { + impl.mTextUpdateNeeded = true; + } + break; + } + case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT: + { + impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >()); + break; + } + } + + // Request relayout when text update is needed. It's necessary to call it + // as changing the property not via UI interaction brings no effect if only + // the mTextUpdateNeeded is changed. + if( impl.mTextUpdateNeeded ) + { + // need to request relayout as size of text may have changed + impl.RequestTextRelayout(); } } + + + + } Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index ) @@ -750,6 +816,32 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION: + { + if( impl.mController ) + { + value = impl.mController->GetTextDirection(); + } + break; + } + case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT: + { + if( impl.mController ) + { + value = impl.mController->GetVerticalLineAlignment(); + } + break; + } + case Toolkit::DevelTextLabel::Property::BACKGROUND: + { + GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT ); + break; + } + case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT: + { + value = impl.mController->IsIgnoreSpacesAfterText(); + break; + } } } @@ -819,13 +911,21 @@ void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange:: Vector3 TextLabel::GetNaturalSize() { - return mController->GetNaturalSize(); + Extents padding; + padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); + + Vector3 naturalSize = mController->GetNaturalSize(); + naturalSize.width += ( padding.start + padding.end ); + naturalSize.height += ( padding.top + padding.bottom ); + + return naturalSize; } float TextLabel::GetHeightForWidth( float width ) { - Padding padding; - Self().GetPadding( padding ); + Extents padding; + padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); + return mController->GetHeightForWidth( width ) + padding.top + padding.bottom; } @@ -857,9 +957,10 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) { DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" ); - Padding padding; - Self().GetPadding( padding ); - Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) ); + Extents padding; + padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); + + Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) ); const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize ); @@ -871,13 +972,36 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) // Update the visual TextVisual::EnableRendererUpdate( mVisual ); - Padding padding; - Self().GetPadding( padding ); + // 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 ); + } + + // Calculate the size of the visual that can fit the text + Size layoutSize = mController->GetTextModel()->GetLayoutSize(); + layoutSize.x = contentSize.x; + + const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset(); + if ( shadowOffset.y > Math::MACHINE_EPSILON_1 ) + { + layoutSize.y += shadowOffset.y; + } + + float outlineWidth = mController->GetTextModel()->GetOutlineWidth(); + layoutSize.y += outlineWidth * 2.0f; + layoutSize.y = std::min( layoutSize.y, contentSize.y ); + + // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment. + Vector2 alignmentOffset; + alignmentOffset.x = 0.0f; + alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()]; Property::Map visualTransform; - visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize ) + visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize ) .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ) - .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) ) + .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset ) .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) ) .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN ); @@ -895,6 +1019,7 @@ void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container ) void TextLabel::RequestTextRelayout() { RelayoutRequest(); + Toolkit::DevelControl::RequestLayout( *this ); } void TextLabel::SetUpAutoScrolling() @@ -937,7 +1062,7 @@ void TextLabel::SetUpAutoScrolling() Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() ); - PixelData data = typesetter->Render( verifiedSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment + PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, data.GetPixelFormat(), data.GetWidth(),