2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
22 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/public-api/text/rendering-backend.h>
28 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
29 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
30 #include <dali-toolkit/internal/text/property-string-parser.h>
31 #include <dali-toolkit/internal/text/rendering/text-backend.h>
32 #include <dali-toolkit/internal/text/text-effects-style.h>
33 #include <dali-toolkit/internal/text/text-font-style.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/text/text-definitions.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 #include <dali-toolkit/devel-api/align-enums.h>
39 #include <dali-toolkit/devel-api/controls/control-devel.h>
40 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
41 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
42 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
45 using namespace Dali::Toolkit::Text;
58 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
64 #if defined ( DEBUG_ENABLED )
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
68 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
70 { "IMMEDIATE", Toolkit::DevelTextLabel::AutoScrollStopMode::IMMEDIATE },
71 { "FINISH_LOOP", Toolkit::DevelTextLabel::AutoScrollStopMode::FINISH_LOOP },
73 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
75 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
77 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
78 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
79 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
81 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
83 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
85 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
86 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
87 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
89 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
91 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
93 { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD },
94 { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
96 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
101 return Toolkit::TextLabel::New();
104 // Setup properties, signals and actions using the type-registry.
105 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND ) // Deprecated property
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
135 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE )
137 DALI_DEVEL_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColorAnimatable", Color::BLACK, TEXT_COLOR_ANIMATABLE )
138 DALI_TYPE_REGISTRATION_END()
142 Toolkit::TextLabel TextLabel::New()
144 // Create the implementation, temporarily owned by this handle on stack
145 IntrusivePtr< TextLabel > impl = new TextLabel();
147 // Pass ownership to CustomActor handle
148 Toolkit::TextLabel handle( *impl );
150 // Second-phase init of the implementation
151 // This can only be done after the CustomActor connection has been made...
157 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
159 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
163 TextLabel& impl( GetImpl( label ) );
166 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
168 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
170 int backend = value.Get< int >();
172 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
173 if( Text::RENDERING_VECTOR_BASED == backend )
175 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
178 if( impl.mRenderingBackend != backend )
180 impl.mRenderingBackend = backend;
181 impl.mTextUpdateNeeded = true;
183 if( impl.mController )
185 // When using the vector-based rendering, the size of the GLyphs are different
186 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
187 impl.mController->SetGlyphType( glyphType );
192 case Toolkit::TextLabel::Property::TEXT:
194 if( impl.mController )
196 impl.mController->SetText( value.Get< std::string >() );
200 case Toolkit::TextLabel::Property::FONT_FAMILY:
202 if( impl.mController )
204 const std::string& fontFamily = value.Get< std::string >();
206 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
207 impl.mController->SetDefaultFontFamily( fontFamily );
211 case Toolkit::TextLabel::Property::FONT_STYLE:
213 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
216 case Toolkit::TextLabel::Property::POINT_SIZE:
218 if( impl.mController )
220 const float pointSize = value.Get< float >();
222 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
224 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
229 case Toolkit::TextLabel::Property::MULTI_LINE:
231 if( impl.mController )
233 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
237 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
239 if( impl.mController )
241 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
242 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
243 HORIZONTAL_ALIGNMENT_STRING_TABLE,
244 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
247 impl.mController->SetHorizontalAlignment( alignment );
252 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
254 if( impl.mController )
256 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
257 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
258 VERTICAL_ALIGNMENT_STRING_TABLE,
259 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
262 impl.mController->SetVerticalAlignment( alignment );
268 case Toolkit::TextLabel::Property::TEXT_COLOR:
270 label.SetProperty( DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, value );
271 impl.mTextUpdateNeeded = true;
275 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
277 if( impl.mController )
279 const Vector2& shadowOffset = value.Get< Vector2 >();
280 if ( impl.mController->GetShadowOffset() != shadowOffset )
282 impl.mController->SetShadowOffset( shadowOffset );
283 impl.mTextUpdateNeeded = true;
288 case Toolkit::TextLabel::Property::SHADOW_COLOR:
290 if( impl.mController )
292 const Vector4& shadowColor = value.Get< Vector4 >();
293 if ( impl.mController->GetShadowColor() != shadowColor )
295 impl.mController->SetShadowColor( shadowColor );
296 impl.mTextUpdateNeeded = true;
301 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
303 if( impl.mController )
305 const Vector4& color = value.Get< Vector4 >();
306 if ( impl.mController->GetUnderlineColor() != color )
308 impl.mController->SetUnderlineColor( color );
309 impl.mTextUpdateNeeded = true;
314 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
316 if( impl.mController )
318 const bool enabled = value.Get< bool >();
319 if ( impl.mController->IsUnderlineEnabled() != enabled )
321 impl.mController->SetUnderlineEnabled( enabled );
322 impl.mTextUpdateNeeded = true;
328 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
330 if( impl.mController )
332 float height = value.Get< float >();
333 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
335 impl.mController->SetUnderlineHeight( height );
336 impl.mTextUpdateNeeded = true;
341 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
343 if( impl.mController )
345 const bool enableMarkup = value.Get<bool>();
346 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
350 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
352 if( impl.mController )
354 const bool enableAutoScroll = value.Get<bool>();
355 // If request to auto scroll is the same as current state then do nothing.
356 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
358 // If request is disable (false) and auto scrolling is enabled then need to stop it
359 if ( enableAutoScroll == false )
361 if( impl.mTextScroller )
363 impl.mTextScroller->StopScrolling();
366 // If request is enable (true) then start autoscroll as not already running
369 impl.mController->SetTextElideEnabled( false );
370 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
376 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
378 if( !impl.mTextScroller )
380 impl.mTextScroller = Text::TextScroller::New( impl );
382 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
383 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
384 AUTO_SCROLL_STOP_MODE_TABLE,
385 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
388 impl.mTextScroller->SetStopMode( stopMode );
392 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
394 if( !impl.mTextScroller )
396 impl.mTextScroller = Text::TextScroller::New( impl );
398 impl.mTextScroller->SetSpeed( value.Get<int>() );
401 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
403 if( !impl.mTextScroller )
405 impl.mTextScroller = Text::TextScroller::New( impl );
407 impl.mTextScroller->SetLoopCount( value.Get<int>() );
410 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
412 if( !impl.mTextScroller )
414 impl.mTextScroller = Text::TextScroller::New( impl );
416 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
419 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
421 if( !impl.mTextScroller )
423 impl.mTextScroller = Text::TextScroller::New( impl );
425 impl.mTextScroller->SetGap( value.Get<float>() );
428 case Toolkit::TextLabel::Property::LINE_SPACING:
430 if( impl.mController )
432 const float lineSpacing = value.Get<float>();
433 impl.mController->SetDefaultLineSpacing( lineSpacing );
434 impl.mTextUpdateNeeded = true;
438 case Toolkit::TextLabel::Property::UNDERLINE:
440 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
443 impl.mTextUpdateNeeded = true;
447 case Toolkit::TextLabel::Property::SHADOW:
449 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
452 impl.mTextUpdateNeeded = true;
456 case Toolkit::TextLabel::Property::EMBOSS:
458 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
461 impl.mTextUpdateNeeded = true;
465 case Toolkit::TextLabel::Property::OUTLINE:
467 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
470 impl.mTextUpdateNeeded = true;
474 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
476 if( impl.mController )
478 const float pixelSize = value.Get< float >();
479 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
481 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
483 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
488 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
490 if( impl.mController )
492 const bool ellipsis = value.Get<bool>();
493 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
495 impl.mController->SetTextElideEnabled( ellipsis );
499 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
501 const std::string& wrapModeStr = value.Get< std::string >();
502 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
504 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
505 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
506 LINE_WRAP_MODE_STRING_TABLE,
507 LINE_WRAP_MODE_STRING_TABLE_COUNT,
510 impl.mController->SetLineWrapMode( lineWrapMode );
518 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
520 Property::Value value;
522 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
526 TextLabel& impl( GetImpl( label ) );
529 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
531 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
533 value = impl.mRenderingBackend;
536 case Toolkit::TextLabel::Property::TEXT:
538 if( impl.mController )
541 impl.mController->GetText( text );
546 case Toolkit::TextLabel::Property::FONT_FAMILY:
548 if( impl.mController )
550 value = impl.mController->GetDefaultFontFamily();
554 case Toolkit::TextLabel::Property::FONT_STYLE:
556 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
559 case Toolkit::TextLabel::Property::POINT_SIZE:
561 if( impl.mController )
563 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
567 case Toolkit::TextLabel::Property::MULTI_LINE:
569 if( impl.mController )
571 value = impl.mController->IsMultiLineEnabled();
575 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
577 if( impl.mController )
579 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
580 HORIZONTAL_ALIGNMENT_STRING_TABLE,
581 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
584 value = std::string( name );
589 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
591 if( impl.mController )
593 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
594 VERTICAL_ALIGNMENT_STRING_TABLE,
595 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
598 value = std::string( name );
603 case Toolkit::TextLabel::Property::TEXT_COLOR:
604 case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
606 if ( impl.mController )
608 value = impl.mController->GetDefaultColor();
612 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
614 if ( impl.mController )
616 value = impl.mController->GetShadowOffset();
620 case Toolkit::TextLabel::Property::SHADOW_COLOR:
622 if ( impl.mController )
624 value = impl.mController->GetShadowColor();
628 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
630 if ( impl.mController )
632 value = impl.mController->GetUnderlineColor();
636 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
638 if ( impl.mController )
640 value = impl.mController->IsUnderlineEnabled();
644 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
646 if ( impl.mController )
648 value = impl.mController->GetUnderlineHeight();
652 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
654 if( impl.mController )
656 value = impl.mController->IsMarkupProcessorEnabled();
660 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
662 if( impl.mController )
664 value = impl.mController->IsAutoScrollEnabled();
668 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
670 if( impl.mTextScroller )
672 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
673 AUTO_SCROLL_STOP_MODE_TABLE,
674 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
677 value = std::string( mode );
682 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
684 TextLabel& impl( GetImpl( label ) );
685 if ( impl.mTextScroller )
687 value = impl.mTextScroller->GetSpeed();
691 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
693 if( impl.mController )
695 TextLabel& impl( GetImpl( label ) );
696 if ( impl.mTextScroller )
698 value = impl.mTextScroller->GetLoopCount();
703 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
705 if( impl.mController )
707 TextLabel& impl( GetImpl( label ) );
708 if ( impl.mTextScroller )
710 value = impl.mTextScroller->GetLoopDelay();
715 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
717 TextLabel& impl( GetImpl( label ) );
718 if ( impl.mTextScroller )
720 value = impl.mTextScroller->GetGap();
724 case Toolkit::TextLabel::Property::LINE_SPACING:
726 if( impl.mController )
728 value = impl.mController->GetDefaultLineSpacing();
732 case Toolkit::TextLabel::Property::UNDERLINE:
734 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
737 case Toolkit::TextLabel::Property::SHADOW:
739 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
742 case Toolkit::TextLabel::Property::EMBOSS:
744 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
747 case Toolkit::TextLabel::Property::OUTLINE:
749 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
752 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
754 if( impl.mController )
756 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
760 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
762 if( impl.mController )
764 value = impl.mController->IsTextElideEnabled();
768 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
770 if( impl.mController )
772 value = impl.mController->GetLineWrapMode();
776 case Toolkit::DevelTextLabel::Property::LINE_COUNT:
778 if( impl.mController )
780 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
781 value = impl.mController->GetLineCount( width );
791 void TextLabel::OnInitialize()
795 Property::Map propertyMap;
796 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT );
798 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
799 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
801 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE );
803 mController = TextVisual::GetController(mVisual);
806 mController->SetControlInterface(this);
809 // Use height-for-width negotiation by default
810 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
811 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
813 // Enable the text ellipsis.
814 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
816 Layout::Engine& engine = mController->GetLayoutEngine();
817 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
820 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
822 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
826 case StyleChange::DEFAULT_FONT_CHANGE:
828 // Property system did not set the font so should update it.
829 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
830 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
831 mController->UpdateAfterFontChange( newFont );
835 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
837 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
841 case StyleChange::THEME_CHANGE:
843 // Nothing to do, let control base class handle this
848 // Up call to Control
849 Control::OnStyleChange( styleManager, change );
852 Vector3 TextLabel::GetNaturalSize()
854 return mController->GetNaturalSize();
857 float TextLabel::GetHeightForWidth( float width )
860 Self().GetPadding( padding );
861 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
864 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
866 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
870 case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
872 const Vector4& textColor = propertyValue.Get< Vector4 >();
873 if( mController->GetDefaultColor() != textColor )
875 mController->SetDefaultColor( textColor );
876 mTextUpdateNeeded = true;
882 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
888 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
890 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
893 Self().GetPadding( padding );
894 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
896 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
898 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
899 || mTextUpdateNeeded )
901 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
904 TextVisual::EnableRendererUpdate( mVisual );
907 Self().GetPadding( padding );
909 Property::Map visualTransform;
910 visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, contentSize )
911 .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) )
912 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
913 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::ABSOLUTE, Toolkit::DevelVisual::Transform::Policy::ABSOLUTE ) )
914 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
915 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
916 mVisual.SetTransformAndSize( visualTransform, size );
918 if ( mController->IsAutoScrollEnabled() )
920 SetUpAutoScrolling();
923 mTextUpdateNeeded = false;
927 void TextLabel::RequestTextRelayout()
932 void TextLabel::SetUpAutoScrolling()
934 const Size& controlSize = mController->GetView().GetControlSize();
935 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.
936 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
938 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
939 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
941 if ( !mTextScroller )
943 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
945 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
946 mTextScroller = Text::TextScroller::New( *this );
949 // Create a texture of the text for scrolling
950 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
951 PixelData data = typesetter->Render( textNaturalSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true ); // ignore the horizontal alignment
952 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
953 data.GetPixelFormat(),
956 texture.Upload( data );
958 TextureSet textureSet = TextureSet::New();
959 textureSet.SetTexture( 0u, texture );
961 // Filter mode needs to be set to nearest to avoid blurry text.
962 Sampler sampler = Sampler::New();
963 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
964 textureSet.SetSampler( 0u, sampler );
966 // Set parameters for scrolling
967 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
968 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, textNaturalSize, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
971 void TextLabel::ScrollingFinished()
973 // Pure Virtual from TextScroller Interface
974 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
975 mController->SetAutoScrollEnabled( false );
976 mController->SetTextElideEnabled( true );
977 RequestTextRelayout();
980 TextLabel::TextLabel()
981 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
982 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
983 mTextUpdateNeeded( false )
987 TextLabel::~TextLabel()
991 } // namespace Internal
993 } // namespace Toolkit