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_TYPE_REGISTRATION_END()
135 Toolkit::TextLabel TextLabel::New()
137 // Create the implementation, temporarily owned by this handle on stack
138 IntrusivePtr< TextLabel > impl = new TextLabel();
140 // Pass ownership to CustomActor handle
141 Toolkit::TextLabel handle( *impl );
143 // Second-phase init of the implementation
144 // This can only be done after the CustomActor connection has been made...
150 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
152 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
156 TextLabel& impl( GetImpl( label ) );
159 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
161 int backend = value.Get< int >();
163 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
164 if( Text::RENDERING_VECTOR_BASED == backend )
166 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
169 if( impl.mRenderingBackend != backend )
171 impl.mRenderingBackend = backend;
172 impl.mRenderer.Reset();
174 if( impl.mController )
176 // When using the vector-based rendering, the size of the GLyphs are different
177 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
178 impl.mController->SetGlyphType( glyphType );
183 case Toolkit::TextLabel::Property::TEXT:
185 if( impl.mController )
187 impl.mController->SetText( value.Get< std::string >() );
191 case Toolkit::TextLabel::Property::FONT_FAMILY:
193 if( impl.mController )
195 const std::string& fontFamily = value.Get< std::string >();
197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
198 impl.mController->SetDefaultFontFamily( fontFamily );
202 case Toolkit::TextLabel::Property::FONT_STYLE:
204 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
207 case Toolkit::TextLabel::Property::POINT_SIZE:
209 if( impl.mController )
211 const float pointSize = value.Get< float >();
213 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
215 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
220 case Toolkit::TextLabel::Property::MULTI_LINE:
222 if( impl.mController )
224 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
228 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
230 if( impl.mController )
232 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
233 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
234 HORIZONTAL_ALIGNMENT_STRING_TABLE,
235 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
238 impl.mController->SetHorizontalAlignment( alignment );
243 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
245 if( impl.mController )
247 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
248 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
249 VERTICAL_ALIGNMENT_STRING_TABLE,
250 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
253 impl.mController->SetVerticalAlignment( alignment );
259 case Toolkit::TextLabel::Property::TEXT_COLOR:
261 SetProperty( object, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, value );
265 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
267 if( impl.mController )
269 const Vector2& shadowOffset = value.Get< Vector2 >();
270 if ( impl.mController->GetShadowOffset() != shadowOffset )
272 impl.mController->SetShadowOffset( shadowOffset );
273 impl.mRenderer.Reset();
278 case Toolkit::TextLabel::Property::SHADOW_COLOR:
280 if( impl.mController )
282 const Vector4& shadowColor = value.Get< Vector4 >();
283 if ( impl.mController->GetShadowColor() != shadowColor )
285 impl.mController->SetShadowColor( shadowColor );
286 impl.mRenderer.Reset();
291 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
293 if( impl.mController )
295 const Vector4& color = value.Get< Vector4 >();
296 if ( impl.mController->GetUnderlineColor() != color )
298 impl.mController->SetUnderlineColor( color );
299 impl.mRenderer.Reset();
304 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
306 if( impl.mController )
308 const bool enabled = value.Get< bool >();
309 if ( impl.mController->IsUnderlineEnabled() != enabled )
311 impl.mController->SetUnderlineEnabled( enabled );
312 impl.mRenderer.Reset();
318 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
320 if( impl.mController )
322 float height = value.Get< float >();
323 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
325 impl.mController->SetUnderlineHeight( height );
326 impl.mRenderer.Reset();
331 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
333 if( impl.mController )
335 const bool enableMarkup = value.Get<bool>();
336 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
340 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
342 if( impl.mController )
344 const bool enableAutoScroll = value.Get<bool>();
345 // If request to auto scroll is the same as current state then do nothing.
346 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
348 // If request is disable (false) and auto scrolling is enabled then need to stop it
349 if ( enableAutoScroll == false )
351 if( impl.mTextScroller )
353 impl.mTextScroller->StopScrolling();
356 // If request is enable (true) then start autoscroll as not already running
359 impl.mController->SetTextElideEnabled( false );
360 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
366 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
368 if( !impl.mTextScroller )
370 impl.mTextScroller = Text::TextScroller::New( impl );
372 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
373 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
374 AUTO_SCROLL_STOP_MODE_TABLE,
375 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
378 impl.mTextScroller->SetStopMode( stopMode );
382 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
384 if( !impl.mTextScroller )
386 impl.mTextScroller = Text::TextScroller::New( impl );
388 impl.mTextScroller->SetSpeed( value.Get<int>() );
391 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
393 if( !impl.mTextScroller )
395 impl.mTextScroller = Text::TextScroller::New( impl );
397 impl.mTextScroller->SetLoopCount( value.Get<int>() );
400 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
402 if( !impl.mTextScroller )
404 impl.mTextScroller = Text::TextScroller::New( impl );
406 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
409 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
411 if( !impl.mTextScroller )
413 impl.mTextScroller = Text::TextScroller::New( impl );
415 impl.mTextScroller->SetGap( value.Get<float>() );
418 case Toolkit::TextLabel::Property::LINE_SPACING:
420 if( impl.mController )
422 const float lineSpacing = value.Get<float>();
423 impl.mController->SetDefaultLineSpacing( lineSpacing );
424 impl.mRenderer.Reset();
428 case Toolkit::TextLabel::Property::UNDERLINE:
430 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
433 impl.mRenderer.Reset();
437 case Toolkit::TextLabel::Property::SHADOW:
439 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
442 impl.mRenderer.Reset();
446 case Toolkit::TextLabel::Property::EMBOSS:
448 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
451 impl.mRenderer.Reset();
455 case Toolkit::TextLabel::Property::OUTLINE:
457 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
460 impl.mRenderer.Reset();
464 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
466 if( impl.mController )
468 const float pixelSize = value.Get< float >();
469 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
471 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
473 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
478 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
480 if( impl.mController )
482 const bool ellipsis = value.Get<bool>();
483 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
485 impl.mController->SetTextElideEnabled( ellipsis );
489 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
491 const std::string& wrapModeStr = value.Get< std::string >();
492 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
494 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
495 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
496 LINE_WRAP_MODE_STRING_TABLE,
497 LINE_WRAP_MODE_STRING_TABLE_COUNT,
500 impl.mController->SetLineWrapMode( lineWrapMode );
508 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
510 Property::Value value;
512 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
516 TextLabel& impl( GetImpl( label ) );
519 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
521 value = impl.mRenderingBackend;
524 case Toolkit::TextLabel::Property::TEXT:
526 if( impl.mController )
529 impl.mController->GetText( text );
534 case Toolkit::TextLabel::Property::FONT_FAMILY:
536 if( impl.mController )
538 value = impl.mController->GetDefaultFontFamily();
542 case Toolkit::TextLabel::Property::FONT_STYLE:
544 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
547 case Toolkit::TextLabel::Property::POINT_SIZE:
549 if( impl.mController )
551 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
555 case Toolkit::TextLabel::Property::MULTI_LINE:
557 if( impl.mController )
559 value = impl.mController->IsMultiLineEnabled();
563 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
565 if( impl.mController )
567 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
568 HORIZONTAL_ALIGNMENT_STRING_TABLE,
569 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
572 value = std::string( name );
577 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
579 if( impl.mController )
581 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
582 VERTICAL_ALIGNMENT_STRING_TABLE,
583 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
586 value = std::string( name );
591 case Toolkit::TextLabel::Property::TEXT_COLOR:
592 case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
594 if ( impl.mController )
596 value = impl.mController->GetDefaultColor();
600 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
602 if ( impl.mController )
604 value = impl.mController->GetShadowOffset();
608 case Toolkit::TextLabel::Property::SHADOW_COLOR:
610 if ( impl.mController )
612 value = impl.mController->GetShadowColor();
616 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
618 if ( impl.mController )
620 value = impl.mController->GetUnderlineColor();
624 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
626 if ( impl.mController )
628 value = impl.mController->IsUnderlineEnabled();
632 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
634 if ( impl.mController )
636 value = impl.mController->GetUnderlineHeight();
640 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
642 if( impl.mController )
644 value = impl.mController->IsMarkupProcessorEnabled();
648 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
650 if( impl.mController )
652 value = impl.mController->IsAutoScrollEnabled();
656 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
658 if( impl.mTextScroller )
660 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
661 AUTO_SCROLL_STOP_MODE_TABLE,
662 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
665 value = std::string( mode );
670 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
672 TextLabel& impl( GetImpl( label ) );
673 if ( impl.mTextScroller )
675 value = impl.mTextScroller->GetSpeed();
679 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
681 if( impl.mController )
683 TextLabel& impl( GetImpl( label ) );
684 if ( impl.mTextScroller )
686 value = impl.mTextScroller->GetLoopCount();
691 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
693 if( impl.mController )
695 TextLabel& impl( GetImpl( label ) );
696 if ( impl.mTextScroller )
698 value = impl.mTextScroller->GetLoopDelay();
703 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
705 TextLabel& impl( GetImpl( label ) );
706 if ( impl.mTextScroller )
708 value = impl.mTextScroller->GetGap();
712 case Toolkit::TextLabel::Property::LINE_SPACING:
714 if( impl.mController )
716 value = impl.mController->GetDefaultLineSpacing();
720 case Toolkit::TextLabel::Property::UNDERLINE:
722 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
725 case Toolkit::TextLabel::Property::SHADOW:
727 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
730 case Toolkit::TextLabel::Property::EMBOSS:
732 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
735 case Toolkit::TextLabel::Property::OUTLINE:
737 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
740 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
742 if( impl.mController )
744 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
748 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
750 if( impl.mController )
752 value = impl.mController->IsTextElideEnabled();
756 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
758 if( impl.mController )
760 value = impl.mController->GetLineWrapMode();
764 case Toolkit::DevelTextLabel::Property::LINE_COUNT:
766 if( impl.mController )
768 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
769 value = impl.mController->GetLineCount( width );
779 void TextLabel::OnInitialize()
783 mController = Text::Controller::New( this );
785 // When using the vector-based rendering, the size of the GLyphs are different
786 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
787 mController->SetGlyphType( glyphType );
789 // Use height-for-width negotiation by default
790 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
791 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
793 // Enable the text ellipsis.
794 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
796 Layout::Engine& engine = mController->GetLayoutEngine();
797 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
799 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
802 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
804 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
808 case StyleChange::DEFAULT_FONT_CHANGE:
810 // Property system did not set the font so should update it.
811 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
812 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
813 mController->UpdateAfterFontChange( newFont );
817 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
819 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
823 case StyleChange::THEME_CHANGE:
825 // Nothing to do, let control base class handle this
830 // Up call to Control
831 Control::OnStyleChange( styleManager, change );
834 Vector3 TextLabel::GetNaturalSize()
836 return mController->GetNaturalSize();
839 float TextLabel::GetHeightForWidth( float width )
842 Self().GetPadding( padding );
843 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
846 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
848 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
852 case Toolkit::TextLabel::Property::TEXT_COLOR:
853 case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
855 const Vector4& textColor = propertyValue.Get< Vector4 >();
856 if( mController->GetDefaultColor() != textColor )
858 mController->SetDefaultColor( textColor );
865 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
871 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
873 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
876 Self().GetPadding( padding );
877 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
880 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
882 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
887 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
893 void TextLabel::RequestTextRelayout()
898 void TextLabel::RenderText()
900 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
903 Actor renderableActor;
905 float alignmentOffset = 0.f;
909 Dali::Toolkit::TextLabel handle = Dali::Toolkit::TextLabel( GetOwner() );
911 renderableActor = mRenderer->Render( mController->GetView(),
913 Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE,
915 DepthIndex::CONTENT );
918 if( renderableActor != mRenderableActor )
920 UnparentAndReset( mRenderableActor );
922 if( renderableActor )
924 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
926 self.GetPadding( padding );
927 renderableActor.SetPosition( scrollOffset.x + alignmentOffset + padding.left, scrollOffset.y + padding.top );
929 self.Add( renderableActor );
931 mRenderableActor = renderableActor;
933 if ( mController->IsAutoScrollEnabled() )
935 SetUpAutoScrolling();
940 void TextLabel::SetUpAutoScrolling()
942 const Size& controlSize = mController->GetView().GetControlSize();
943 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.
944 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
945 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
947 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
948 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
950 if ( !mTextScroller )
952 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
954 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
955 mTextScroller = Text::TextScroller::New( *this );
957 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset, mController->GetHorizontalAlignment() );
960 self.Add( mTextScroller->GetScrollingText() );
961 self.Add( mTextScroller->GetSourceCamera() );
964 void TextLabel::OnStageConnect( Dali::Actor actor )
966 if ( mHasBeenStaged )
972 mHasBeenStaged = true;
976 void TextLabel::ScrollingFinished()
978 // Pure Virtual from TextScroller Interface
979 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
980 mController->SetAutoScrollEnabled( false );
981 mController->SetTextElideEnabled( true );
982 RequestTextRelayout();
985 TextLabel::TextLabel()
986 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
987 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
988 mHasBeenStaged( false )
992 TextLabel::~TextLabel()
996 } // namespace Internal
998 } // namespace Toolkit