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/internal/text/property-string-parser.h>
30 #include <dali-toolkit/internal/text/rendering/text-backend.h>
31 #include <dali-toolkit/internal/text/text-effects-style.h>
32 #include <dali-toolkit/internal/text/text-font-style.h>
33 #include <dali-toolkit/internal/text/text-view.h>
34 #include <dali-toolkit/internal/text/text-definitions.h>
35 #include <dali-toolkit/internal/styling/style-manager-impl.h>
37 #include <dali-toolkit/public-api/align-enumerations.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
40 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
41 #include <dali-toolkit/public-api/visuals/visual-properties.h>
42 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
44 using namespace Dali::Toolkit::Text;
57 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
63 #if defined ( DEBUG_ENABLED )
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
67 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
69 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
70 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
72 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
74 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
76 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
77 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
78 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
80 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
82 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
84 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
85 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
86 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
88 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
90 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
92 { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD },
93 { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
95 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
100 return Toolkit::TextLabel::New();
103 // Setup properties, signals and actions using the type-registry.
104 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
134 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE )
136 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
137 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
138 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
139 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
140 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
141 DALI_TYPE_REGISTRATION_END()
145 Toolkit::TextLabel TextLabel::New()
147 // Create the implementation, temporarily owned by this handle on stack
148 IntrusivePtr< TextLabel > impl = new TextLabel();
150 // Pass ownership to CustomActor handle
151 Toolkit::TextLabel handle( *impl );
153 // Second-phase init of the implementation
154 // This can only be done after the CustomActor connection has been made...
160 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
162 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
166 TextLabel& impl( GetImpl( label ) );
169 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
171 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
173 int backend = value.Get< int >();
175 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
176 if( Text::RENDERING_VECTOR_BASED == backend )
178 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
181 if( impl.mRenderingBackend != backend )
183 impl.mRenderingBackend = backend;
184 impl.mTextUpdateNeeded = true;
186 if( impl.mController )
188 // When using the vector-based rendering, the size of the GLyphs are different
189 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
190 impl.mController->SetGlyphType( glyphType );
195 case Toolkit::TextLabel::Property::TEXT:
197 if( impl.mController )
199 impl.mController->SetText( value.Get< std::string >() );
203 case Toolkit::TextLabel::Property::FONT_FAMILY:
205 if( impl.mController )
207 const std::string& fontFamily = value.Get< std::string >();
209 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
210 impl.mController->SetDefaultFontFamily( fontFamily );
214 case Toolkit::TextLabel::Property::FONT_STYLE:
216 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
219 case Toolkit::TextLabel::Property::POINT_SIZE:
221 if( impl.mController )
223 const float pointSize = value.Get< float >();
225 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
227 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
232 case Toolkit::TextLabel::Property::MULTI_LINE:
234 if( impl.mController )
236 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
240 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
242 if( impl.mController )
244 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
245 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
246 HORIZONTAL_ALIGNMENT_STRING_TABLE,
247 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
250 impl.mController->SetHorizontalAlignment( alignment );
255 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
257 if( impl.mController )
259 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
260 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
261 VERTICAL_ALIGNMENT_STRING_TABLE,
262 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
265 impl.mController->SetVerticalAlignment( alignment );
271 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
273 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
274 impl.mTextUpdateNeeded = true;
278 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
280 if( impl.mController )
282 const Vector2& shadowOffset = value.Get< Vector2 >();
283 if ( impl.mController->GetShadowOffset() != shadowOffset )
285 impl.mController->SetShadowOffset( shadowOffset );
286 impl.mTextUpdateNeeded = true;
291 case Toolkit::TextLabel::Property::SHADOW_COLOR:
293 if( impl.mController )
295 const Vector4& shadowColor = value.Get< Vector4 >();
296 if ( impl.mController->GetShadowColor() != shadowColor )
298 impl.mController->SetShadowColor( shadowColor );
299 impl.mTextUpdateNeeded = true;
304 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
306 if( impl.mController )
308 const Vector4& color = value.Get< Vector4 >();
309 if ( impl.mController->GetUnderlineColor() != color )
311 impl.mController->SetUnderlineColor( color );
312 impl.mTextUpdateNeeded = true;
317 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
319 if( impl.mController )
321 const bool enabled = value.Get< bool >();
322 if ( impl.mController->IsUnderlineEnabled() != enabled )
324 impl.mController->SetUnderlineEnabled( enabled );
325 impl.mTextUpdateNeeded = true;
331 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
333 if( impl.mController )
335 float height = value.Get< float >();
336 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
338 impl.mController->SetUnderlineHeight( height );
339 impl.mTextUpdateNeeded = true;
344 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
346 if( impl.mController )
348 const bool enableMarkup = value.Get<bool>();
349 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
353 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
355 if( impl.mController )
357 const bool enableAutoScroll = value.Get<bool>();
358 // If request to auto scroll is the same as current state then do nothing.
359 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
361 // If request is disable (false) and auto scrolling is enabled then need to stop it
362 if ( enableAutoScroll == false )
364 if( impl.mTextScroller )
366 impl.mTextScroller->StopScrolling();
369 // If request is enable (true) then start autoscroll as not already running
372 impl.mController->SetTextElideEnabled( false );
373 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
379 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
381 if( !impl.mTextScroller )
383 impl.mTextScroller = Text::TextScroller::New( impl );
385 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
386 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
387 AUTO_SCROLL_STOP_MODE_TABLE,
388 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
391 impl.mTextScroller->SetStopMode( stopMode );
395 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
397 if( !impl.mTextScroller )
399 impl.mTextScroller = Text::TextScroller::New( impl );
401 impl.mTextScroller->SetSpeed( value.Get<int>() );
404 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
406 if( !impl.mTextScroller )
408 impl.mTextScroller = Text::TextScroller::New( impl );
410 impl.mTextScroller->SetLoopCount( value.Get<int>() );
413 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
415 if( !impl.mTextScroller )
417 impl.mTextScroller = Text::TextScroller::New( impl );
419 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
422 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
424 if( !impl.mTextScroller )
426 impl.mTextScroller = Text::TextScroller::New( impl );
428 impl.mTextScroller->SetGap( value.Get<float>() );
431 case Toolkit::TextLabel::Property::LINE_SPACING:
433 if( impl.mController )
435 const float lineSpacing = value.Get<float>();
436 impl.mController->SetDefaultLineSpacing( lineSpacing );
437 impl.mTextUpdateNeeded = true;
441 case Toolkit::TextLabel::Property::UNDERLINE:
443 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
446 impl.mTextUpdateNeeded = true;
450 case Toolkit::TextLabel::Property::SHADOW:
452 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
455 impl.mTextUpdateNeeded = true;
459 case Toolkit::TextLabel::Property::EMBOSS:
461 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
464 impl.mTextUpdateNeeded = true;
468 case Toolkit::TextLabel::Property::OUTLINE:
470 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
473 impl.mTextUpdateNeeded = true;
477 case Toolkit::TextLabel::Property::PIXEL_SIZE:
479 if( impl.mController )
481 const float pixelSize = value.Get< float >();
482 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
484 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
486 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
491 case Toolkit::TextLabel::Property::ELLIPSIS:
493 if( impl.mController )
495 const bool ellipsis = value.Get<bool>();
496 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
498 impl.mController->SetTextElideEnabled( ellipsis );
502 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
504 const std::string& wrapModeStr = value.Get< std::string >();
505 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
507 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
508 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
509 LINE_WRAP_MODE_STRING_TABLE,
510 LINE_WRAP_MODE_STRING_TABLE_COUNT,
513 impl.mController->SetLineWrapMode( lineWrapMode );
521 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
523 Property::Value value;
525 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
529 TextLabel& impl( GetImpl( label ) );
532 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
534 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
536 value = impl.mRenderingBackend;
539 case Toolkit::TextLabel::Property::TEXT:
541 if( impl.mController )
544 impl.mController->GetText( text );
549 case Toolkit::TextLabel::Property::FONT_FAMILY:
551 if( impl.mController )
553 value = impl.mController->GetDefaultFontFamily();
557 case Toolkit::TextLabel::Property::FONT_STYLE:
559 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
562 case Toolkit::TextLabel::Property::POINT_SIZE:
564 if( impl.mController )
566 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
570 case Toolkit::TextLabel::Property::MULTI_LINE:
572 if( impl.mController )
574 value = impl.mController->IsMultiLineEnabled();
578 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
580 if( impl.mController )
582 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
583 HORIZONTAL_ALIGNMENT_STRING_TABLE,
584 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
587 value = std::string( name );
592 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
594 if( impl.mController )
596 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
597 VERTICAL_ALIGNMENT_STRING_TABLE,
598 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
601 value = std::string( name );
606 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
608 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
611 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
613 if ( impl.mController )
615 value = impl.mController->GetShadowOffset();
619 case Toolkit::TextLabel::Property::SHADOW_COLOR:
621 if ( impl.mController )
623 value = impl.mController->GetShadowColor();
627 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
629 if ( impl.mController )
631 value = impl.mController->GetUnderlineColor();
635 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
637 if ( impl.mController )
639 value = impl.mController->IsUnderlineEnabled();
643 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
645 if ( impl.mController )
647 value = impl.mController->GetUnderlineHeight();
651 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
653 if( impl.mController )
655 value = impl.mController->IsMarkupProcessorEnabled();
659 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
661 if( impl.mController )
663 value = impl.mController->IsAutoScrollEnabled();
667 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
669 if( impl.mTextScroller )
671 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
672 AUTO_SCROLL_STOP_MODE_TABLE,
673 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
676 value = std::string( mode );
681 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
683 TextLabel& impl( GetImpl( label ) );
684 if ( impl.mTextScroller )
686 value = impl.mTextScroller->GetSpeed();
690 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
692 if( impl.mController )
694 TextLabel& impl( GetImpl( label ) );
695 if ( impl.mTextScroller )
697 value = impl.mTextScroller->GetLoopCount();
702 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
704 if( impl.mController )
706 TextLabel& impl( GetImpl( label ) );
707 if ( impl.mTextScroller )
709 value = impl.mTextScroller->GetLoopDelay();
714 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
716 TextLabel& impl( GetImpl( label ) );
717 if ( impl.mTextScroller )
719 value = impl.mTextScroller->GetGap();
723 case Toolkit::TextLabel::Property::LINE_SPACING:
725 if( impl.mController )
727 value = impl.mController->GetDefaultLineSpacing();
731 case Toolkit::TextLabel::Property::UNDERLINE:
733 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
736 case Toolkit::TextLabel::Property::SHADOW:
738 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
741 case Toolkit::TextLabel::Property::EMBOSS:
743 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
746 case Toolkit::TextLabel::Property::OUTLINE:
748 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
751 case Toolkit::TextLabel::Property::PIXEL_SIZE:
753 if( impl.mController )
755 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
759 case Toolkit::TextLabel::Property::ELLIPSIS:
761 if( impl.mController )
763 value = impl.mController->IsTextElideEnabled();
767 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
769 if( impl.mController )
771 value = impl.mController->GetLineWrapMode();
775 case Toolkit::TextLabel::Property::LINE_COUNT:
777 if( impl.mController )
779 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
780 value = impl.mController->GetLineCount( width );
790 void TextLabel::OnInitialize()
794 Property::Map propertyMap;
795 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
797 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
798 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
800 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
802 mController = TextVisual::GetController(mVisual);
805 mController->SetControlInterface(this);
808 // Use height-for-width negotiation by default
809 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
810 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
812 // Enable the text ellipsis.
813 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
815 Layout::Engine& engine = mController->GetLayoutEngine();
816 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
819 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
821 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
825 case StyleChange::DEFAULT_FONT_CHANGE:
827 // Property system did not set the font so should update it.
828 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
829 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
830 mController->UpdateAfterFontChange( newFont );
834 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
836 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
840 case StyleChange::THEME_CHANGE:
842 // Nothing to do, let control base class handle this
847 // Up call to Control
848 Control::OnStyleChange( styleManager, change );
851 Vector3 TextLabel::GetNaturalSize()
853 return mController->GetNaturalSize();
856 float TextLabel::GetHeightForWidth( float width )
859 Self().GetPadding( padding );
860 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
863 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
865 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
869 case Toolkit::TextLabel::Property::TEXT_COLOR:
871 const Vector4& textColor = propertyValue.Get< Vector4 >();
872 if( mController->GetDefaultColor() != textColor )
874 mController->SetDefaultColor( textColor );
875 mTextUpdateNeeded = true;
881 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
887 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
889 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
892 Self().GetPadding( padding );
893 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
895 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
897 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
898 || mTextUpdateNeeded )
900 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
903 TextVisual::EnableRendererUpdate( mVisual );
906 Self().GetPadding( padding );
908 Property::Map visualTransform;
909 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
910 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
911 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
912 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
913 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
914 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
915 mVisual.SetTransformAndSize( visualTransform, size );
917 if ( mController->IsAutoScrollEnabled() )
919 SetUpAutoScrolling();
922 mTextUpdateNeeded = false;
926 void TextLabel::RequestTextRelayout()
931 void TextLabel::SetUpAutoScrolling()
933 const Size& controlSize = mController->GetView().GetControlSize();
934 const Size textNaturalSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
935 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
937 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
938 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
940 if ( !mTextScroller )
942 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
944 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
945 mTextScroller = Text::TextScroller::New( *this );
948 // Create a texture of the text for scrolling
949 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
950 PixelData data = typesetter->Render( textNaturalSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
951 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
952 data.GetPixelFormat(),
955 texture.Upload( data );
957 TextureSet textureSet = TextureSet::New();
958 textureSet.SetTexture( 0u, texture );
960 // Filter mode needs to be set to linear to produce better quality while scaling.
961 Sampler sampler = Sampler::New();
962 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
963 textureSet.SetSampler( 0u, sampler );
965 // Set parameters for scrolling
966 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
967 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, textNaturalSize, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
970 void TextLabel::ScrollingFinished()
972 // Pure Virtual from TextScroller Interface
973 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
974 mController->SetAutoScrollEnabled( false );
975 mController->SetTextElideEnabled( true );
976 RequestTextRelayout();
979 TextLabel::TextLabel()
980 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
981 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
982 mTextUpdateNeeded( false )
986 TextLabel::~TextLabel()
990 } // namespace Internal
992 } // namespace Toolkit