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] );
84 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
86 { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD },
87 { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
89 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
94 return Toolkit::TextLabel::New();
97 // Setup properties, signals and actions using the type-registry.
98 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
124 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
125 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
126 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
127 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
128 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
129 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE )
130 DALI_DEVEL_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColorAnimatable", Color::WHITE, TEXT_COLOR_ANIMATABLE )
131 DALI_DEVEL_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR_ANIMATABLE, 0)
132 DALI_DEVEL_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR_ANIMATABLE, 1)
133 DALI_DEVEL_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR_ANIMATABLE, 2)
134 DALI_DEVEL_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR_ANIMATABLE, 3)
135 DALI_TYPE_REGISTRATION_END()
139 Toolkit::TextLabel TextLabel::New()
141 // Create the implementation, temporarily owned by this handle on stack
142 IntrusivePtr< TextLabel > impl = new TextLabel();
144 // Pass ownership to CustomActor handle
145 Toolkit::TextLabel handle( *impl );
147 // Second-phase init of the implementation
148 // This can only be done after the CustomActor connection has been made...
154 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
156 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
160 TextLabel& impl( GetImpl( label ) );
163 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
165 int backend = value.Get< int >();
167 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
168 if( Text::RENDERING_VECTOR_BASED == backend )
170 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
173 if( impl.mRenderingBackend != backend )
175 impl.mRenderingBackend = backend;
176 impl.mRenderer.Reset();
178 if( impl.mController )
180 // When using the vector-based rendering, the size of the GLyphs are different
181 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
182 impl.mController->SetGlyphType( glyphType );
187 case Toolkit::TextLabel::Property::TEXT:
189 if( impl.mController )
191 impl.mController->SetText( value.Get< std::string >() );
195 case Toolkit::TextLabel::Property::FONT_FAMILY:
197 if( impl.mController )
199 const std::string& fontFamily = value.Get< std::string >();
201 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
202 impl.mController->SetDefaultFontFamily( fontFamily );
206 case Toolkit::TextLabel::Property::FONT_STYLE:
208 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
211 case Toolkit::TextLabel::Property::POINT_SIZE:
213 if( impl.mController )
215 const float pointSize = value.Get< float >();
217 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
219 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
224 case Toolkit::TextLabel::Property::MULTI_LINE:
226 if( impl.mController )
228 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
232 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
234 if( impl.mController )
236 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
237 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
238 HORIZONTAL_ALIGNMENT_STRING_TABLE,
239 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
242 impl.mController->SetHorizontalAlignment( alignment );
247 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
249 if( impl.mController )
251 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
252 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
253 VERTICAL_ALIGNMENT_STRING_TABLE,
254 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
257 impl.mController->SetVerticalAlignment( alignment );
263 case Toolkit::TextLabel::Property::TEXT_COLOR:
265 SetProperty( object, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, value );
269 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
271 if( impl.mController )
273 const Vector2& shadowOffset = value.Get< Vector2 >();
274 if ( impl.mController->GetShadowOffset() != shadowOffset )
276 impl.mController->SetShadowOffset( shadowOffset );
277 impl.mRenderer.Reset();
282 case Toolkit::TextLabel::Property::SHADOW_COLOR:
284 if( impl.mController )
286 const Vector4& shadowColor = value.Get< Vector4 >();
287 if ( impl.mController->GetShadowColor() != shadowColor )
289 impl.mController->SetShadowColor( shadowColor );
290 impl.mRenderer.Reset();
295 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
297 if( impl.mController )
299 const Vector4& color = value.Get< Vector4 >();
300 if ( impl.mController->GetUnderlineColor() != color )
302 impl.mController->SetUnderlineColor( color );
303 impl.mRenderer.Reset();
308 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
310 if( impl.mController )
312 const bool enabled = value.Get< bool >();
313 if ( impl.mController->IsUnderlineEnabled() != enabled )
315 impl.mController->SetUnderlineEnabled( enabled );
316 impl.mRenderer.Reset();
322 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
324 if( impl.mController )
326 float height = value.Get< float >();
327 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
329 impl.mController->SetUnderlineHeight( height );
330 impl.mRenderer.Reset();
335 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
337 if( impl.mController )
339 const bool enableMarkup = value.Get<bool>();
340 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
344 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
346 if( impl.mController )
348 const bool enableAutoScroll = value.Get<bool>();
349 // If request to auto scroll is the same as current state then do nothing.
350 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
352 // If request is disable (false) and auto scrolling is enabled then need to stop it
353 if ( enableAutoScroll == false )
355 if( impl.mTextScroller )
357 impl.mTextScroller->StopScrolling();
360 // If request is enable (true) then start autoscroll as not already running
363 impl.mController->SetTextElideEnabled( false );
364 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
370 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
372 if( !impl.mTextScroller )
374 impl.mTextScroller = Text::TextScroller::New( impl );
376 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
377 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
378 AUTO_SCROLL_STOP_MODE_TABLE,
379 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
382 impl.mTextScroller->SetStopMode( stopMode );
386 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
388 if( !impl.mTextScroller )
390 impl.mTextScroller = Text::TextScroller::New( impl );
392 impl.mTextScroller->SetSpeed( value.Get<int>() );
395 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
397 if( !impl.mTextScroller )
399 impl.mTextScroller = Text::TextScroller::New( impl );
401 impl.mTextScroller->SetLoopCount( value.Get<int>() );
404 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
406 if( !impl.mTextScroller )
408 impl.mTextScroller = Text::TextScroller::New( impl );
410 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
413 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
415 if( !impl.mTextScroller )
417 impl.mTextScroller = Text::TextScroller::New( impl );
419 impl.mTextScroller->SetGap( value.Get<float>() );
422 case Toolkit::TextLabel::Property::LINE_SPACING:
424 if( impl.mController )
426 const float lineSpacing = value.Get<float>();
427 impl.mController->SetDefaultLineSpacing( lineSpacing );
428 impl.mRenderer.Reset();
432 case Toolkit::TextLabel::Property::UNDERLINE:
434 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
437 impl.mRenderer.Reset();
441 case Toolkit::TextLabel::Property::SHADOW:
443 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
446 impl.mRenderer.Reset();
450 case Toolkit::TextLabel::Property::EMBOSS:
452 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
455 impl.mRenderer.Reset();
459 case Toolkit::TextLabel::Property::OUTLINE:
461 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
464 impl.mRenderer.Reset();
468 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
470 if( impl.mController )
472 const float pixelSize = value.Get< float >();
473 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
475 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
477 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
482 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
484 if( impl.mController )
486 const bool ellipsis = value.Get<bool>();
487 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
489 impl.mController->SetTextElideEnabled( ellipsis );
493 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
495 const std::string& wrapModeStr = value.Get< std::string >();
496 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
498 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
499 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
500 LINE_WRAP_MODE_STRING_TABLE,
501 LINE_WRAP_MODE_STRING_TABLE_COUNT,
504 impl.mController->SetLineWrapMode( lineWrapMode );
512 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
514 Property::Value value;
516 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
520 TextLabel& impl( GetImpl( label ) );
523 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
525 value = impl.mRenderingBackend;
528 case Toolkit::TextLabel::Property::TEXT:
530 if( impl.mController )
533 impl.mController->GetText( text );
538 case Toolkit::TextLabel::Property::FONT_FAMILY:
540 if( impl.mController )
542 value = impl.mController->GetDefaultFontFamily();
546 case Toolkit::TextLabel::Property::FONT_STYLE:
548 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
551 case Toolkit::TextLabel::Property::POINT_SIZE:
553 if( impl.mController )
555 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
559 case Toolkit::TextLabel::Property::MULTI_LINE:
561 if( impl.mController )
563 value = impl.mController->IsMultiLineEnabled();
567 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
569 if( impl.mController )
571 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
572 HORIZONTAL_ALIGNMENT_STRING_TABLE,
573 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
576 value = std::string( name );
581 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
583 if( impl.mController )
585 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
586 VERTICAL_ALIGNMENT_STRING_TABLE,
587 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
590 value = std::string( name );
595 case Toolkit::TextLabel::Property::TEXT_COLOR:
597 if( impl.mController )
599 value = impl.mController->GetDefaultColor();
603 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
605 if ( impl.mController )
607 value = impl.mController->GetShadowOffset();
611 case Toolkit::TextLabel::Property::SHADOW_COLOR:
613 if ( impl.mController )
615 value = impl.mController->GetShadowColor();
619 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
621 if ( impl.mController )
623 value = impl.mController->GetUnderlineColor();
627 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
629 if ( impl.mController )
631 value = impl.mController->IsUnderlineEnabled();
635 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
637 if ( impl.mController )
639 value = impl.mController->GetUnderlineHeight();
643 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
645 if( impl.mController )
647 value = impl.mController->IsMarkupProcessorEnabled();
651 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
653 if( impl.mController )
655 value = impl.mController->IsAutoScrollEnabled();
659 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
661 if( impl.mTextScroller )
663 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
664 AUTO_SCROLL_STOP_MODE_TABLE,
665 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
668 value = std::string( mode );
673 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
675 TextLabel& impl( GetImpl( label ) );
676 if ( impl.mTextScroller )
678 value = impl.mTextScroller->GetSpeed();
682 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
684 if( impl.mController )
686 TextLabel& impl( GetImpl( label ) );
687 if ( impl.mTextScroller )
689 value = impl.mTextScroller->GetLoopCount();
694 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
696 if( impl.mController )
698 TextLabel& impl( GetImpl( label ) );
699 if ( impl.mTextScroller )
701 value = impl.mTextScroller->GetLoopDelay();
706 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
708 TextLabel& impl( GetImpl( label ) );
709 if ( impl.mTextScroller )
711 value = impl.mTextScroller->GetGap();
715 case Toolkit::TextLabel::Property::LINE_SPACING:
717 if( impl.mController )
719 value = impl.mController->GetDefaultLineSpacing();
723 case Toolkit::TextLabel::Property::UNDERLINE:
725 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
728 case Toolkit::TextLabel::Property::SHADOW:
730 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
733 case Toolkit::TextLabel::Property::EMBOSS:
735 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
738 case Toolkit::TextLabel::Property::OUTLINE:
740 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
743 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
745 if( impl.mController )
747 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
751 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
753 if( impl.mController )
755 value = impl.mController->IsTextElideEnabled();
759 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
761 if( impl.mController )
763 value = impl.mController->GetLineWrapMode();
767 case Toolkit::DevelTextLabel::Property::LINE_COUNT:
769 if( impl.mController )
771 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
772 value = impl.mController->GetLineCount( width );
782 void TextLabel::OnInitialize()
786 mController = Text::Controller::New( this );
788 // When using the vector-based rendering, the size of the GLyphs are different
789 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
790 mController->SetGlyphType( glyphType );
792 // Use height-for-width negotiation by default
793 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
794 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
796 // Enable the text ellipsis.
797 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
799 Layout::Engine& engine = mController->GetLayoutEngine();
800 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
802 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
805 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
807 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
811 case StyleChange::DEFAULT_FONT_CHANGE:
813 // Property system did not set the font so should update it.
814 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
815 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
816 mController->UpdateAfterFontChange( newFont );
820 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
822 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
826 case StyleChange::THEME_CHANGE:
828 // Nothing to do, let control base class handle this
833 // Up call to Control
834 Control::OnStyleChange( styleManager, change );
837 Vector3 TextLabel::GetNaturalSize()
839 return mController->GetNaturalSize();
842 float TextLabel::GetHeightForWidth( float width )
845 Self().GetPadding( padding );
846 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
849 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
851 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
855 case Toolkit::TextLabel::Property::TEXT_COLOR:
856 case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
858 const Vector4& textColor = propertyValue.Get< Vector4 >();
859 if( mController->GetDefaultColor() != textColor )
861 mController->SetDefaultColor( textColor );
868 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
874 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
876 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
879 Self().GetPadding( padding );
880 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
883 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
885 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
890 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
896 void TextLabel::RequestTextRelayout()
901 void TextLabel::RenderText()
903 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
906 Actor renderableActor;
908 float alignmentOffset = 0.f;
912 Dali::Toolkit::TextLabel handle = Dali::Toolkit::TextLabel( GetOwner() );
914 renderableActor = mRenderer->Render( mController->GetView(),
916 Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE,
918 DepthIndex::CONTENT );
921 if( renderableActor != mRenderableActor )
923 UnparentAndReset( mRenderableActor );
925 if( renderableActor )
927 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
929 self.GetPadding( padding );
930 renderableActor.SetPosition( scrollOffset.x + alignmentOffset + padding.left, scrollOffset.y + padding.top );
932 self.Add( renderableActor );
934 mRenderableActor = renderableActor;
936 if ( mController->IsAutoScrollEnabled() )
938 SetUpAutoScrolling();
943 void TextLabel::SetUpAutoScrolling()
945 const Size& controlSize = mController->GetView().GetControlSize();
946 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.
947 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
948 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
950 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
951 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
953 if ( !mTextScroller )
955 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
957 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
958 mTextScroller = Text::TextScroller::New( *this );
960 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset, mController->GetHorizontalAlignment() );
963 self.Add( mTextScroller->GetScrollingText() );
964 self.Add( mTextScroller->GetSourceCamera() );
967 void TextLabel::OnStageConnect( Dali::Actor actor )
969 if ( mHasBeenStaged )
975 mHasBeenStaged = true;
979 void TextLabel::ScrollingFinished()
981 // Pure Virtual from TextScroller Interface
982 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
983 mController->SetAutoScrollEnabled( false );
984 mController->SetTextElideEnabled( true );
985 RequestTextRelayout();
988 TextLabel::TextLabel()
989 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
990 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
991 mHasBeenStaged( false )
995 TextLabel::~TextLabel()
999 } // namespace Internal
1001 } // namespace Toolkit