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] );
79 return Toolkit::TextLabel::New();
82 // Setup properties, signals and actions using the type-registry.
83 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
113 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
115 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
116 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
117 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
118 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
119 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
120 DALI_TYPE_REGISTRATION_END()
124 Toolkit::TextLabel TextLabel::New()
126 // Create the implementation, temporarily owned by this handle on stack
127 IntrusivePtr< TextLabel > impl = new TextLabel();
129 // Pass ownership to CustomActor handle
130 Toolkit::TextLabel handle( *impl );
132 // Second-phase init of the implementation
133 // This can only be done after the CustomActor connection has been made...
139 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
141 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
145 TextLabel& impl( GetImpl( label ) );
148 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
150 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
152 int backend = value.Get< int >();
154 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
155 if( Text::RENDERING_VECTOR_BASED == backend )
157 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
160 if( impl.mRenderingBackend != backend )
162 impl.mRenderingBackend = backend;
163 impl.mTextUpdateNeeded = true;
165 if( impl.mController )
167 // When using the vector-based rendering, the size of the GLyphs are different
168 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
169 impl.mController->SetGlyphType( glyphType );
174 case Toolkit::TextLabel::Property::TEXT:
176 if( impl.mController )
178 impl.mController->SetText( value.Get< std::string >() );
182 case Toolkit::TextLabel::Property::FONT_FAMILY:
184 if( impl.mController )
186 const std::string& fontFamily = value.Get< std::string >();
188 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
189 impl.mController->SetDefaultFontFamily( fontFamily );
193 case Toolkit::TextLabel::Property::FONT_STYLE:
195 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
198 case Toolkit::TextLabel::Property::POINT_SIZE:
200 if( impl.mController )
202 const float pointSize = value.Get< float >();
204 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
206 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
211 case Toolkit::TextLabel::Property::MULTI_LINE:
213 if( impl.mController )
215 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
219 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
221 if( impl.mController )
223 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
224 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
226 impl.mController->SetHorizontalAlignment( alignment );
231 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
233 if( impl.mController )
235 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
236 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
238 impl.mController->SetVerticalAlignment( alignment );
244 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
246 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
247 impl.mTextUpdateNeeded = true;
251 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
253 if( impl.mController )
255 const Vector2& shadowOffset = value.Get< Vector2 >();
256 if ( impl.mController->GetShadowOffset() != shadowOffset )
258 impl.mController->SetShadowOffset( shadowOffset );
259 impl.mTextUpdateNeeded = true;
264 case Toolkit::TextLabel::Property::SHADOW_COLOR:
266 if( impl.mController )
268 const Vector4& shadowColor = value.Get< Vector4 >();
269 if ( impl.mController->GetShadowColor() != shadowColor )
271 impl.mController->SetShadowColor( shadowColor );
272 impl.mTextUpdateNeeded = true;
277 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
279 if( impl.mController )
281 const Vector4& color = value.Get< Vector4 >();
282 if ( impl.mController->GetUnderlineColor() != color )
284 impl.mController->SetUnderlineColor( color );
285 impl.mTextUpdateNeeded = true;
290 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
292 if( impl.mController )
294 const bool enabled = value.Get< bool >();
295 if ( impl.mController->IsUnderlineEnabled() != enabled )
297 impl.mController->SetUnderlineEnabled( enabled );
298 impl.mTextUpdateNeeded = true;
304 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
306 if( impl.mController )
308 float height = value.Get< float >();
309 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
311 impl.mController->SetUnderlineHeight( height );
312 impl.mTextUpdateNeeded = true;
317 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
319 if( impl.mController )
321 const bool enableMarkup = value.Get<bool>();
322 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
326 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
328 if( impl.mController )
330 const bool enableAutoScroll = value.Get<bool>();
331 // If request to auto scroll is the same as current state then do nothing.
332 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
334 // If request is disable (false) and auto scrolling is enabled then need to stop it
335 if ( enableAutoScroll == false )
337 if( impl.mTextScroller )
339 impl.mTextScroller->StopScrolling();
342 // If request is enable (true) then start autoscroll as not already running
345 impl.mController->SetTextElideEnabled( false );
346 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
352 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
354 if( !impl.mTextScroller )
356 impl.mTextScroller = Text::TextScroller::New( impl );
358 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
359 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
360 AUTO_SCROLL_STOP_MODE_TABLE,
361 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
364 impl.mTextScroller->SetStopMode( stopMode );
368 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
370 if( !impl.mTextScroller )
372 impl.mTextScroller = Text::TextScroller::New( impl );
374 impl.mTextScroller->SetSpeed( value.Get<int>() );
377 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
379 if( !impl.mTextScroller )
381 impl.mTextScroller = Text::TextScroller::New( impl );
383 impl.mTextScroller->SetLoopCount( value.Get<int>() );
386 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
388 if( !impl.mTextScroller )
390 impl.mTextScroller = Text::TextScroller::New( impl );
392 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
395 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
397 if( !impl.mTextScroller )
399 impl.mTextScroller = Text::TextScroller::New( impl );
401 impl.mTextScroller->SetGap( value.Get<float>() );
404 case Toolkit::TextLabel::Property::LINE_SPACING:
406 if( impl.mController )
408 const float lineSpacing = value.Get<float>();
409 impl.mController->SetDefaultLineSpacing( lineSpacing );
410 impl.mTextUpdateNeeded = true;
414 case Toolkit::TextLabel::Property::UNDERLINE:
416 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
419 impl.mTextUpdateNeeded = true;
423 case Toolkit::TextLabel::Property::SHADOW:
425 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
428 impl.mTextUpdateNeeded = true;
432 case Toolkit::TextLabel::Property::EMBOSS:
434 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
437 impl.mTextUpdateNeeded = true;
441 case Toolkit::TextLabel::Property::OUTLINE:
443 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
446 impl.mTextUpdateNeeded = true;
450 case Toolkit::TextLabel::Property::PIXEL_SIZE:
452 if( impl.mController )
454 const float pixelSize = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
457 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
459 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
464 case Toolkit::TextLabel::Property::ELLIPSIS:
466 if( impl.mController )
468 const bool ellipsis = value.Get<bool>();
469 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
471 impl.mController->SetTextElideEnabled( ellipsis );
475 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
477 if( impl.mController )
479 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
480 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
482 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
483 impl.mController->SetLineWrapMode( lineWrapMode );
492 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
494 Property::Value value;
496 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
500 TextLabel& impl( GetImpl( label ) );
503 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
505 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
507 value = impl.mRenderingBackend;
510 case Toolkit::TextLabel::Property::TEXT:
512 if( impl.mController )
515 impl.mController->GetText( text );
520 case Toolkit::TextLabel::Property::FONT_FAMILY:
522 if( impl.mController )
524 value = impl.mController->GetDefaultFontFamily();
528 case Toolkit::TextLabel::Property::FONT_STYLE:
530 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
533 case Toolkit::TextLabel::Property::POINT_SIZE:
535 if( impl.mController )
537 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
541 case Toolkit::TextLabel::Property::MULTI_LINE:
543 if( impl.mController )
545 value = impl.mController->IsMultiLineEnabled();
549 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
551 if( impl.mController )
553 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
557 value = std::string( name );
562 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
564 if( impl.mController )
566 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
569 value = std::string( name );
574 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
576 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
579 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
581 if ( impl.mController )
583 value = impl.mController->GetShadowOffset();
587 case Toolkit::TextLabel::Property::SHADOW_COLOR:
589 if ( impl.mController )
591 value = impl.mController->GetShadowColor();
595 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
597 if ( impl.mController )
599 value = impl.mController->GetUnderlineColor();
603 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
605 if ( impl.mController )
607 value = impl.mController->IsUnderlineEnabled();
611 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
613 if ( impl.mController )
615 value = impl.mController->GetUnderlineHeight();
619 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
621 if( impl.mController )
623 value = impl.mController->IsMarkupProcessorEnabled();
627 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
629 if( impl.mController )
631 value = impl.mController->IsAutoScrollEnabled();
635 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
637 if( impl.mTextScroller )
639 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
640 AUTO_SCROLL_STOP_MODE_TABLE,
641 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
644 value = std::string( mode );
649 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
651 TextLabel& impl( GetImpl( label ) );
652 if ( impl.mTextScroller )
654 value = impl.mTextScroller->GetSpeed();
658 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
660 if( impl.mController )
662 TextLabel& impl( GetImpl( label ) );
663 if ( impl.mTextScroller )
665 value = impl.mTextScroller->GetLoopCount();
670 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
672 if( impl.mController )
674 TextLabel& impl( GetImpl( label ) );
675 if ( impl.mTextScroller )
677 value = impl.mTextScroller->GetLoopDelay();
682 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
684 TextLabel& impl( GetImpl( label ) );
685 if ( impl.mTextScroller )
687 value = impl.mTextScroller->GetGap();
691 case Toolkit::TextLabel::Property::LINE_SPACING:
693 if( impl.mController )
695 value = impl.mController->GetDefaultLineSpacing();
699 case Toolkit::TextLabel::Property::UNDERLINE:
701 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
704 case Toolkit::TextLabel::Property::SHADOW:
706 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
709 case Toolkit::TextLabel::Property::EMBOSS:
711 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
714 case Toolkit::TextLabel::Property::OUTLINE:
716 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
719 case Toolkit::TextLabel::Property::PIXEL_SIZE:
721 if( impl.mController )
723 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
727 case Toolkit::TextLabel::Property::ELLIPSIS:
729 if( impl.mController )
731 value = impl.mController->IsTextElideEnabled();
735 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
737 if( impl.mController )
739 value = impl.mController->GetLineWrapMode();
743 case Toolkit::TextLabel::Property::LINE_COUNT:
745 if( impl.mController )
747 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
748 value = impl.mController->GetLineCount( width );
758 void TextLabel::OnInitialize()
762 Property::Map propertyMap;
763 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
765 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
766 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
768 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
770 mController = TextVisual::GetController(mVisual);
773 mController->SetControlInterface(this);
776 // Use height-for-width negotiation by default
777 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
778 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
780 // Enable the text ellipsis.
781 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
783 Layout::Engine& engine = mController->GetLayoutEngine();
784 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
787 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
789 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
793 case StyleChange::DEFAULT_FONT_CHANGE:
795 // Property system did not set the font so should update it.
796 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
797 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
798 mController->UpdateAfterFontChange( newFont );
802 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
804 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
808 case StyleChange::THEME_CHANGE:
810 // Nothing to do, let control base class handle this
815 // Up call to Control
816 Control::OnStyleChange( styleManager, change );
819 Vector3 TextLabel::GetNaturalSize()
821 return mController->GetNaturalSize();
824 float TextLabel::GetHeightForWidth( float width )
827 Self().GetPadding( padding );
828 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
831 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
833 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
837 case Toolkit::TextLabel::Property::TEXT_COLOR:
839 const Vector4& textColor = propertyValue.Get< Vector4 >();
840 if( mController->GetDefaultColor() != textColor )
842 mController->SetDefaultColor( textColor );
843 mTextUpdateNeeded = true;
849 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
855 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
857 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
860 Self().GetPadding( padding );
861 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
863 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
865 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
866 || mTextUpdateNeeded )
868 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
871 TextVisual::EnableRendererUpdate( mVisual );
874 Self().GetPadding( padding );
876 Property::Map visualTransform;
877 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, contentSize )
878 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
879 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(padding.left, padding.top) )
880 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
881 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
882 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
883 mVisual.SetTransformAndSize( visualTransform, size );
885 if ( mController->IsAutoScrollEnabled() )
887 SetUpAutoScrolling();
890 mTextUpdateNeeded = false;
894 void TextLabel::RequestTextRelayout()
899 void TextLabel::SetUpAutoScrolling()
901 const Size& controlSize = mController->GetView().GetControlSize();
902 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.
903 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
905 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
906 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
908 if ( !mTextScroller )
910 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
912 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
913 mTextScroller = Text::TextScroller::New( *this );
916 // Create a texture of the text for scrolling
917 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
918 PixelData data = typesetter->Render( textNaturalSize, Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
919 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
920 data.GetPixelFormat(),
923 texture.Upload( data );
925 TextureSet textureSet = TextureSet::New();
926 textureSet.SetTexture( 0u, texture );
928 // Filter mode needs to be set to linear to produce better quality while scaling.
929 Sampler sampler = Sampler::New();
930 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
931 textureSet.SetSampler( 0u, sampler );
933 // Set parameters for scrolling
934 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
935 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, textNaturalSize, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
938 void TextLabel::ScrollingFinished()
940 // Pure Virtual from TextScroller Interface
941 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
942 mController->SetAutoScrollEnabled( false );
943 mController->SetTextElideEnabled( true );
944 RequestTextRelayout();
947 TextLabel::TextLabel()
948 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
949 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
950 mTextUpdateNeeded( false )
954 TextLabel::~TextLabel()
958 } // namespace Internal
960 } // namespace Toolkit