2 * Copyright (c) 2019 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/public-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/devel-api/adaptor-framework/image-loading.h>
26 #include <dali/integration-api/debug.h>
29 #include <dali-toolkit/public-api/text/rendering-backend.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/internal/text/property-string-parser.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-effects-style.h>
35 #include <dali-toolkit/internal/text/text-font-style.h>
36 #include <dali-toolkit/internal/text/text-view.h>
37 #include <dali-toolkit/internal/text/text-definitions.h>
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40 #include <dali-toolkit/public-api/align-enumerations.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/devel-api/controls/control-devel.h>
43 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
44 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
45 #include <dali-toolkit/public-api/visuals/visual-properties.h>
46 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
48 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
50 using namespace Dali::Toolkit::Text;
63 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
66 * @brief How the text visual should be aligned vertically inside the control.
68 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
69 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
71 const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
73 0.0f, // VerticalAlignment::TOP
74 0.5f, // VerticalAlignment::CENTER
75 1.0f // VerticalAlignment::BOTTOM
78 const std::string TEXT_FIT_ENABLE_KEY( "enable" );
79 const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
80 const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
81 const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
82 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
88 #if defined ( DEBUG_ENABLED )
89 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
92 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
94 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
95 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
97 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
102 return Toolkit::TextLabel::New();
105 // Setup properties, signals and actions using the type-registry.
106 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty03", STRING, RESERVED_PROPERTY_03 )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty04", STRING, RESERVED_PROPERTY_04 )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "reservedProperty05", STRING, RESERVED_PROPERTY_05 )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
136 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
143 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
144 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
145 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
147 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
149 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
150 DALI_TYPE_REGISTRATION_END()
154 Toolkit::TextLabel TextLabel::New()
156 // Create the implementation, temporarily owned by this handle on stack
157 IntrusivePtr< TextLabel > impl = new TextLabel();
159 // Pass ownership to CustomActor handle
160 Toolkit::TextLabel handle( *impl );
162 // Second-phase init of the implementation
163 // This can only be done after the CustomActor connection has been made...
169 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
171 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
175 TextLabel& impl( GetImpl( label ) );
178 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
180 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
182 int backend = value.Get< int >();
184 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
185 if( Text::RENDERING_VECTOR_BASED == backend )
187 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
190 if( impl.mRenderingBackend != backend )
192 impl.mRenderingBackend = backend;
193 impl.mTextUpdateNeeded = true;
195 if( impl.mController )
197 // When using the vector-based rendering, the size of the GLyphs are different
198 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
199 impl.mController->SetGlyphType( glyphType );
204 case Toolkit::TextLabel::Property::TEXT:
206 if( impl.mController )
208 impl.mController->SetText( value.Get< std::string >() );
212 case Toolkit::TextLabel::Property::FONT_FAMILY:
214 if( impl.mController )
216 const std::string& fontFamily = value.Get< std::string >();
218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
219 impl.mController->SetDefaultFontFamily( fontFamily );
223 case Toolkit::TextLabel::Property::FONT_STYLE:
225 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
228 case Toolkit::TextLabel::Property::POINT_SIZE:
230 if( impl.mController )
232 const float pointSize = value.Get< float >();
234 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
236 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
241 case Toolkit::TextLabel::Property::MULTI_LINE:
243 if( impl.mController )
245 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
249 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
251 if( impl.mController )
253 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
254 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
256 impl.mController->SetHorizontalAlignment( alignment );
261 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
263 if( impl.mController )
265 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
266 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
268 impl.mController->SetVerticalAlignment( alignment );
274 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
276 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
277 impl.mTextUpdateNeeded = true;
280 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
282 if( impl.mController )
284 const bool enableMarkup = value.Get<bool>();
285 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
289 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
291 if( impl.mController )
293 const bool enableAutoScroll = value.Get<bool>();
294 // If request to auto scroll is the same as current state then do nothing.
295 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
297 // If request is disable (false) and auto scrolling is enabled then need to stop it
298 if ( enableAutoScroll == false )
300 if( impl.mTextScroller )
302 impl.mTextScroller->StopScrolling();
305 // If request is enable (true) then start autoscroll as not already running
308 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
314 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
316 if( !impl.mTextScroller )
318 impl.mTextScroller = Text::TextScroller::New( impl );
320 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
321 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
322 AUTO_SCROLL_STOP_MODE_TABLE,
323 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
326 impl.mTextScroller->SetStopMode( stopMode );
330 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
332 if( !impl.mTextScroller )
334 impl.mTextScroller = Text::TextScroller::New( impl );
336 impl.mTextScroller->SetSpeed( value.Get<int>() );
339 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
341 if( !impl.mTextScroller )
343 impl.mTextScroller = Text::TextScroller::New( impl );
345 impl.mTextScroller->SetLoopCount( value.Get<int>() );
348 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
350 if( !impl.mTextScroller )
352 impl.mTextScroller = Text::TextScroller::New( impl );
354 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
357 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
359 if( !impl.mTextScroller )
361 impl.mTextScroller = Text::TextScroller::New( impl );
363 impl.mTextScroller->SetGap( value.Get<float>() );
366 case Toolkit::TextLabel::Property::LINE_SPACING:
368 if( impl.mController )
370 const float lineSpacing = value.Get<float>();
372 // Don't trigger anything if the line spacing didn't change
373 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
375 impl.mTextUpdateNeeded = true;
380 case Toolkit::TextLabel::Property::UNDERLINE:
382 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
385 impl.mTextUpdateNeeded = true;
389 case Toolkit::TextLabel::Property::SHADOW:
391 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
394 impl.mTextUpdateNeeded = true;
398 case Toolkit::TextLabel::Property::EMBOSS:
400 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
403 impl.mTextUpdateNeeded = true;
407 case Toolkit::TextLabel::Property::OUTLINE:
409 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
412 impl.mTextUpdateNeeded = true;
416 case Toolkit::TextLabel::Property::PIXEL_SIZE:
418 if( impl.mController )
420 const float pixelSize = value.Get< float >();
421 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
423 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
425 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
430 case Toolkit::TextLabel::Property::ELLIPSIS:
432 if( impl.mController )
434 const bool ellipsis = value.Get<bool>();
435 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
437 impl.mController->SetTextElideEnabled( ellipsis );
441 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
443 if( impl.mController )
445 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
446 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
448 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
449 impl.mController->SetLineWrapMode( lineWrapMode );
454 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
456 if( impl.mController && impl.mController->GetTextModel() )
458 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
460 impl.mController->SetVerticalLineAlignment( alignment );
462 // Property doesn't affect the layout, only Visual must be updated
463 TextVisual::EnableRendererUpdate( impl.mVisual );
465 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
466 TextVisual::UpdateRenderer( impl.mVisual );
470 case Toolkit::DevelTextLabel::Property::BACKGROUND:
472 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
475 impl.mTextUpdateNeeded = true;
479 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
481 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
484 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
486 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
489 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
491 const Property::Map& propertiesMap = value.Get<Property::Map>();
493 bool enabled = false;
496 float stepSize = 0.f;
497 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
498 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
500 if ( !propertiesMap.Empty() )
502 const unsigned int numberOfItems = propertiesMap.Count();
504 // Parses and applies
505 for( unsigned int index = 0u; index < numberOfItems; ++index )
507 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
509 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
512 enabled = valueGet.second.Get< bool >();
514 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
517 minSize = valueGet.second.Get< float >();
520 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
523 maxSize = valueGet.second.Get< float >();
526 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
529 stepSize = valueGet.second.Get< float >();
530 isStepSizeSet = true;
532 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
534 if( "pixelSize" == valueGet.second.Get< std::string >() )
536 type = Controller::FontSizeType::PIXEL_SIZE;
541 impl.mController->SetTextFitEnabled( enabled );
544 impl.mController->SetTextFitMinSize( minSize, type );
548 impl.mController->SetTextFitMaxSize( maxSize, type );
552 impl.mController->SetTextFitStepSize( stepSize, type );
557 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
559 if( impl.mController )
561 const float lineSize = value.Get<float>();
563 if( impl.mController->SetDefaultLineSize( lineSize ) )
565 impl.mTextUpdateNeeded = true;
572 // Request relayout when text update is needed. It's necessary to call it
573 // as changing the property not via UI interaction brings no effect if only
574 // the mTextUpdateNeeded is changed.
575 if( impl.mTextUpdateNeeded )
577 // need to request relayout as size of text may have changed
578 impl.RequestTextRelayout();
583 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
585 Property::Value value;
587 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
591 TextLabel& impl( GetImpl( label ) );
594 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
596 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
598 value = impl.mRenderingBackend;
601 case Toolkit::TextLabel::Property::TEXT:
603 if( impl.mController )
606 impl.mController->GetText( text );
611 case Toolkit::TextLabel::Property::FONT_FAMILY:
613 if( impl.mController )
615 value = impl.mController->GetDefaultFontFamily();
619 case Toolkit::TextLabel::Property::FONT_STYLE:
621 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
624 case Toolkit::TextLabel::Property::POINT_SIZE:
626 if( impl.mController )
628 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
632 case Toolkit::TextLabel::Property::MULTI_LINE:
634 if( impl.mController )
636 value = impl.mController->IsMultiLineEnabled();
640 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
642 if( impl.mController )
644 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
648 value = std::string( name );
653 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
655 if( impl.mController )
657 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
660 value = std::string( name );
665 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
667 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
670 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
672 if( impl.mController )
674 value = impl.mController->IsMarkupProcessorEnabled();
678 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
680 if( impl.mController )
682 value = impl.mController->IsAutoScrollEnabled();
686 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
688 if( impl.mTextScroller )
690 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
691 AUTO_SCROLL_STOP_MODE_TABLE,
692 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
695 value = std::string( mode );
700 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
702 TextLabel& impl( GetImpl( label ) );
703 if ( impl.mTextScroller )
705 value = impl.mTextScroller->GetSpeed();
709 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
711 if( impl.mController )
713 TextLabel& impl( GetImpl( label ) );
714 if ( impl.mTextScroller )
716 value = impl.mTextScroller->GetLoopCount();
721 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
723 if( impl.mController )
725 TextLabel& impl( GetImpl( label ) );
726 if ( impl.mTextScroller )
728 value = impl.mTextScroller->GetLoopDelay();
733 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
735 TextLabel& impl( GetImpl( label ) );
736 if ( impl.mTextScroller )
738 value = impl.mTextScroller->GetGap();
742 case Toolkit::TextLabel::Property::LINE_SPACING:
744 if( impl.mController )
746 value = impl.mController->GetDefaultLineSpacing();
750 case Toolkit::TextLabel::Property::UNDERLINE:
752 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
755 case Toolkit::TextLabel::Property::SHADOW:
757 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
760 case Toolkit::TextLabel::Property::EMBOSS:
762 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
765 case Toolkit::TextLabel::Property::OUTLINE:
767 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
770 case Toolkit::TextLabel::Property::PIXEL_SIZE:
772 if( impl.mController )
774 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
778 case Toolkit::TextLabel::Property::ELLIPSIS:
780 if( impl.mController )
782 value = impl.mController->IsTextElideEnabled();
786 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
788 if( impl.mController )
790 value = impl.mController->GetLineWrapMode();
794 case Toolkit::TextLabel::Property::LINE_COUNT:
796 if( impl.mController )
798 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
799 value = impl.mController->GetLineCount( width );
803 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
805 if( impl.mController )
807 value = impl.mController->GetTextDirection();
811 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
813 if( impl.mController )
815 value = impl.mController->GetVerticalLineAlignment();
819 case Toolkit::DevelTextLabel::Property::BACKGROUND:
821 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
824 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
826 value = impl.mController->IsIgnoreSpacesAfterText();
829 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
831 value = impl.mController->IsMatchSystemLanguageDirection();
834 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
836 const bool enabled = impl.mController->IsTextFitEnabled();
837 const float minSize = impl.mController->GetTextFitMinSize();
838 const float maxSize = impl.mController->GetTextFitMaxSize();
839 const float stepSize = impl.mController->GetTextFitStepSize();
842 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
843 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
844 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
845 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
846 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
851 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
853 if( impl.mController )
855 value = impl.mController->GetDefaultLineSize();
865 void TextLabel::OnInitialize()
869 Property::Map propertyMap;
870 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
872 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
873 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
875 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
877 mController = TextVisual::GetController(mVisual);
880 mController->SetControlInterface(this);
883 // Use height-for-width negotiation by default
884 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
885 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
887 // Enable the text ellipsis.
888 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
890 // Sets layoutDirection value
891 Dali::Stage stage = Dali::Stage::GetCurrent();
892 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
893 mController->SetLayoutDirection( layoutDirection );
895 Layout::Engine& engine = mController->GetLayoutEngine();
896 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
899 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
901 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
905 case StyleChange::DEFAULT_FONT_CHANGE:
907 // Property system did not set the font so should update it.
908 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
909 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
910 mController->UpdateAfterFontChange( newFont );
914 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
916 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
920 case StyleChange::THEME_CHANGE:
922 // Nothing to do, let control base class handle this
927 // Up call to Control
928 Control::OnStyleChange( styleManager, change );
931 Vector3 TextLabel::GetNaturalSize()
934 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
936 Vector3 naturalSize = mController->GetNaturalSize();
937 naturalSize.width += ( padding.start + padding.end );
938 naturalSize.height += ( padding.top + padding.bottom );
943 float TextLabel::GetHeightForWidth( float width )
946 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
948 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
951 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
953 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
957 case Toolkit::TextLabel::Property::TEXT_COLOR:
959 const Vector4& textColor = propertyValue.Get< Vector4 >();
960 if( mController->GetDefaultColor() != textColor )
962 mController->SetDefaultColor( textColor );
963 mTextUpdateNeeded = true;
969 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
975 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
977 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
980 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
982 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
984 if( mController->IsTextFitEnabled() )
986 mController->FitPointSizeforLayout( contentSize );
987 mController->SetTextFitContentSize( contentSize );
990 // Support Right-To-Left
991 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
993 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
995 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
996 || mTextUpdateNeeded )
998 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
1000 // Update the visual
1001 TextVisual::EnableRendererUpdate( mVisual );
1003 // Support Right-To-Left of padding
1004 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1006 std::swap( padding.start, padding.end );
1009 // Calculate the size of the visual that can fit the text
1010 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
1011 layoutSize.x = contentSize.x;
1013 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1014 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
1016 layoutSize.y += shadowOffset.y;
1019 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1020 layoutSize.y += outlineWidth * 2.0f;
1021 layoutSize.y = std::min( layoutSize.y, contentSize.y );
1023 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1024 Vector2 alignmentOffset;
1025 alignmentOffset.x = 0.0f;
1026 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1028 Property::Map visualTransform;
1029 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1030 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1031 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1032 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1033 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1034 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1035 mVisual.SetTransformAndSize( visualTransform, size );
1037 if ( mController->IsAutoScrollEnabled() )
1039 SetUpAutoScrolling();
1042 mTextUpdateNeeded = false;
1046 void TextLabel::RequestTextRelayout()
1049 // Signal that a Relayout may be needed
1052 void TextLabel::SetUpAutoScrolling()
1054 const Size& controlSize = mController->GetView().GetControlSize();
1055 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.
1056 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1058 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1059 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1061 if ( !mTextScroller )
1063 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1065 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1066 mTextScroller = Text::TextScroller::New( *this );
1069 // Calculate the actual gap before scrolling wraps.
1070 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1071 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1072 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1074 // Create a texture of the text for scrolling
1075 Size verifiedSize = textureSize;
1076 const int maxTextureSize = Dali::GetMaxTextureSize();
1078 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1079 bool actualellipsis = mController->IsTextElideEnabled();
1080 if( verifiedSize.width > maxTextureSize )
1082 verifiedSize.width = maxTextureSize;
1083 if( textNaturalSize.width > maxTextureSize )
1085 mController->SetTextElideEnabled( true );
1087 GetHeightForWidth( maxTextureSize );
1088 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1091 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1093 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1094 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1095 data.GetPixelFormat(),
1098 texture.Upload( data );
1100 TextureSet textureSet = TextureSet::New();
1101 textureSet.SetTexture( 0u, texture );
1103 // Filter mode needs to be set to linear to produce better quality while scaling.
1104 Sampler sampler = Sampler::New();
1105 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1106 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1107 textureSet.SetSampler( 0u, sampler );
1109 // Set parameters for scrolling
1110 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1111 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1112 mController->SetTextElideEnabled( actualellipsis );
1115 void TextLabel::ScrollingFinished()
1117 // Pure Virtual from TextScroller Interface
1118 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1119 mController->SetAutoScrollEnabled( false );
1120 RequestTextRelayout();
1123 TextLabel::TextLabel()
1124 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1125 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1126 mTextUpdateNeeded( false )
1130 TextLabel::~TextLabel()
1134 } // namespace Internal
1136 } // namespace Toolkit