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=00ae80df7489265411371ee6314faa5b089492c4;hp=93c550076d0b0171d94007ea0f019c0814dbfa3b;hb=a3390cb9c1cd0aeddbcd4aa89d6045592a123dd3;hpb=53daf86a69225c2409e7912a0b4a99c7bc28c852 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 93c5500..00ae80d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -20,18 +20,17 @@ // EXTERNAL INCLUDES #include +#include #include // INTERNAL INCLUDES -#include -#include // TODO - Get from RendererFactory +#include +#include +#include +#include using Dali::Toolkit::Text::LayoutEngine; - -namespace -{ - -} // namespace +using Dali::Toolkit::Text::Backend; namespace Dali { @@ -39,14 +38,16 @@ 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 ); - namespace Internal { namespace { + const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; +} + +namespace +{ // Type registration BaseHandle Create() @@ -54,10 +55,17 @@ BaseHandle Create() return Toolkit::TextLabel::New(); } -TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create ); +// Setup properties, signals and actions using the type-registry. +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, 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 ); +DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND ) +DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT ) +DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY ) +DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE ) +DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE ) +DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE ) + +DALI_TYPE_REGISTRATION_END() } // namespace @@ -76,28 +84,91 @@ 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_TEXT: + case Toolkit::TextLabel::Property::RENDERING_BACKEND: + { + int backend = value.Get< int >(); + + if( impl.mRenderingBackend != backend ) + { + impl.mRenderingBackend = backend; + impl.mRenderer.Reset(); + impl.RequestTextRelayout(); + } + break; + } + case Toolkit::TextLabel::Property::TEXT: + { + if( impl.mController ) + { + impl.mController->SetText( value.Get< std::string >() ); + impl.RequestTextRelayout(); + } + break; + } + case Toolkit::TextLabel::Property::FONT_FAMILY: + { + if( impl.mController ) + { + std::string fontFamily = value.Get< std::string >(); + + if( impl.mController->GetDefaultFontFamily() != fontFamily ) + { + impl.mController->SetDefaultFontFamily( fontFamily ); + impl.RequestTextRelayout(); + } + } + break; + } + case Toolkit::TextLabel::Property::FONT_STYLE: + { + if( impl.mController ) + { + std::string fontStyle = value.Get< std::string >(); + + if( impl.mController->GetDefaultFontStyle() != fontStyle ) + { + impl.mController->SetDefaultFontStyle( fontStyle ); + impl.RequestTextRelayout(); + } + } + break; + } + case Toolkit::TextLabel::Property::POINT_SIZE: { - labelImpl.SetText( value.Get< std::string >() ); + if( impl.mController ) + { + float pointSize = value.Get< float >(); + + if( impl.mController->GetDefaultPointSize() != pointSize /*TODO - epsilon*/ ) + { + impl.mController->SetDefaultPointSize( pointSize ); + impl.RequestTextRelayout(); + } + } break; } - case Toolkit::TextLabel::PROPERTY_MULTI_LINE: + case Toolkit::TextLabel::Property::MULTI_LINE: { - labelImpl.SetMultiLine( value.Get< bool >() ); + if( impl.mController ) + { + LayoutEngine& engine = impl.mController->GetLayoutEngine(); + LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX; + + if( engine.GetLayout() != layout ) + { + impl.mController->GetLayoutEngine().SetLayout( layout ); + impl.RequestTextRelayout(); + } + } break; } } @@ -112,11 +183,30 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde if( label ) { + TextLabel& impl( GetImpl( label ) ); switch( index ) { - case Toolkit::TextLabel::PROPERTY_TEXT: + case Toolkit::TextLabel::Property::RENDERING_BACKEND: + { + value = impl.mRenderingBackend; + break; + } + case Toolkit::TextLabel::Property::TEXT: + { + if( impl.mController ) + { + std::string text; + impl.mController->GetText( text ); + value = text; + } + break; + } + case Toolkit::TextLabel::Property::MULTI_LINE: { - DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" ); + if( impl.mController ) + { + value = static_cast( LayoutEngine::MULTI_LINE_BOX == impl.mController->GetLayoutEngine().GetLayout() ); + } break; } } @@ -127,7 +217,12 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde void TextLabel::OnInitialize() { - mController = Text::Controller::New(); + mController = Text::Controller::New( *this ); +} + +void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change ) +{ + GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); } Vector3 TextLabel::GetNaturalSize() @@ -142,52 +237,42 @@ float TextLabel::GetHeightForWidth( float width ) void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container ) { - if( mController->Relayout( size ) ) + if( mController->Relayout( size ) || + !mRenderer ) { if( !mRenderer ) { - // TODO - Get from RendererFactory - mRenderer = Dali::Toolkit::Text::BasicRenderer::New(); + mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); } + RenderableActor renderableActor; if( mRenderer ) { - Actor renderableActor = mRenderer->Render( mController->GetView() ); + renderableActor = mRenderer->Render( mController->GetView() ); + } + + if( renderableActor != mRenderableActor ) + { + UnparentAndReset( mRenderableActor ); if( renderableActor ) { Self().Add( renderableActor ); } - } - } -} -void TextLabel::SetText( const std::string& text ) -{ - if( mController ) - { - // The Controller updates the View for the renderer - mController->SetText( text ); + mRenderableActor = renderableActor; + } } } -void TextLabel::SetMultiLine( bool multiLine ) +void TextLabel::RequestTextRelayout() { - 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( REQUIRES_STYLE_CHANGE_SIGNALS ) ), + mRenderingBackend( DEFAULT_RENDERING_BACKEND ) { }