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=7c7de295a09ff03163ec59f6e6406a9416357ace;hp=c498f0e4ddba625f38f161e5253eee48e13483fa;hb=297b1b9a9b6ed72fe98d5afb018ff4d1c951ce7d;hpb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682 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 c498f0e..7c7de29 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -24,13 +24,16 @@ // INTERNAL INCLUDES #include -#include // TODO - Get from RendererFactory +#include using Dali::Toolkit::Text::LayoutEngine; +using Dali::Toolkit::Text::Backend; namespace { +const unsigned int DEFAULT_RENDERING_BACKEND = 0; + } // namespace namespace Dali @@ -39,8 +42,9 @@ namespace Dali namespace Toolkit { -const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX ); -const Property::Index TextLabel::PROPERTY_MULTI_LINE( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 1 ); +const Property::Index TextLabel::PROPERTY_RENDERING_BACKEND( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX ); +const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 1 ); +const Property::Index TextLabel::PROPERTY_MULTI_LINE( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 2 ); namespace Internal { @@ -56,8 +60,9 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create ); -PropertyRegistration property1( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty ); -PropertyRegistration property2( mType, "multi-line", Toolkit::TextLabel::PROPERTY_MULTI_LINE, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty ); +PropertyRegistration property1( mType, "rendering-backend", Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND, Property::INTEGER, &TextLabel::SetProperty, &TextLabel::GetProperty ); +PropertyRegistration property2( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty ); +PropertyRegistration property3( mType, "multi-line", Toolkit::TextLabel::PROPERTY_MULTI_LINE, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty ); } // namespace @@ -76,28 +81,41 @@ Toolkit::TextLabel TextLabel::New() return handle; } -void TextLabel::SetRenderer( Text::RendererPtr renderer ) -{ - mRenderer = renderer; -} - void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) { Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) ); if( label ) { - TextLabel& labelImpl( GetImpl( label ) ); + TextLabel& impl( GetImpl( label ) ); switch( index ) { + case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND: + { + unsigned int backend = value.Get< int >(); + + if( impl.mRenderingBackend != backend ) + { + impl.mRenderingBackend = static_cast< unsigned int >( backend ); + impl.mRenderer.Reset(); + } + break; + } case Toolkit::TextLabel::PROPERTY_TEXT: { - labelImpl.SetText( value.Get< std::string >() ); + if( impl.mController ) + { + impl.mController->SetText( value.Get< std::string >() ); + } break; } case Toolkit::TextLabel::PROPERTY_MULTI_LINE: { - labelImpl.SetMultiLine( value.Get< bool >() ); + if( impl.mController ) + { + LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX; + impl.mController->GetLayoutEngine().SetLayout( layout ); + } break; } } @@ -112,13 +130,29 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde if( label ) { + TextLabel& impl( GetImpl( label ) ); switch( index ) { + case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND: + { + value = impl.mRenderingBackend; + break; + } + case Toolkit::TextLabel::PROPERTY_TEXT: { DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" ); break; } + + case Toolkit::TextLabel::PROPERTY_MULTI_LINE: + { + if( impl.mController ) + { + value = impl.mController->GetLayoutEngine().GetLayout(); + } + break; + } } } @@ -127,7 +161,17 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde void TextLabel::OnInitialize() { - mController = Text::Controller::New(); + mController = Text::Controller::New( *this ); +} + +Vector3 TextLabel::GetNaturalSize() +{ + return mController->GetNaturalSize(); +} + +float TextLabel::GetHeightForWidth( float width ) +{ + return mController->GetHeightForWidth( width ); } void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container ) @@ -136,8 +180,7 @@ void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container ) { if( !mRenderer ) { - // TODO - Get from RendererFactory - mRenderer = Dali::Toolkit::Text::BasicRenderer::New(); + mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); } if( mRenderer ) @@ -152,32 +195,14 @@ void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container ) } } -void TextLabel::SetText( const std::string& text ) +void TextLabel::RequestTextRelayout() { - if( mController ) - { - // The Controller updates the View for the renderer - mController->SetText( text ); - } -} - -void TextLabel::SetMultiLine( bool multiLine ) -{ - if( mController ) - { - if( multiLine ) - { - mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX ); - } - else - { - mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX ); - } - } + RelayoutRequest(); } TextLabel::TextLabel() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ), + mRenderingBackend( DEFAULT_RENDERING_BACKEND ) { }