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/public-api/text/text-enumerations.h>
29 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.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 #include <dali-toolkit/public-api/align-enumerations.h>
39 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
40 #include <dali-toolkit/devel-api/controls/control-devel.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
42 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
43 #include <dali-toolkit/public-api/visuals/visual-properties.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
46 using namespace Dali::Toolkit::Text;
59 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
65 #if defined ( DEBUG_ENABLED )
66 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
69 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
71 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
72 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
74 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
76 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
78 { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD },
79 { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
81 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
86 return Toolkit::TextLabel::New();
89 // Setup properties, signals and actions using the type-registry.
90 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
120 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE )
122 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
123 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
124 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
125 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
126 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
127 DALI_TYPE_REGISTRATION_END()
131 Toolkit::TextLabel TextLabel::New()
133 // Create the implementation, temporarily owned by this handle on stack
134 IntrusivePtr< TextLabel > impl = new TextLabel();
136 // Pass ownership to CustomActor handle
137 Toolkit::TextLabel handle( *impl );
139 // Second-phase init of the implementation
140 // This can only be done after the CustomActor connection has been made...
146 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
148 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
152 TextLabel& impl( GetImpl( label ) );
155 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
157 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
159 int backend = value.Get< int >();
161 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
162 if( Text::RENDERING_VECTOR_BASED == backend )
164 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
167 if( impl.mRenderingBackend != backend )
169 impl.mRenderingBackend = backend;
170 impl.mTextUpdateNeeded = true;
172 if( impl.mController )
174 // When using the vector-based rendering, the size of the GLyphs are different
175 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
176 impl.mController->SetGlyphType( glyphType );
181 case Toolkit::TextLabel::Property::TEXT:
183 if( impl.mController )
185 impl.mController->SetText( value.Get< std::string >() );
189 case Toolkit::TextLabel::Property::FONT_FAMILY:
191 if( impl.mController )
193 const std::string& fontFamily = value.Get< std::string >();
195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
196 impl.mController->SetDefaultFontFamily( fontFamily );
200 case Toolkit::TextLabel::Property::FONT_STYLE:
202 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
205 case Toolkit::TextLabel::Property::POINT_SIZE:
207 if( impl.mController )
209 const float pointSize = value.Get< float >();
211 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
213 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
218 case Toolkit::TextLabel::Property::MULTI_LINE:
220 if( impl.mController )
222 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
226 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
228 if( impl.mController )
230 Toolkit::Text::HorizontalAlignment::Type alignment( Toolkit::Text::HorizontalAlignment::BEGIN );
231 Text::GetHorizontalAlignmentEnum( value, alignment );
233 impl.mController->SetHorizontalAlignment( alignment );
238 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
240 if( impl.mController )
242 Toolkit::Text::VerticalAlignment::Type alignment( Toolkit::Text::VerticalAlignment::BOTTOM );
243 Text::GetVerticalAlignmentEnum( value, alignment );
245 impl.mController->SetVerticalAlignment( alignment );
250 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
252 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
253 impl.mTextUpdateNeeded = true;
257 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
259 if( impl.mController )
261 const Vector2& shadowOffset = value.Get< Vector2 >();
262 if ( impl.mController->GetShadowOffset() != shadowOffset )
264 impl.mController->SetShadowOffset( shadowOffset );
265 impl.mTextUpdateNeeded = true;
270 case Toolkit::TextLabel::Property::SHADOW_COLOR:
272 if( impl.mController )
274 const Vector4& shadowColor = value.Get< Vector4 >();
275 if ( impl.mController->GetShadowColor() != shadowColor )
277 impl.mController->SetShadowColor( shadowColor );
278 impl.mTextUpdateNeeded = true;
283 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
285 if( impl.mController )
287 const Vector4& color = value.Get< Vector4 >();
288 if ( impl.mController->GetUnderlineColor() != color )
290 impl.mController->SetUnderlineColor( color );
291 impl.mTextUpdateNeeded = true;
296 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
298 if( impl.mController )
300 const bool enabled = value.Get< bool >();
301 if ( impl.mController->IsUnderlineEnabled() != enabled )
303 impl.mController->SetUnderlineEnabled( enabled );
304 impl.mTextUpdateNeeded = true;
310 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
312 if( impl.mController )
314 float height = value.Get< float >();
315 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
317 impl.mController->SetUnderlineHeight( height );
318 impl.mTextUpdateNeeded = true;
323 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
325 if( impl.mController )
327 const bool enableMarkup = value.Get<bool>();
328 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
332 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
334 if( impl.mController )
336 const bool enableAutoScroll = value.Get<bool>();
337 // If request to auto scroll is the same as current state then do nothing.
338 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
340 // If request is disable (false) and auto scrolling is enabled then need to stop it
341 if ( enableAutoScroll == false )
343 if( impl.mTextScroller )
345 impl.mTextScroller->StopScrolling();
348 // If request is enable (true) then start autoscroll as not already running
351 impl.mController->SetTextElideEnabled( false );
352 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
358 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
360 if( !impl.mTextScroller )
362 impl.mTextScroller = Text::TextScroller::New( impl );
364 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
365 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
366 AUTO_SCROLL_STOP_MODE_TABLE,
367 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
370 impl.mTextScroller->SetStopMode( stopMode );
374 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
376 if( !impl.mTextScroller )
378 impl.mTextScroller = Text::TextScroller::New( impl );
380 impl.mTextScroller->SetSpeed( value.Get<int>() );
383 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
385 if( !impl.mTextScroller )
387 impl.mTextScroller = Text::TextScroller::New( impl );
389 impl.mTextScroller->SetLoopCount( value.Get<int>() );
392 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
394 if( !impl.mTextScroller )
396 impl.mTextScroller = Text::TextScroller::New( impl );
398 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
401 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
403 if( !impl.mTextScroller )
405 impl.mTextScroller = Text::TextScroller::New( impl );
407 impl.mTextScroller->SetGap( value.Get<float>() );
410 case Toolkit::TextLabel::Property::LINE_SPACING:
412 if( impl.mController )
414 const float lineSpacing = value.Get<float>();
415 impl.mController->SetDefaultLineSpacing( lineSpacing );
416 impl.mTextUpdateNeeded = true;
420 case Toolkit::TextLabel::Property::UNDERLINE:
422 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
425 impl.mTextUpdateNeeded = true;
429 case Toolkit::TextLabel::Property::SHADOW:
431 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
434 impl.mTextUpdateNeeded = true;
438 case Toolkit::TextLabel::Property::EMBOSS:
440 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
443 impl.mTextUpdateNeeded = true;
447 case Toolkit::TextLabel::Property::OUTLINE:
449 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
452 impl.mTextUpdateNeeded = true;
456 case Toolkit::TextLabel::Property::PIXEL_SIZE:
458 if( impl.mController )
460 const float pixelSize = value.Get< float >();
461 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
463 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
465 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
470 case Toolkit::TextLabel::Property::ELLIPSIS:
472 if( impl.mController )
474 const bool ellipsis = value.Get<bool>();
475 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
477 impl.mController->SetTextElideEnabled( ellipsis );
481 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
483 const std::string& wrapModeStr = value.Get< std::string >();
484 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
486 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
487 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
488 LINE_WRAP_MODE_STRING_TABLE,
489 LINE_WRAP_MODE_STRING_TABLE_COUNT,
492 impl.mController->SetLineWrapMode( lineWrapMode );
500 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
502 Property::Value value;
504 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
508 TextLabel& impl( GetImpl( label ) );
511 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
513 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
515 value = impl.mRenderingBackend;
518 case Toolkit::TextLabel::Property::TEXT:
520 if( impl.mController )
523 impl.mController->GetText( text );
528 case Toolkit::TextLabel::Property::FONT_FAMILY:
530 if( impl.mController )
532 value = impl.mController->GetDefaultFontFamily();
536 case Toolkit::TextLabel::Property::FONT_STYLE:
538 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
541 case Toolkit::TextLabel::Property::POINT_SIZE:
543 if( impl.mController )
545 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
549 case Toolkit::TextLabel::Property::MULTI_LINE:
551 if( impl.mController )
553 value = impl.mController->IsMultiLineEnabled();
557 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
559 if( impl.mController )
561 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
565 value = std::string( name );
570 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
572 if( impl.mController )
574 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
577 value = std::string( name );
582 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
584 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
587 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
589 if ( impl.mController )
591 value = impl.mController->GetShadowOffset();
595 case Toolkit::TextLabel::Property::SHADOW_COLOR:
597 if ( impl.mController )
599 value = impl.mController->GetShadowColor();
603 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
605 if ( impl.mController )
607 value = impl.mController->GetUnderlineColor();
611 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
613 if ( impl.mController )
615 value = impl.mController->IsUnderlineEnabled();
619 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
621 if ( impl.mController )
623 value = impl.mController->GetUnderlineHeight();
627 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
629 if( impl.mController )
631 value = impl.mController->IsMarkupProcessorEnabled();
635 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
637 if( impl.mController )
639 value = impl.mController->IsAutoScrollEnabled();
643 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
645 if( impl.mTextScroller )
647 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
648 AUTO_SCROLL_STOP_MODE_TABLE,
649 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
652 value = std::string( mode );
657 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
659 TextLabel& impl( GetImpl( label ) );
660 if ( impl.mTextScroller )
662 value = impl.mTextScroller->GetSpeed();
666 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
668 if( impl.mController )
670 TextLabel& impl( GetImpl( label ) );
671 if ( impl.mTextScroller )
673 value = impl.mTextScroller->GetLoopCount();
678 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
680 if( impl.mController )
682 TextLabel& impl( GetImpl( label ) );
683 if ( impl.mTextScroller )
685 value = impl.mTextScroller->GetLoopDelay();
690 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
692 TextLabel& impl( GetImpl( label ) );
693 if ( impl.mTextScroller )
695 value = impl.mTextScroller->GetGap();
699 case Toolkit::TextLabel::Property::LINE_SPACING:
701 if( impl.mController )
703 value = impl.mController->GetDefaultLineSpacing();
707 case Toolkit::TextLabel::Property::UNDERLINE:
709 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
712 case Toolkit::TextLabel::Property::SHADOW:
714 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
717 case Toolkit::TextLabel::Property::EMBOSS:
719 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
722 case Toolkit::TextLabel::Property::OUTLINE:
724 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
727 case Toolkit::TextLabel::Property::PIXEL_SIZE:
729 if( impl.mController )
731 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
735 case Toolkit::TextLabel::Property::ELLIPSIS:
737 if( impl.mController )
739 value = impl.mController->IsTextElideEnabled();
743 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
745 if( impl.mController )
747 value = impl.mController->GetLineWrapMode();
751 case Toolkit::TextLabel::Property::LINE_COUNT:
753 if( impl.mController )
755 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
756 value = impl.mController->GetLineCount( width );
766 void TextLabel::OnInitialize()
770 Property::Map propertyMap;
771 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
773 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
774 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
776 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
778 mController = TextVisual::GetController(mVisual);
781 mController->SetControlInterface(this);
784 // Use height-for-width negotiation by default
785 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
786 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
788 // Enable the text ellipsis.
789 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
791 Layout::Engine& engine = mController->GetLayoutEngine();
792 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
795 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
801 case StyleChange::DEFAULT_FONT_CHANGE:
803 // Property system did not set the font so should update it.
804 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
805 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
806 mController->UpdateAfterFontChange( newFont );
810 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
812 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
816 case StyleChange::THEME_CHANGE:
818 // Nothing to do, let control base class handle this
823 // Up call to Control
824 Control::OnStyleChange( styleManager, change );
827 Vector3 TextLabel::GetNaturalSize()
829 return mController->GetNaturalSize();
832 float TextLabel::GetHeightForWidth( float width )
835 Self().GetPadding( padding );
836 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
839 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
841 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
845 case Toolkit::TextLabel::Property::TEXT_COLOR:
847 const Vector4& textColor = propertyValue.Get< Vector4 >();
848 if( mController->GetDefaultColor() != textColor )
850 mController->SetDefaultColor( textColor );
851 mTextUpdateNeeded = true;
857 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
863 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
865 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
868 Self().GetPadding( padding );
869 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
871 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
873 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
874 || mTextUpdateNeeded )
876 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
879 TextVisual::EnableRendererUpdate( mVisual );
882 Self().GetPadding( padding );
884 Property::Map visualTransform;
885 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
886 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
887 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
888 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
889 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
890 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
891 mVisual.SetTransformAndSize( visualTransform, size );
893 if ( mController->IsAutoScrollEnabled() )
895 SetUpAutoScrolling();
898 mTextUpdateNeeded = false;
902 void TextLabel::RequestTextRelayout()
907 void TextLabel::SetUpAutoScrolling()
909 const Size& controlSize = mController->GetView().GetControlSize();
910 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.
911 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
913 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
914 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
916 if ( !mTextScroller )
918 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
920 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
921 mTextScroller = Text::TextScroller::New( *this );
924 // Create a texture of the text for scrolling
925 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
926 PixelData data = typesetter->Render( textNaturalSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
927 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
928 data.GetPixelFormat(),
931 texture.Upload( data );
933 TextureSet textureSet = TextureSet::New();
934 textureSet.SetTexture( 0u, texture );
936 // Filter mode needs to be set to linear to produce better quality while scaling.
937 Sampler sampler = Sampler::New();
938 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
939 textureSet.SetSampler( 0u, sampler );
941 // Set parameters for scrolling
942 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
943 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, textNaturalSize, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
946 void TextLabel::ScrollingFinished()
948 // Pure Virtual from TextScroller Interface
949 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
950 mController->SetAutoScrollEnabled( false );
951 mController->SetTextElideEnabled( true );
952 RequestTextRelayout();
955 TextLabel::TextLabel()
956 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
957 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
958 mTextUpdateNeeded( false )
962 TextLabel::~TextLabel()
966 } // namespace Internal
968 } // namespace Toolkit