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 AUTO_SCROLL_STOP_MODE_TABLE[] =
63 { "IMMEDIATE", Toolkit::DevelTextLabel::AutoScrollStopMode::IMMEDIATE },
64 { "FINISH_LOOP", Toolkit::DevelTextLabel::AutoScrollStopMode::FINISH_LOOP },
66 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
68 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
70 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
71 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
72 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
74 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
76 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
78 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
79 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
80 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
82 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
87 return Toolkit::TextLabel::New();
90 // Setup properties, signals and actions using the type-registry.
91 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
117 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
118 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
119 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
120 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
122 DALI_TYPE_REGISTRATION_END()
126 Toolkit::TextLabel TextLabel::New()
128 // Create the implementation, temporarily owned by this handle on stack
129 IntrusivePtr< TextLabel > impl = new TextLabel();
131 // Pass ownership to CustomActor handle
132 Toolkit::TextLabel handle( *impl );
134 // Second-phase init of the implementation
135 // This can only be done after the CustomActor connection has been made...
141 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
143 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
147 TextLabel& impl( GetImpl( label ) );
150 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
152 int backend = value.Get< int >();
154 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
155 if( Text::RENDERING_VECTOR_BASED == backend )
157 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
160 if( impl.mRenderingBackend != backend )
162 impl.mRenderingBackend = backend;
163 impl.mRenderer.Reset();
165 if( impl.mController )
167 // When using the vector-based rendering, the size of the GLyphs are different
168 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
169 impl.mController->SetGlyphType( glyphType );
174 case Toolkit::TextLabel::Property::TEXT:
176 if( impl.mController )
178 impl.mController->SetText( value.Get< std::string >() );
182 case Toolkit::TextLabel::Property::FONT_FAMILY:
184 if( impl.mController )
186 const std::string& fontFamily = value.Get< std::string >();
188 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
189 impl.mController->SetDefaultFontFamily( fontFamily );
193 case Toolkit::TextLabel::Property::FONT_STYLE:
195 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
198 case Toolkit::TextLabel::Property::POINT_SIZE:
200 if( impl.mController )
202 const float pointSize = value.Get< float >();
204 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
206 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
211 case Toolkit::TextLabel::Property::MULTI_LINE:
213 if( impl.mController )
215 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
219 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
221 if( impl.mController )
223 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
224 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
225 HORIZONTAL_ALIGNMENT_STRING_TABLE,
226 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
229 impl.mController->SetHorizontalAlignment( alignment );
234 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
236 if( impl.mController )
238 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
239 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
240 VERTICAL_ALIGNMENT_STRING_TABLE,
241 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
244 impl.mController->SetVerticalAlignment( alignment );
250 case Toolkit::TextLabel::Property::TEXT_COLOR:
252 if( impl.mController )
254 const Vector4& textColor = value.Get< Vector4 >();
255 if( impl.mController->GetDefaultColor() != textColor )
257 impl.mController->SetDefaultColor( textColor );
258 impl.mRenderer.Reset();
264 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
266 if( impl.mController )
268 const Vector2& shadowOffset = value.Get< Vector2 >();
269 if ( impl.mController->GetShadowOffset() != shadowOffset )
271 impl.mController->SetShadowOffset( shadowOffset );
272 impl.mRenderer.Reset();
277 case Toolkit::TextLabel::Property::SHADOW_COLOR:
279 if( impl.mController )
281 const Vector4& shadowColor = value.Get< Vector4 >();
282 if ( impl.mController->GetShadowColor() != shadowColor )
284 impl.mController->SetShadowColor( shadowColor );
285 impl.mRenderer.Reset();
290 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
292 if( impl.mController )
294 const Vector4& color = value.Get< Vector4 >();
295 if ( impl.mController->GetUnderlineColor() != color )
297 impl.mController->SetUnderlineColor( color );
298 impl.mRenderer.Reset();
303 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
305 if( impl.mController )
307 const bool enabled = value.Get< bool >();
308 if ( impl.mController->IsUnderlineEnabled() != enabled )
310 impl.mController->SetUnderlineEnabled( enabled );
311 impl.mRenderer.Reset();
317 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
319 if( impl.mController )
321 float height = value.Get< float >();
322 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
324 impl.mController->SetUnderlineHeight( height );
325 impl.mRenderer.Reset();
330 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
332 if( impl.mController )
334 const bool enableMarkup = value.Get<bool>();
335 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
339 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
341 if( impl.mController )
343 const bool enableAutoScroll = value.Get<bool>();
344 // If request to auto scroll is the same as current state then do nothing.
345 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
347 // If request is disable (false) and auto scrolling is enabled then need to stop it
348 if ( enableAutoScroll == false )
350 if( impl.mTextScroller )
352 impl.mTextScroller->SetLoopCount( 0 ); // Causes the current animation to finish playing (0)
355 // If request is enable (true) then start autoscroll as not already running
358 impl.mController->SetTextElideEnabled( false );
359 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
365 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
367 if( !impl.mTextScroller )
369 impl.mTextScroller = Text::TextScroller::New( impl );
371 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
372 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
373 AUTO_SCROLL_STOP_MODE_TABLE,
374 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
377 impl.mTextScroller->SetStopMode( stopMode );
381 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
383 if( !impl.mTextScroller )
385 impl.mTextScroller = Text::TextScroller::New( impl );
387 impl.mTextScroller->SetSpeed( value.Get<int>() );
390 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
392 if( !impl.mTextScroller )
394 impl.mTextScroller = Text::TextScroller::New( impl );
396 impl.mTextScroller->SetLoopCount( value.Get<int>() );
399 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
401 if( !impl.mTextScroller )
403 impl.mTextScroller = Text::TextScroller::New( impl );
405 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
408 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
410 if( !impl.mTextScroller )
412 impl.mTextScroller = Text::TextScroller::New( impl );
414 impl.mTextScroller->SetGap( value.Get<float>() );
417 case Toolkit::TextLabel::Property::LINE_SPACING:
419 if( impl.mController )
421 const float lineSpacing = value.Get<float>();
422 impl.mController->SetDefaultLineSpacing( lineSpacing );
423 impl.mRenderer.Reset();
427 case Toolkit::TextLabel::Property::UNDERLINE:
429 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
432 impl.mRenderer.Reset();
436 case Toolkit::TextLabel::Property::SHADOW:
438 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
441 impl.mRenderer.Reset();
445 case Toolkit::TextLabel::Property::EMBOSS:
447 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
450 impl.mRenderer.Reset();
454 case Toolkit::TextLabel::Property::OUTLINE:
456 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
459 impl.mRenderer.Reset();
463 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
465 if( impl.mController )
467 const float pixelSize = value.Get< float >();
468 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
470 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
472 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
477 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
479 if( impl.mController )
481 const bool ellipsis = value.Get<bool>();
482 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
484 impl.mController->SetTextElideEnabled( ellipsis );
492 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
494 Property::Value value;
496 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
500 TextLabel& impl( GetImpl( label ) );
503 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
505 value = impl.mRenderingBackend;
508 case Toolkit::TextLabel::Property::TEXT:
510 if( impl.mController )
513 impl.mController->GetText( text );
518 case Toolkit::TextLabel::Property::FONT_FAMILY:
520 if( impl.mController )
522 value = impl.mController->GetDefaultFontFamily();
526 case Toolkit::TextLabel::Property::FONT_STYLE:
528 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
531 case Toolkit::TextLabel::Property::POINT_SIZE:
533 if( impl.mController )
535 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
539 case Toolkit::TextLabel::Property::MULTI_LINE:
541 if( impl.mController )
543 value = impl.mController->IsMultiLineEnabled();
547 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
549 if( impl.mController )
551 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
552 HORIZONTAL_ALIGNMENT_STRING_TABLE,
553 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
556 value = std::string( name );
561 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
563 if( impl.mController )
565 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
566 VERTICAL_ALIGNMENT_STRING_TABLE,
567 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
570 value = std::string( name );
575 case Toolkit::TextLabel::Property::TEXT_COLOR:
577 if ( impl.mController )
579 value = impl.mController->GetDefaultColor();
583 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
585 if ( impl.mController )
587 value = impl.mController->GetShadowOffset();
591 case Toolkit::TextLabel::Property::SHADOW_COLOR:
593 if ( impl.mController )
595 value = impl.mController->GetShadowColor();
599 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
601 if ( impl.mController )
603 value = impl.mController->GetUnderlineColor();
607 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
609 if ( impl.mController )
611 value = impl.mController->IsUnderlineEnabled();
615 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
617 if ( impl.mController )
619 value = impl.mController->GetUnderlineHeight();
623 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
625 if( impl.mController )
627 value = impl.mController->IsMarkupProcessorEnabled();
631 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
633 if( impl.mController )
635 value = impl.mController->IsAutoScrollEnabled();
639 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
641 if( impl.mTextScroller )
643 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
644 AUTO_SCROLL_STOP_MODE_TABLE,
645 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
648 value = std::string( mode );
653 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
655 TextLabel& impl( GetImpl( label ) );
656 if ( impl.mTextScroller )
658 value = impl.mTextScroller->GetSpeed();
662 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
664 if( impl.mController )
666 TextLabel& impl( GetImpl( label ) );
667 if ( impl.mTextScroller )
669 value = impl.mTextScroller->GetLoopCount();
674 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
676 if( impl.mController )
678 TextLabel& impl( GetImpl( label ) );
679 if ( impl.mTextScroller )
681 value = impl.mTextScroller->GetLoopDelay();
686 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
688 TextLabel& impl( GetImpl( label ) );
689 if ( impl.mTextScroller )
691 value = impl.mTextScroller->GetGap();
695 case Toolkit::TextLabel::Property::LINE_SPACING:
697 if( impl.mController )
699 value = impl.mController->GetDefaultLineSpacing();
703 case Toolkit::TextLabel::Property::UNDERLINE:
705 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
708 case Toolkit::TextLabel::Property::SHADOW:
710 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
713 case Toolkit::TextLabel::Property::EMBOSS:
715 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
718 case Toolkit::TextLabel::Property::OUTLINE:
720 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
723 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
725 if( impl.mController )
727 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
731 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
733 if( impl.mController )
735 value = impl.mController->IsTextElideEnabled();
745 void TextLabel::OnInitialize()
749 mController = Text::Controller::New( this );
751 // When using the vector-based rendering, the size of the GLyphs are different
752 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
753 mController->SetGlyphType( glyphType );
755 // Use height-for-width negotiation by default
756 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
757 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
759 // Enable the text ellipsis.
760 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
762 Layout::Engine& engine = mController->GetLayoutEngine();
763 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
765 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
768 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
770 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
774 case StyleChange::DEFAULT_FONT_CHANGE:
776 // Property system did not set the font so should update it.
777 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
778 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
779 mController->UpdateAfterFontChange( newFont );
783 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
785 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
789 case StyleChange::THEME_CHANGE:
791 // Nothing to do, let control base class handle this
796 // Up call to Control
797 Control::OnStyleChange( styleManager, change );
800 Vector3 TextLabel::GetNaturalSize()
802 return mController->GetNaturalSize();
805 float TextLabel::GetHeightForWidth( float width )
807 return mController->GetHeightForWidth( width );
810 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
812 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
814 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
816 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
821 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
827 void TextLabel::RequestTextRelayout()
832 void TextLabel::RenderText()
834 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
837 Actor renderableActor;
839 float alignmentOffset = 0.f;
842 renderableActor = mRenderer->Render( mController->GetView(),
844 DepthIndex::CONTENT );
847 if( renderableActor != mRenderableActor )
849 UnparentAndReset( mRenderableActor );
851 if( renderableActor )
853 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
854 renderableActor.SetPosition( scrollOffset.x + alignmentOffset, scrollOffset.y );
856 self.Add( renderableActor );
858 mRenderableActor = renderableActor;
860 if ( mController->IsAutoScrollEnabled() )
862 SetUpAutoScrolling();
867 void TextLabel::SetUpAutoScrolling()
869 const Size& controlSize = mController->GetView().GetControlSize();
870 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.
871 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
872 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
874 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
875 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
877 if ( !mTextScroller )
879 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
881 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
882 mTextScroller = Text::TextScroller::New( *this );
884 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset );
887 self.Add( mTextScroller->GetScrollingText() );
888 self.Add( mTextScroller->GetSourceCamera() );
891 void TextLabel::OnStageConnect( Dali::Actor actor )
893 if ( mHasBeenStaged )
899 mHasBeenStaged = true;
903 void TextLabel::ScrollingFinished()
905 // Pure Virtual from TextScroller Interface
906 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
907 mController->SetAutoScrollEnabled( false );
908 mController->SetTextElideEnabled( true );
909 RequestTextRelayout();
912 TextLabel::TextLabel()
913 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
914 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
915 mHasBeenStaged( false )
919 TextLabel::~TextLabel()
923 } // namespace Internal
925 } // namespace Toolkit