2 * Copyright (c) 2017 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-helper.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/public-api/text/rendering-backend.h>
28 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
29 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
30 #include <dali-toolkit/internal/text/property-string-parser.h>
31 #include <dali-toolkit/internal/text/rendering/text-backend.h>
32 #include <dali-toolkit/internal/text/text-effects-style.h>
33 #include <dali-toolkit/internal/text/text-font-style.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/text/text-definitions.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
51 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 #if defined ( DEBUG_ENABLED )
58 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
61 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
63 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
64 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
65 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
67 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
69 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
71 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
72 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
73 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
75 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
80 return Toolkit::TextLabel::New();
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
110 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
111 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
113 DALI_TYPE_REGISTRATION_END()
117 Toolkit::TextLabel TextLabel::New()
119 // Create the implementation, temporarily owned by this handle on stack
120 IntrusivePtr< TextLabel > impl = new TextLabel();
122 // Pass ownership to CustomActor handle
123 Toolkit::TextLabel handle( *impl );
125 // Second-phase init of the implementation
126 // This can only be done after the CustomActor connection has been made...
132 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
134 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
138 TextLabel& impl( GetImpl( label ) );
141 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
143 int backend = value.Get< int >();
145 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
146 if( Text::RENDERING_VECTOR_BASED == backend )
148 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
151 if( impl.mRenderingBackend != backend )
153 impl.mRenderingBackend = backend;
154 impl.mRenderer.Reset();
156 if( impl.mController )
158 // When using the vector-based rendering, the size of the GLyphs are different
159 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
160 impl.mController->SetGlyphType( glyphType );
165 case Toolkit::TextLabel::Property::TEXT:
167 if( impl.mController )
169 impl.mController->SetText( value.Get< std::string >() );
173 case Toolkit::TextLabel::Property::FONT_FAMILY:
175 if( impl.mController )
177 const std::string& fontFamily = value.Get< std::string >();
179 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
180 impl.mController->SetDefaultFontFamily( fontFamily );
184 case Toolkit::TextLabel::Property::FONT_STYLE:
186 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
189 case Toolkit::TextLabel::Property::POINT_SIZE:
191 if( impl.mController )
193 const float pointSize = value.Get< float >();
195 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
197 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
202 case Toolkit::TextLabel::Property::MULTI_LINE:
204 if( impl.mController )
206 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
210 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
212 if( impl.mController )
214 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
215 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
216 HORIZONTAL_ALIGNMENT_STRING_TABLE,
217 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
220 impl.mController->SetHorizontalAlignment( alignment );
225 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
227 if( impl.mController )
229 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
230 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
231 VERTICAL_ALIGNMENT_STRING_TABLE,
232 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
235 impl.mController->SetVerticalAlignment( alignment );
241 case Toolkit::TextLabel::Property::TEXT_COLOR:
243 if( impl.mController )
245 const Vector4& textColor = value.Get< Vector4 >();
246 if( impl.mController->GetDefaultColor() != textColor )
248 impl.mController->SetDefaultColor( textColor );
249 impl.mRenderer.Reset();
255 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
257 if( impl.mController )
259 const Vector2& shadowOffset = value.Get< Vector2 >();
260 if ( impl.mController->GetShadowOffset() != shadowOffset )
262 impl.mController->SetShadowOffset( shadowOffset );
263 impl.mRenderer.Reset();
268 case Toolkit::TextLabel::Property::SHADOW_COLOR:
270 if( impl.mController )
272 const Vector4& shadowColor = value.Get< Vector4 >();
273 if ( impl.mController->GetShadowColor() != shadowColor )
275 impl.mController->SetShadowColor( shadowColor );
276 impl.mRenderer.Reset();
281 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
283 if( impl.mController )
285 const Vector4& color = value.Get< Vector4 >();
286 if ( impl.mController->GetUnderlineColor() != color )
288 impl.mController->SetUnderlineColor( color );
289 impl.mRenderer.Reset();
294 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
296 if( impl.mController )
298 const bool enabled = value.Get< bool >();
299 if ( impl.mController->IsUnderlineEnabled() != enabled )
301 impl.mController->SetUnderlineEnabled( enabled );
302 impl.mRenderer.Reset();
308 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
310 if( impl.mController )
312 float height = value.Get< float >();
313 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
315 impl.mController->SetUnderlineHeight( height );
316 impl.mRenderer.Reset();
321 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
323 if( impl.mController )
325 const bool enableMarkup = value.Get<bool>();
326 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
330 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
332 if( impl.mController )
334 const bool enableAutoScroll = value.Get<bool>();
335 // If request to auto scroll is the same as current state then do nothing.
336 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
338 // If request is disable (false) and auto scrolling is enabled then need to stop it
339 if ( enableAutoScroll == false )
341 if( impl.mTextScroller )
343 impl.mTextScroller->SetLoopCount( 0 ); // Causes the current animation to finish playing (0)
346 // If request is enable (true) then start autoscroll as not already running
349 impl.mController->SetTextElideEnabled( false );
350 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
356 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
358 if( !impl.mTextScroller )
360 impl.mTextScroller = Text::TextScroller::New( impl );
362 impl.mTextScroller->SetSpeed( value.Get<int>() );
365 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
367 if( !impl.mTextScroller )
369 impl.mTextScroller = Text::TextScroller::New( impl );
371 impl.mTextScroller->SetLoopCount( value.Get<int>() );
374 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
376 if( !impl.mTextScroller )
378 impl.mTextScroller = Text::TextScroller::New( impl );
380 impl.mTextScroller->SetGap( value.Get<float>() );
383 case Toolkit::TextLabel::Property::LINE_SPACING:
385 if( impl.mController )
387 const float lineSpacing = value.Get<float>();
388 impl.mController->SetDefaultLineSpacing( lineSpacing );
389 impl.mRenderer.Reset();
393 case Toolkit::TextLabel::Property::UNDERLINE:
395 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
398 impl.mRenderer.Reset();
402 case Toolkit::TextLabel::Property::SHADOW:
404 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
407 impl.mRenderer.Reset();
411 case Toolkit::TextLabel::Property::EMBOSS:
413 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
416 impl.mRenderer.Reset();
420 case Toolkit::TextLabel::Property::OUTLINE:
422 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
425 impl.mRenderer.Reset();
429 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
431 if( impl.mController )
433 const float pixelSize = value.Get< float >();
434 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
436 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
438 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
443 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
445 if( impl.mController )
447 const bool ellipsis = value.Get<bool>();
448 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
450 impl.mController->SetTextElideEnabled( ellipsis );
458 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
460 Property::Value value;
462 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
466 TextLabel& impl( GetImpl( label ) );
469 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
471 value = impl.mRenderingBackend;
474 case Toolkit::TextLabel::Property::TEXT:
476 if( impl.mController )
479 impl.mController->GetText( text );
484 case Toolkit::TextLabel::Property::FONT_FAMILY:
486 if( impl.mController )
488 value = impl.mController->GetDefaultFontFamily();
492 case Toolkit::TextLabel::Property::FONT_STYLE:
494 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
497 case Toolkit::TextLabel::Property::POINT_SIZE:
499 if( impl.mController )
501 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
505 case Toolkit::TextLabel::Property::MULTI_LINE:
507 if( impl.mController )
509 value = impl.mController->IsMultiLineEnabled();
513 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
515 if( impl.mController )
517 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
518 HORIZONTAL_ALIGNMENT_STRING_TABLE,
519 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
522 value = std::string( name );
527 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
529 if( impl.mController )
531 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
532 VERTICAL_ALIGNMENT_STRING_TABLE,
533 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
536 value = std::string( name );
541 case Toolkit::TextLabel::Property::TEXT_COLOR:
543 if ( impl.mController )
545 value = impl.mController->GetDefaultColor();
549 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
551 if ( impl.mController )
553 value = impl.mController->GetShadowOffset();
557 case Toolkit::TextLabel::Property::SHADOW_COLOR:
559 if ( impl.mController )
561 value = impl.mController->GetShadowColor();
565 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
567 if ( impl.mController )
569 value = impl.mController->GetUnderlineColor();
573 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
575 if ( impl.mController )
577 value = impl.mController->IsUnderlineEnabled();
581 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
583 if ( impl.mController )
585 value = impl.mController->GetUnderlineHeight();
589 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
591 if( impl.mController )
593 value = impl.mController->IsMarkupProcessorEnabled();
597 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
599 if( impl.mController )
601 value = impl.mController->IsAutoScrollEnabled();
605 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
607 TextLabel& impl( GetImpl( label ) );
608 if ( impl.mTextScroller )
610 value = impl.mTextScroller->GetSpeed();
614 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
616 if( impl.mController )
618 TextLabel& impl( GetImpl( label ) );
619 if ( impl.mTextScroller )
621 value = impl.mTextScroller->GetLoopCount();
626 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
628 TextLabel& impl( GetImpl( label ) );
629 if ( impl.mTextScroller )
631 value = impl.mTextScroller->GetGap();
635 case Toolkit::TextLabel::Property::LINE_SPACING:
637 if( impl.mController )
639 value = impl.mController->GetDefaultLineSpacing();
643 case Toolkit::TextLabel::Property::UNDERLINE:
645 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
648 case Toolkit::TextLabel::Property::SHADOW:
650 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
653 case Toolkit::TextLabel::Property::EMBOSS:
655 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
658 case Toolkit::TextLabel::Property::OUTLINE:
660 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
663 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
665 if( impl.mController )
667 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
671 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
673 if( impl.mController )
675 value = impl.mController->IsTextElideEnabled();
685 void TextLabel::OnInitialize()
689 mController = Text::Controller::New( this );
691 // When using the vector-based rendering, the size of the GLyphs are different
692 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
693 mController->SetGlyphType( glyphType );
695 // Use height-for-width negotiation by default
696 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
697 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
699 // Enable the text ellipsis.
700 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
702 Layout::Engine& engine = mController->GetLayoutEngine();
703 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
705 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
708 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
714 case StyleChange::DEFAULT_FONT_CHANGE:
716 // Property system did not set the font so should update it.
717 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
718 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
719 mController->UpdateAfterFontChange( newFont );
723 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
725 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
729 case StyleChange::THEME_CHANGE:
731 // Nothing to do, let control base class handle this
736 // Up call to Control
737 Control::OnStyleChange( styleManager, change );
740 Vector3 TextLabel::GetNaturalSize()
742 return mController->GetNaturalSize();
745 float TextLabel::GetHeightForWidth( float width )
747 return mController->GetHeightForWidth( width );
750 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
752 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
754 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
756 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
761 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
767 void TextLabel::RequestTextRelayout()
772 void TextLabel::RenderText()
774 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
777 Actor renderableActor;
779 float alignmentOffset = 0.f;
782 renderableActor = mRenderer->Render( mController->GetView(),
784 DepthIndex::CONTENT );
787 if( renderableActor != mRenderableActor )
789 UnparentAndReset( mRenderableActor );
791 if( renderableActor )
793 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
794 renderableActor.SetPosition( scrollOffset.x + alignmentOffset, scrollOffset.y );
796 self.Add( renderableActor );
798 mRenderableActor = renderableActor;
800 if ( mController->IsAutoScrollEnabled() )
802 SetUpAutoScrolling();
807 void TextLabel::SetUpAutoScrolling()
809 const Size& controlSize = mController->GetView().GetControlSize();
810 const Size offScreenSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
811 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
812 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
814 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
815 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
817 if ( !mTextScroller )
819 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
821 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
822 mTextScroller = Text::TextScroller::New( *this );
824 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset );
827 self.Add( mTextScroller->GetScrollingText() );
828 self.Add( mTextScroller->GetSourceCamera() );
831 void TextLabel::OnStageConnect( Dali::Actor actor )
833 if ( mHasBeenStaged )
839 mHasBeenStaged = true;
843 void TextLabel::ScrollingFinished()
845 // Pure Virtual from TextScroller Interface
846 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
847 mController->SetAutoScrollEnabled( false );
848 mController->SetTextElideEnabled( true );
849 RequestTextRelayout();
852 TextLabel::TextLabel()
853 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
854 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
855 mHasBeenStaged( false )
859 TextLabel::~TextLabel()
863 } // namespace Internal
865 } // namespace Toolkit