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 using namespace Dali::Toolkit::Text;
60 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
66 #if defined ( DEBUG_ENABLED )
67 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
70 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
72 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
73 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
75 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
80 return Toolkit::TextLabel::New();
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
114 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
116 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
117 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
118 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
119 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
120 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
121 DALI_TYPE_REGISTRATION_END()
125 Toolkit::TextLabel TextLabel::New()
127 // Create the implementation, temporarily owned by this handle on stack
128 IntrusivePtr< TextLabel > impl = new TextLabel();
130 // Pass ownership to CustomActor handle
131 Toolkit::TextLabel handle( *impl );
133 // Second-phase init of the implementation
134 // This can only be done after the CustomActor connection has been made...
140 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
142 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
146 TextLabel& impl( GetImpl( label ) );
149 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
151 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
153 int backend = value.Get< int >();
155 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
156 if( Text::RENDERING_VECTOR_BASED == backend )
158 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
161 if( impl.mRenderingBackend != backend )
163 impl.mRenderingBackend = backend;
164 impl.mTextUpdateNeeded = true;
166 if( impl.mController )
168 // When using the vector-based rendering, the size of the GLyphs are different
169 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
170 impl.mController->SetGlyphType( glyphType );
175 case Toolkit::TextLabel::Property::TEXT:
177 if( impl.mController )
179 impl.mController->SetText( value.Get< std::string >() );
183 case Toolkit::TextLabel::Property::FONT_FAMILY:
185 if( impl.mController )
187 const std::string& fontFamily = value.Get< std::string >();
189 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
190 impl.mController->SetDefaultFontFamily( fontFamily );
194 case Toolkit::TextLabel::Property::FONT_STYLE:
196 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
199 case Toolkit::TextLabel::Property::POINT_SIZE:
201 if( impl.mController )
203 const float pointSize = value.Get< float >();
205 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
207 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
212 case Toolkit::TextLabel::Property::MULTI_LINE:
214 if( impl.mController )
216 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
220 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
222 if( impl.mController )
224 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
225 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
227 impl.mController->SetHorizontalAlignment( alignment );
232 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
234 if( impl.mController )
236 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
237 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
239 impl.mController->SetVerticalAlignment( alignment );
245 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
247 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
248 impl.mTextUpdateNeeded = true;
252 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
254 if( impl.mController )
256 const Vector2& shadowOffset = value.Get< Vector2 >();
257 if ( impl.mController->GetShadowOffset() != shadowOffset )
259 impl.mController->SetShadowOffset( shadowOffset );
260 impl.mTextUpdateNeeded = true;
265 case Toolkit::TextLabel::Property::SHADOW_COLOR:
267 if( impl.mController )
269 const Vector4& shadowColor = value.Get< Vector4 >();
270 if ( impl.mController->GetShadowColor() != shadowColor )
272 impl.mController->SetShadowColor( shadowColor );
273 impl.mTextUpdateNeeded = true;
278 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
280 if( impl.mController )
282 const Vector4& color = value.Get< Vector4 >();
283 if ( impl.mController->GetUnderlineColor() != color )
285 impl.mController->SetUnderlineColor( color );
286 impl.mTextUpdateNeeded = true;
291 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
293 if( impl.mController )
295 const bool enabled = value.Get< bool >();
296 if ( impl.mController->IsUnderlineEnabled() != enabled )
298 impl.mController->SetUnderlineEnabled( enabled );
299 impl.mTextUpdateNeeded = true;
305 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
307 if( impl.mController )
309 float height = value.Get< float >();
310 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
312 impl.mController->SetUnderlineHeight( height );
313 impl.mTextUpdateNeeded = true;
318 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
320 if( impl.mController )
322 const bool enableMarkup = value.Get<bool>();
323 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
327 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
329 if( impl.mController )
331 const bool enableAutoScroll = value.Get<bool>();
332 // If request to auto scroll is the same as current state then do nothing.
333 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
335 // If request is disable (false) and auto scrolling is enabled then need to stop it
336 if ( enableAutoScroll == false )
338 if( impl.mTextScroller )
340 impl.mTextScroller->StopScrolling();
343 // If request is enable (true) then start autoscroll as not already running
346 impl.mController->SetTextElideEnabled( false );
347 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
353 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
355 if( !impl.mTextScroller )
357 impl.mTextScroller = Text::TextScroller::New( impl );
359 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
360 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
361 AUTO_SCROLL_STOP_MODE_TABLE,
362 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
365 impl.mTextScroller->SetStopMode( stopMode );
369 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
371 if( !impl.mTextScroller )
373 impl.mTextScroller = Text::TextScroller::New( impl );
375 impl.mTextScroller->SetSpeed( value.Get<int>() );
378 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
380 if( !impl.mTextScroller )
382 impl.mTextScroller = Text::TextScroller::New( impl );
384 impl.mTextScroller->SetLoopCount( value.Get<int>() );
387 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
389 if( !impl.mTextScroller )
391 impl.mTextScroller = Text::TextScroller::New( impl );
393 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
396 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
398 if( !impl.mTextScroller )
400 impl.mTextScroller = Text::TextScroller::New( impl );
402 impl.mTextScroller->SetGap( value.Get<float>() );
405 case Toolkit::TextLabel::Property::LINE_SPACING:
407 if( impl.mController )
409 const float lineSpacing = value.Get<float>();
410 impl.mController->SetDefaultLineSpacing( lineSpacing );
411 impl.mTextUpdateNeeded = true;
415 case Toolkit::TextLabel::Property::UNDERLINE:
417 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
420 impl.mTextUpdateNeeded = true;
424 case Toolkit::TextLabel::Property::SHADOW:
426 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
429 impl.mTextUpdateNeeded = true;
433 case Toolkit::TextLabel::Property::EMBOSS:
435 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
438 impl.mTextUpdateNeeded = true;
442 case Toolkit::TextLabel::Property::OUTLINE:
444 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
447 impl.mTextUpdateNeeded = true;
451 case Toolkit::TextLabel::Property::PIXEL_SIZE:
453 if( impl.mController )
455 const float pixelSize = value.Get< float >();
456 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
458 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
460 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
465 case Toolkit::TextLabel::Property::ELLIPSIS:
467 if( impl.mController )
469 const bool ellipsis = value.Get<bool>();
470 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
472 impl.mController->SetTextElideEnabled( ellipsis );
476 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
478 if( impl.mController )
480 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
481 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
483 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
484 impl.mController->SetLineWrapMode( lineWrapMode );
493 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
495 Property::Value value;
497 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
501 TextLabel& impl( GetImpl( label ) );
504 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
506 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
508 value = impl.mRenderingBackend;
511 case Toolkit::TextLabel::Property::TEXT:
513 if( impl.mController )
516 impl.mController->GetText( text );
521 case Toolkit::TextLabel::Property::FONT_FAMILY:
523 if( impl.mController )
525 value = impl.mController->GetDefaultFontFamily();
529 case Toolkit::TextLabel::Property::FONT_STYLE:
531 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
534 case Toolkit::TextLabel::Property::POINT_SIZE:
536 if( impl.mController )
538 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
542 case Toolkit::TextLabel::Property::MULTI_LINE:
544 if( impl.mController )
546 value = impl.mController->IsMultiLineEnabled();
550 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
552 if( impl.mController )
554 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
558 value = std::string( name );
563 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
565 if( impl.mController )
567 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
570 value = std::string( name );
575 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
577 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
580 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
582 if ( impl.mController )
584 value = impl.mController->GetShadowOffset();
588 case Toolkit::TextLabel::Property::SHADOW_COLOR:
590 if ( impl.mController )
592 value = impl.mController->GetShadowColor();
596 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
598 if ( impl.mController )
600 value = impl.mController->GetUnderlineColor();
604 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
606 if ( impl.mController )
608 value = impl.mController->IsUnderlineEnabled();
612 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
614 if ( impl.mController )
616 value = impl.mController->GetUnderlineHeight();
620 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
622 if( impl.mController )
624 value = impl.mController->IsMarkupProcessorEnabled();
628 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
630 if( impl.mController )
632 value = impl.mController->IsAutoScrollEnabled();
636 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
638 if( impl.mTextScroller )
640 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
641 AUTO_SCROLL_STOP_MODE_TABLE,
642 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
645 value = std::string( mode );
650 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
652 TextLabel& impl( GetImpl( label ) );
653 if ( impl.mTextScroller )
655 value = impl.mTextScroller->GetSpeed();
659 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
661 if( impl.mController )
663 TextLabel& impl( GetImpl( label ) );
664 if ( impl.mTextScroller )
666 value = impl.mTextScroller->GetLoopCount();
671 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
673 if( impl.mController )
675 TextLabel& impl( GetImpl( label ) );
676 if ( impl.mTextScroller )
678 value = impl.mTextScroller->GetLoopDelay();
683 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
685 TextLabel& impl( GetImpl( label ) );
686 if ( impl.mTextScroller )
688 value = impl.mTextScroller->GetGap();
692 case Toolkit::TextLabel::Property::LINE_SPACING:
694 if( impl.mController )
696 value = impl.mController->GetDefaultLineSpacing();
700 case Toolkit::TextLabel::Property::UNDERLINE:
702 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
705 case Toolkit::TextLabel::Property::SHADOW:
707 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
710 case Toolkit::TextLabel::Property::EMBOSS:
712 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
715 case Toolkit::TextLabel::Property::OUTLINE:
717 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
720 case Toolkit::TextLabel::Property::PIXEL_SIZE:
722 if( impl.mController )
724 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
728 case Toolkit::TextLabel::Property::ELLIPSIS:
730 if( impl.mController )
732 value = impl.mController->IsTextElideEnabled();
736 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
738 if( impl.mController )
740 value = impl.mController->GetLineWrapMode();
744 case Toolkit::TextLabel::Property::LINE_COUNT:
746 if( impl.mController )
748 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
749 value = impl.mController->GetLineCount( width );
759 void TextLabel::OnInitialize()
763 Property::Map propertyMap;
764 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
766 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
767 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
769 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
771 mController = TextVisual::GetController(mVisual);
774 mController->SetControlInterface(this);
777 // Use height-for-width negotiation by default
778 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
779 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
781 // Enable the text ellipsis.
782 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
784 Layout::Engine& engine = mController->GetLayoutEngine();
785 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
788 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
790 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
794 case StyleChange::DEFAULT_FONT_CHANGE:
796 // Property system did not set the font so should update it.
797 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
798 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
799 mController->UpdateAfterFontChange( newFont );
803 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
805 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
809 case StyleChange::THEME_CHANGE:
811 // Nothing to do, let control base class handle this
816 // Up call to Control
817 Control::OnStyleChange( styleManager, change );
820 Vector3 TextLabel::GetNaturalSize()
822 return mController->GetNaturalSize();
825 float TextLabel::GetHeightForWidth( float width )
828 Self().GetPadding( padding );
829 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
832 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
834 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
838 case Toolkit::TextLabel::Property::TEXT_COLOR:
840 const Vector4& textColor = propertyValue.Get< Vector4 >();
841 if( mController->GetDefaultColor() != textColor )
843 mController->SetDefaultColor( textColor );
844 mTextUpdateNeeded = true;
850 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
856 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
858 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
861 Self().GetPadding( padding );
862 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
864 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
866 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
867 || mTextUpdateNeeded )
869 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
872 TextVisual::EnableRendererUpdate( mVisual );
875 Self().GetPadding( padding );
877 Property::Map visualTransform;
878 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
879 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
880 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
881 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
882 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
883 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
884 mVisual.SetTransformAndSize( visualTransform, size );
886 if ( mController->IsAutoScrollEnabled() )
888 SetUpAutoScrolling();
891 mTextUpdateNeeded = false;
895 void TextLabel::RequestTextRelayout()
900 void TextLabel::SetUpAutoScrolling()
902 const Size& controlSize = mController->GetView().GetControlSize();
903 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.
904 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
906 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
907 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
909 if ( !mTextScroller )
911 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
913 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
914 mTextScroller = Text::TextScroller::New( *this );
917 // Calculate the actual gap before scrolling wraps.
918 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
919 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
920 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
922 // Create a texture of the text for scrolling
923 Size verifiedSize = textureSize;
924 const int maxTextureSize = Dali::GetMaxTextureSize();
926 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
927 if( verifiedSize.width > maxTextureSize )
929 verifiedSize.width = maxTextureSize;
930 if( textNaturalSize.width > maxTextureSize )
932 mController->SetTextElideEnabled( true );
934 GetHeightForWidth( maxTextureSize );
935 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
938 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
940 PixelData data = typesetter->Render( verifiedSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
941 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
942 data.GetPixelFormat(),
945 texture.Upload( data );
947 TextureSet textureSet = TextureSet::New();
948 textureSet.SetTexture( 0u, texture );
950 // Filter mode needs to be set to linear to produce better quality while scaling.
951 Sampler sampler = Sampler::New();
952 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
953 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
954 textureSet.SetSampler( 0u, sampler );
956 // Set parameters for scrolling
957 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
958 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
961 void TextLabel::ScrollingFinished()
963 // Pure Virtual from TextScroller Interface
964 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
965 mController->SetAutoScrollEnabled( false );
966 mController->SetTextElideEnabled( true );
967 RequestTextRelayout();
970 TextLabel::TextLabel()
971 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
972 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
973 mTextUpdateNeeded( false )
977 TextLabel::~TextLabel()
981 } // namespace Internal
983 } // namespace Toolkit