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/devel-api/adaptor-framework/image-loading.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/public-api/text/rendering-backend.h>
29 #include <dali-toolkit/public-api/text/text-enumerations.h>
30 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
31 #include <dali-toolkit/internal/text/property-string-parser.h>
32 #include <dali-toolkit/internal/text/rendering/text-backend.h>
33 #include <dali-toolkit/internal/text/text-effects-style.h>
34 #include <dali-toolkit/internal/text/text-font-style.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/text/text-definitions.h>
37 #include <dali-toolkit/internal/styling/style-manager-impl.h>
39 #include <dali-toolkit/public-api/align-enumerations.h>
40 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
41 #include <dali-toolkit/devel-api/controls/control-devel.h>
42 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
43 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
44 #include <dali-toolkit/public-api/visuals/visual-properties.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
47 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
49 using namespace Dali::Toolkit::Text;
62 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 #if defined ( DEBUG_ENABLED )
69 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
72 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
74 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
75 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
77 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
82 return Toolkit::TextLabel::New();
85 // Setup properties, signals and actions using the type-registry.
86 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
116 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
118 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
119 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
120 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
121 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
122 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
123 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
124 DALI_TYPE_REGISTRATION_END()
128 Toolkit::TextLabel TextLabel::New()
130 // Create the implementation, temporarily owned by this handle on stack
131 IntrusivePtr< TextLabel > impl = new TextLabel();
133 // Pass ownership to CustomActor handle
134 Toolkit::TextLabel handle( *impl );
136 // Second-phase init of the implementation
137 // This can only be done after the CustomActor connection has been made...
143 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
145 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
149 TextLabel& impl( GetImpl( label ) );
152 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
154 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
156 int backend = value.Get< int >();
158 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
159 if( Text::RENDERING_VECTOR_BASED == backend )
161 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
164 if( impl.mRenderingBackend != backend )
166 impl.mRenderingBackend = backend;
167 impl.mTextUpdateNeeded = true;
169 if( impl.mController )
171 // When using the vector-based rendering, the size of the GLyphs are different
172 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
173 impl.mController->SetGlyphType( glyphType );
178 case Toolkit::TextLabel::Property::TEXT:
180 if( impl.mController )
182 impl.mController->SetText( value.Get< std::string >() );
186 case Toolkit::TextLabel::Property::FONT_FAMILY:
188 if( impl.mController )
190 const std::string& fontFamily = value.Get< std::string >();
192 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
193 impl.mController->SetDefaultFontFamily( fontFamily );
197 case Toolkit::TextLabel::Property::FONT_STYLE:
199 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
202 case Toolkit::TextLabel::Property::POINT_SIZE:
204 if( impl.mController )
206 const float pointSize = value.Get< float >();
208 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
210 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
215 case Toolkit::TextLabel::Property::MULTI_LINE:
217 if( impl.mController )
219 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
223 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
225 if( impl.mController )
227 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
228 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
230 impl.mController->SetHorizontalAlignment( alignment );
235 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
237 if( impl.mController )
239 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
240 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
242 impl.mController->SetVerticalAlignment( alignment );
248 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
250 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
251 impl.mTextUpdateNeeded = true;
255 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
257 if( impl.mController )
259 const Vector2& shadowOffset = value.Get< Vector2 >();
260 if ( impl.mController->GetShadowOffset() != shadowOffset )
262 impl.mController->SetShadowOffset( shadowOffset );
263 impl.mTextUpdateNeeded = true;
268 case Toolkit::TextLabel::Property::SHADOW_COLOR:
270 if( impl.mController )
272 const Vector4& shadowColor = value.Get< Vector4 >();
273 if ( impl.mController->GetShadowColor() != shadowColor )
275 impl.mController->SetShadowColor( shadowColor );
276 impl.mTextUpdateNeeded = true;
281 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
283 if( impl.mController )
285 const Vector4& color = value.Get< Vector4 >();
286 if ( impl.mController->GetUnderlineColor() != color )
288 impl.mController->SetUnderlineColor( color );
289 impl.mTextUpdateNeeded = true;
294 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
296 if( impl.mController )
298 const bool enabled = value.Get< bool >();
299 if ( impl.mController->IsUnderlineEnabled() != enabled )
301 impl.mController->SetUnderlineEnabled( enabled );
302 impl.mTextUpdateNeeded = true;
308 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
310 if( impl.mController )
312 float height = value.Get< float >();
313 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
315 impl.mController->SetUnderlineHeight( height );
316 impl.mTextUpdateNeeded = true;
321 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
323 if( impl.mController )
325 const bool enableMarkup = value.Get<bool>();
326 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
330 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
332 if( impl.mController )
334 const bool enableAutoScroll = value.Get<bool>();
335 // If request to auto scroll is the same as current state then do nothing.
336 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
338 // If request is disable (false) and auto scrolling is enabled then need to stop it
339 if ( enableAutoScroll == false )
341 if( impl.mTextScroller )
343 impl.mTextScroller->StopScrolling();
346 // If request is enable (true) then start autoscroll as not already running
349 impl.mController->SetTextElideEnabled( false );
350 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
356 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
358 if( !impl.mTextScroller )
360 impl.mTextScroller = Text::TextScroller::New( impl );
362 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
363 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
364 AUTO_SCROLL_STOP_MODE_TABLE,
365 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
368 impl.mTextScroller->SetStopMode( stopMode );
372 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
374 if( !impl.mTextScroller )
376 impl.mTextScroller = Text::TextScroller::New( impl );
378 impl.mTextScroller->SetSpeed( value.Get<int>() );
381 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
383 if( !impl.mTextScroller )
385 impl.mTextScroller = Text::TextScroller::New( impl );
387 impl.mTextScroller->SetLoopCount( value.Get<int>() );
390 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
392 if( !impl.mTextScroller )
394 impl.mTextScroller = Text::TextScroller::New( impl );
396 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
399 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
401 if( !impl.mTextScroller )
403 impl.mTextScroller = Text::TextScroller::New( impl );
405 impl.mTextScroller->SetGap( value.Get<float>() );
408 case Toolkit::TextLabel::Property::LINE_SPACING:
410 if( impl.mController )
412 const float lineSpacing = value.Get<float>();
413 impl.mController->SetDefaultLineSpacing( lineSpacing );
414 impl.mTextUpdateNeeded = true;
418 case Toolkit::TextLabel::Property::UNDERLINE:
420 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
423 impl.mTextUpdateNeeded = true;
427 case Toolkit::TextLabel::Property::SHADOW:
429 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
432 impl.mTextUpdateNeeded = true;
436 case Toolkit::TextLabel::Property::EMBOSS:
438 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
441 impl.mTextUpdateNeeded = true;
445 case Toolkit::TextLabel::Property::OUTLINE:
447 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
450 impl.mTextUpdateNeeded = true;
454 case Toolkit::TextLabel::Property::PIXEL_SIZE:
456 if( impl.mController )
458 const float pixelSize = value.Get< float >();
459 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
461 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
463 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
468 case Toolkit::TextLabel::Property::ELLIPSIS:
470 if( impl.mController )
472 const bool ellipsis = value.Get<bool>();
473 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
475 impl.mController->SetTextElideEnabled( ellipsis );
479 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
481 if( impl.mController )
483 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
484 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
486 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
487 impl.mController->SetLineWrapMode( lineWrapMode );
496 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
498 Property::Value value;
500 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
504 TextLabel& impl( GetImpl( label ) );
507 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
509 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
511 value = impl.mRenderingBackend;
514 case Toolkit::TextLabel::Property::TEXT:
516 if( impl.mController )
519 impl.mController->GetText( text );
524 case Toolkit::TextLabel::Property::FONT_FAMILY:
526 if( impl.mController )
528 value = impl.mController->GetDefaultFontFamily();
532 case Toolkit::TextLabel::Property::FONT_STYLE:
534 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
537 case Toolkit::TextLabel::Property::POINT_SIZE:
539 if( impl.mController )
541 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
545 case Toolkit::TextLabel::Property::MULTI_LINE:
547 if( impl.mController )
549 value = impl.mController->IsMultiLineEnabled();
553 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
555 if( impl.mController )
557 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
561 value = std::string( name );
566 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
568 if( impl.mController )
570 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
573 value = std::string( name );
578 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
580 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
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::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
641 if( impl.mTextScroller )
643 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::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::TextLabel::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::TextLabel::Property::PIXEL_SIZE:
725 if( impl.mController )
727 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
731 case Toolkit::TextLabel::Property::ELLIPSIS:
733 if( impl.mController )
735 value = impl.mController->IsTextElideEnabled();
739 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
741 if( impl.mController )
743 value = impl.mController->GetLineWrapMode();
747 case Toolkit::TextLabel::Property::LINE_COUNT:
749 if( impl.mController )
751 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
752 value = impl.mController->GetLineCount( width );
756 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
758 if( impl.mController )
760 value = impl.mController->GetTextDirection();
770 void TextLabel::OnInitialize()
774 Property::Map propertyMap;
775 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
777 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
778 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
780 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
782 mController = TextVisual::GetController(mVisual);
785 mController->SetControlInterface(this);
788 // Use height-for-width negotiation by default
789 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
790 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
792 // Enable the text ellipsis.
793 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
795 Layout::Engine& engine = mController->GetLayoutEngine();
796 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
799 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
801 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
805 case StyleChange::DEFAULT_FONT_CHANGE:
807 // Property system did not set the font so should update it.
808 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
809 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
810 mController->UpdateAfterFontChange( newFont );
814 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
816 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
820 case StyleChange::THEME_CHANGE:
822 // Nothing to do, let control base class handle this
827 // Up call to Control
828 Control::OnStyleChange( styleManager, change );
831 Vector3 TextLabel::GetNaturalSize()
834 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
836 Vector3 naturalSize = mController->GetNaturalSize();
837 naturalSize.width += ( padding.start + padding.end );
838 naturalSize.height += ( padding.top + padding.bottom );
843 float TextLabel::GetHeightForWidth( float width )
846 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
848 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
851 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
853 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
857 case Toolkit::TextLabel::Property::TEXT_COLOR:
859 const Vector4& textColor = propertyValue.Get< Vector4 >();
860 if( mController->GetDefaultColor() != textColor )
862 mController->SetDefaultColor( textColor );
863 mTextUpdateNeeded = true;
869 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
875 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
877 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
880 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
882 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
884 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
886 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
887 || mTextUpdateNeeded )
889 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
892 TextVisual::EnableRendererUpdate( mVisual );
894 // Support Right-To-Left of padding
895 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
896 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
898 std::swap( padding.start, padding.end );
901 Property::Map visualTransform;
902 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
903 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
904 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) )
905 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
906 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
907 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
908 mVisual.SetTransformAndSize( visualTransform, size );
910 if ( mController->IsAutoScrollEnabled() )
912 SetUpAutoScrolling();
915 mTextUpdateNeeded = false;
919 void TextLabel::RequestTextRelayout()
924 void TextLabel::SetUpAutoScrolling()
926 const Size& controlSize = mController->GetView().GetControlSize();
927 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.
928 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
930 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
931 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
933 if ( !mTextScroller )
935 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
937 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
938 mTextScroller = Text::TextScroller::New( *this );
941 // Calculate the actual gap before scrolling wraps.
942 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
943 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
944 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
946 // Create a texture of the text for scrolling
947 Size verifiedSize = textureSize;
948 const int maxTextureSize = Dali::GetMaxTextureSize();
950 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
951 if( verifiedSize.width > maxTextureSize )
953 verifiedSize.width = maxTextureSize;
954 if( textNaturalSize.width > maxTextureSize )
956 mController->SetTextElideEnabled( true );
958 GetHeightForWidth( maxTextureSize );
959 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
962 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
964 PixelData data = typesetter->Render( verifiedSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
965 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
966 data.GetPixelFormat(),
969 texture.Upload( data );
971 TextureSet textureSet = TextureSet::New();
972 textureSet.SetTexture( 0u, texture );
974 // Filter mode needs to be set to linear to produce better quality while scaling.
975 Sampler sampler = Sampler::New();
976 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
977 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
978 textureSet.SetSampler( 0u, sampler );
980 // Set parameters for scrolling
981 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
982 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
985 void TextLabel::ScrollingFinished()
987 // Pure Virtual from TextScroller Interface
988 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
989 mController->SetAutoScrollEnabled( false );
990 mController->SetTextElideEnabled( true );
991 RequestTextRelayout();
994 TextLabel::TextLabel()
995 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
996 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
997 mTextUpdateNeeded( false )
1001 TextLabel::~TextLabel()
1005 } // namespace Internal
1007 } // namespace Toolkit