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/basic/text-basic-renderer.h> // TODO - Get from RendererFactory
29 using Dali::Toolkit::Text::LayoutEngine;
42 const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX );
43 const Property::Index TextLabel::PROPERTY_MULTI_LINE( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 1 );
54 return Toolkit::TextLabel::New();
57 TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create );
59 PropertyRegistration property1( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
60 PropertyRegistration property2( mType, "multi-line", Toolkit::TextLabel::PROPERTY_MULTI_LINE, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
64 Toolkit::TextLabel TextLabel::New()
66 // Create the implementation, temporarily owned by this handle on stack
67 IntrusivePtr< TextLabel > impl = new TextLabel();
69 // Pass ownership to CustomActor handle
70 Toolkit::TextLabel handle( *impl );
72 // Second-phase init of the implementation
73 // This can only be done after the CustomActor connection has been made...
79 void TextLabel::SetRenderer( Text::RendererPtr renderer )
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& labelImpl( GetImpl( label ) );
93 case Toolkit::TextLabel::PROPERTY_TEXT:
95 labelImpl.SetText( value.Get< std::string >() );
98 case Toolkit::TextLabel::PROPERTY_MULTI_LINE:
100 labelImpl.SetMultiLine( value.Get< bool >() );
107 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
109 Property::Value value;
111 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
117 case Toolkit::TextLabel::PROPERTY_TEXT:
119 DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
128 void TextLabel::OnInitialize()
130 mController = Text::Controller::New();
133 Vector3 TextLabel::GetNaturalSize()
135 return mController->GetNaturalSize();
138 float TextLabel::GetHeightForWidth( float width )
140 return mController->GetHeightForWidth( width );
143 void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container )
145 if( mController->Relayout( size ) )
149 // TODO - Get from RendererFactory
150 mRenderer = Dali::Toolkit::Text::BasicRenderer::New();
155 Actor renderableActor = mRenderer->Render( mController->GetView() );
157 if( renderableActor )
159 Self().Add( renderableActor );
165 void TextLabel::SetText( const std::string& text )
169 // The Controller updates the View for the renderer
170 mController->SetText( text );
174 void TextLabel::SetMultiLine( bool multiLine )
180 mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
184 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
189 TextLabel::TextLabel()
190 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
194 TextLabel::~TextLabel()
198 } // namespace Internal
200 } // namespace Toolkit