2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/public-api/text/layouts/layout-engine.h>
27 #include <dali-toolkit/public-api/text/rendering/text-backend.h>
29 using Dali::Toolkit::Text::LayoutEngine;
30 using Dali::Toolkit::Text::Backend;
35 const unsigned int DEFAULT_RENDERING_BACKEND = 0;
45 const Property::Index TextLabel::PROPERTY_RENDERING_BACKEND( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX );
46 const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 1 );
47 const Property::Index TextLabel::PROPERTY_MULTI_LINE( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 2 );
58 return Toolkit::TextLabel::New();
61 TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create );
63 PropertyRegistration property1( mType, "rendering-backend", Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND, Property::INTEGER, &TextLabel::SetProperty, &TextLabel::GetProperty );
64 PropertyRegistration property2( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
65 PropertyRegistration property3( mType, "multi-line", Toolkit::TextLabel::PROPERTY_MULTI_LINE, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
69 Toolkit::TextLabel TextLabel::New()
71 // Create the implementation, temporarily owned by this handle on stack
72 IntrusivePtr< TextLabel > impl = new TextLabel();
74 // Pass ownership to CustomActor handle
75 Toolkit::TextLabel handle( *impl );
77 // Second-phase init of the implementation
78 // This can only be done after the CustomActor connection has been made...
84 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
86 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
90 TextLabel& impl( GetImpl( label ) );
93 case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND:
95 unsigned int backend = value.Get< int >();
97 if( impl.mRenderingBackend != backend )
99 impl.mRenderingBackend = static_cast< unsigned int >( backend );
100 impl.mRenderer.Reset();
104 case Toolkit::TextLabel::PROPERTY_TEXT:
106 if( impl.mController )
108 impl.mController->SetText( value.Get< std::string >() );
112 case Toolkit::TextLabel::PROPERTY_MULTI_LINE:
114 if( impl.mController )
116 LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX;
117 impl.mController->GetLayoutEngine().SetLayout( layout );
125 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
127 Property::Value value;
129 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
133 TextLabel& impl( GetImpl( label ) );
136 case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND:
138 value = impl.mRenderingBackend;
142 case Toolkit::TextLabel::PROPERTY_TEXT:
144 DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
148 case Toolkit::TextLabel::PROPERTY_MULTI_LINE:
150 if( impl.mController )
152 value = impl.mController->GetLayoutEngine().GetLayout();
162 void TextLabel::OnInitialize()
164 mController = Text::Controller::New( *this );
167 Vector3 TextLabel::GetNaturalSize()
169 return mController->GetNaturalSize();
172 float TextLabel::GetHeightForWidth( float width )
174 return mController->GetHeightForWidth( width );
177 void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container )
179 if( mController->Relayout( size ) )
183 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
188 Actor renderableActor = mRenderer->Render( mController->GetView() );
190 if( renderableActor )
192 Self().Add( renderableActor );
198 void TextLabel::RequestTextRelayout()
203 TextLabel::TextLabel()
204 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
205 mRenderingBackend( DEFAULT_RENDERING_BACKEND )
209 TextLabel::~TextLabel()
213 } // namespace Internal
215 } // namespace Toolkit