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 )
112 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
114 DALI_TYPE_REGISTRATION_END()
118 Toolkit::TextLabel TextLabel::New()
120 // Create the implementation, temporarily owned by this handle on stack
121 IntrusivePtr< TextLabel > impl = new TextLabel();
123 // Pass ownership to CustomActor handle
124 Toolkit::TextLabel handle( *impl );
126 // Second-phase init of the implementation
127 // This can only be done after the CustomActor connection has been made...
133 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
135 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
139 TextLabel& impl( GetImpl( label ) );
142 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
144 int backend = value.Get< int >();
146 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
147 if( Text::RENDERING_VECTOR_BASED == backend )
149 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
152 if( impl.mRenderingBackend != backend )
154 impl.mRenderingBackend = backend;
155 impl.mRenderer.Reset();
157 if( impl.mController )
159 // When using the vector-based rendering, the size of the GLyphs are different
160 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
161 impl.mController->SetGlyphType( glyphType );
166 case Toolkit::TextLabel::Property::TEXT:
168 if( impl.mController )
170 impl.mController->SetText( value.Get< std::string >() );
174 case Toolkit::TextLabel::Property::FONT_FAMILY:
176 if( impl.mController )
178 const std::string& fontFamily = value.Get< std::string >();
180 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
181 impl.mController->SetDefaultFontFamily( fontFamily );
185 case Toolkit::TextLabel::Property::FONT_STYLE:
187 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
190 case Toolkit::TextLabel::Property::POINT_SIZE:
192 if( impl.mController )
194 const float pointSize = value.Get< float >();
196 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
198 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
203 case Toolkit::TextLabel::Property::MULTI_LINE:
205 if( impl.mController )
207 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
211 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
213 if( impl.mController )
215 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
216 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
217 HORIZONTAL_ALIGNMENT_STRING_TABLE,
218 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
221 impl.mController->SetHorizontalAlignment( alignment );
226 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
228 if( impl.mController )
230 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
231 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
232 VERTICAL_ALIGNMENT_STRING_TABLE,
233 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
236 impl.mController->SetVerticalAlignment( alignment );
242 case Toolkit::TextLabel::Property::TEXT_COLOR:
244 if( impl.mController )
246 const Vector4& textColor = value.Get< Vector4 >();
247 if( impl.mController->GetDefaultColor() != textColor )
249 impl.mController->SetDefaultColor( textColor );
250 impl.mRenderer.Reset();
256 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
258 if( impl.mController )
260 const Vector2& shadowOffset = value.Get< Vector2 >();
261 if ( impl.mController->GetShadowOffset() != shadowOffset )
263 impl.mController->SetShadowOffset( shadowOffset );
264 impl.mRenderer.Reset();
269 case Toolkit::TextLabel::Property::SHADOW_COLOR:
271 if( impl.mController )
273 const Vector4& shadowColor = value.Get< Vector4 >();
274 if ( impl.mController->GetShadowColor() != shadowColor )
276 impl.mController->SetShadowColor( shadowColor );
277 impl.mRenderer.Reset();
282 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
284 if( impl.mController )
286 const Vector4& color = value.Get< Vector4 >();
287 if ( impl.mController->GetUnderlineColor() != color )
289 impl.mController->SetUnderlineColor( color );
290 impl.mRenderer.Reset();
295 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
297 if( impl.mController )
299 const bool enabled = value.Get< bool >();
300 if ( impl.mController->IsUnderlineEnabled() != enabled )
302 impl.mController->SetUnderlineEnabled( enabled );
303 impl.mRenderer.Reset();
309 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
311 if( impl.mController )
313 float height = value.Get< float >();
314 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
316 impl.mController->SetUnderlineHeight( height );
317 impl.mRenderer.Reset();
322 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
324 if( impl.mController )
326 const bool enableMarkup = value.Get<bool>();
327 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
331 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
333 if( impl.mController )
335 const bool enableAutoScroll = value.Get<bool>();
336 // If request to auto scroll is the same as current state then do nothing.
337 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
339 // If request is disable (false) and auto scrolling is enabled then need to stop it
340 if ( enableAutoScroll == false )
342 if( impl.mTextScroller )
344 impl.mTextScroller->SetLoopCount( 0 ); // Causes the current animation to finish playing (0)
347 // If request is enable (true) then start autoscroll as not already running
350 impl.mController->SetTextElideEnabled( false );
351 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
357 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
359 if( !impl.mTextScroller )
361 impl.mTextScroller = Text::TextScroller::New( impl );
363 impl.mTextScroller->SetSpeed( value.Get<int>() );
366 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
368 if( !impl.mTextScroller )
370 impl.mTextScroller = Text::TextScroller::New( impl );
372 impl.mTextScroller->SetLoopCount( value.Get<int>() );
375 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
377 if( !impl.mTextScroller )
379 impl.mTextScroller = Text::TextScroller::New( impl );
381 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
384 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
386 if( !impl.mTextScroller )
388 impl.mTextScroller = Text::TextScroller::New( impl );
390 impl.mTextScroller->SetGap( value.Get<float>() );
393 case Toolkit::TextLabel::Property::LINE_SPACING:
395 if( impl.mController )
397 const float lineSpacing = value.Get<float>();
398 impl.mController->SetDefaultLineSpacing( lineSpacing );
399 impl.mRenderer.Reset();
403 case Toolkit::TextLabel::Property::UNDERLINE:
405 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
408 impl.mRenderer.Reset();
412 case Toolkit::TextLabel::Property::SHADOW:
414 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
417 impl.mRenderer.Reset();
421 case Toolkit::TextLabel::Property::EMBOSS:
423 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
426 impl.mRenderer.Reset();
430 case Toolkit::TextLabel::Property::OUTLINE:
432 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
435 impl.mRenderer.Reset();
439 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
441 if( impl.mController )
443 const float pixelSize = value.Get< float >();
444 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
446 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
448 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
453 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
455 if( impl.mController )
457 const bool ellipsis = value.Get<bool>();
458 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
460 impl.mController->SetTextElideEnabled( ellipsis );
468 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
470 Property::Value value;
472 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
476 TextLabel& impl( GetImpl( label ) );
479 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
481 value = impl.mRenderingBackend;
484 case Toolkit::TextLabel::Property::TEXT:
486 if( impl.mController )
489 impl.mController->GetText( text );
494 case Toolkit::TextLabel::Property::FONT_FAMILY:
496 if( impl.mController )
498 value = impl.mController->GetDefaultFontFamily();
502 case Toolkit::TextLabel::Property::FONT_STYLE:
504 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
507 case Toolkit::TextLabel::Property::POINT_SIZE:
509 if( impl.mController )
511 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
515 case Toolkit::TextLabel::Property::MULTI_LINE:
517 if( impl.mController )
519 value = impl.mController->IsMultiLineEnabled();
523 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
525 if( impl.mController )
527 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
528 HORIZONTAL_ALIGNMENT_STRING_TABLE,
529 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
532 value = std::string( name );
537 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
539 if( impl.mController )
541 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
542 VERTICAL_ALIGNMENT_STRING_TABLE,
543 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
546 value = std::string( name );
551 case Toolkit::TextLabel::Property::TEXT_COLOR:
553 if ( impl.mController )
555 value = impl.mController->GetDefaultColor();
559 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
561 if ( impl.mController )
563 value = impl.mController->GetShadowOffset();
567 case Toolkit::TextLabel::Property::SHADOW_COLOR:
569 if ( impl.mController )
571 value = impl.mController->GetShadowColor();
575 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
577 if ( impl.mController )
579 value = impl.mController->GetUnderlineColor();
583 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
585 if ( impl.mController )
587 value = impl.mController->IsUnderlineEnabled();
591 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
593 if ( impl.mController )
595 value = impl.mController->GetUnderlineHeight();
599 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
601 if( impl.mController )
603 value = impl.mController->IsMarkupProcessorEnabled();
607 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
609 if( impl.mController )
611 value = impl.mController->IsAutoScrollEnabled();
615 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
617 TextLabel& impl( GetImpl( label ) );
618 if ( impl.mTextScroller )
620 value = impl.mTextScroller->GetSpeed();
624 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
626 if( impl.mController )
628 TextLabel& impl( GetImpl( label ) );
629 if ( impl.mTextScroller )
631 value = impl.mTextScroller->GetLoopCount();
636 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
638 if( impl.mController )
640 TextLabel& impl( GetImpl( label ) );
641 if ( impl.mTextScroller )
643 value = impl.mTextScroller->GetLoopDelay();
648 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
650 TextLabel& impl( GetImpl( label ) );
651 if ( impl.mTextScroller )
653 value = impl.mTextScroller->GetGap();
657 case Toolkit::TextLabel::Property::LINE_SPACING:
659 if( impl.mController )
661 value = impl.mController->GetDefaultLineSpacing();
665 case Toolkit::TextLabel::Property::UNDERLINE:
667 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
670 case Toolkit::TextLabel::Property::SHADOW:
672 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
675 case Toolkit::TextLabel::Property::EMBOSS:
677 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
680 case Toolkit::TextLabel::Property::OUTLINE:
682 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
685 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
687 if( impl.mController )
689 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
693 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
695 if( impl.mController )
697 value = impl.mController->IsTextElideEnabled();
707 void TextLabel::OnInitialize()
711 mController = Text::Controller::New( this );
713 // When using the vector-based rendering, the size of the GLyphs are different
714 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
715 mController->SetGlyphType( glyphType );
717 // Use height-for-width negotiation by default
718 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
719 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
721 // Enable the text ellipsis.
722 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
724 Layout::Engine& engine = mController->GetLayoutEngine();
725 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
727 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
730 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
732 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
736 case StyleChange::DEFAULT_FONT_CHANGE:
738 // Property system did not set the font so should update it.
739 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
740 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
741 mController->UpdateAfterFontChange( newFont );
745 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
747 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
751 case StyleChange::THEME_CHANGE:
753 // Nothing to do, let control base class handle this
758 // Up call to Control
759 Control::OnStyleChange( styleManager, change );
762 Vector3 TextLabel::GetNaturalSize()
764 return mController->GetNaturalSize();
767 float TextLabel::GetHeightForWidth( float width )
769 return mController->GetHeightForWidth( width );
772 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
774 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
776 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
778 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
783 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
789 void TextLabel::RequestTextRelayout()
794 void TextLabel::RenderText()
796 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
799 Actor renderableActor;
801 float alignmentOffset = 0.f;
804 renderableActor = mRenderer->Render( mController->GetView(),
806 DepthIndex::CONTENT );
809 if( renderableActor != mRenderableActor )
811 UnparentAndReset( mRenderableActor );
813 if( renderableActor )
815 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
816 renderableActor.SetPosition( scrollOffset.x + alignmentOffset, scrollOffset.y );
818 self.Add( renderableActor );
820 mRenderableActor = renderableActor;
822 if ( mController->IsAutoScrollEnabled() )
824 SetUpAutoScrolling();
829 void TextLabel::SetUpAutoScrolling()
831 const Size& controlSize = mController->GetView().GetControlSize();
832 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.
833 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
834 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
836 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
837 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
839 if ( !mTextScroller )
841 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
843 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
844 mTextScroller = Text::TextScroller::New( *this );
846 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset );
849 self.Add( mTextScroller->GetScrollingText() );
850 self.Add( mTextScroller->GetSourceCamera() );
853 void TextLabel::OnStageConnect( Dali::Actor actor )
855 if ( mHasBeenStaged )
861 mHasBeenStaged = true;
865 void TextLabel::ScrollingFinished()
867 // Pure Virtual from TextScroller Interface
868 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
869 mController->SetAutoScrollEnabled( false );
870 mController->SetTextElideEnabled( true );
871 RequestTextRelayout();
874 TextLabel::TextLabel()
875 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
876 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
877 mHasBeenStaged( false )
881 TextLabel::~TextLabel()
885 } // namespace Internal
887 } // namespace Toolkit