2 * Copyright (c) 2020 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/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/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/integration-api/debug.h>
30 #include <dali-toolkit/public-api/text/text-enumerations.h>
31 #include <dali-toolkit/devel-api/text/rendering-backend.h>
32 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/text/property-string-parser.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-effects-style.h>
36 #include <dali-toolkit/internal/text/text-font-style.h>
37 #include <dali-toolkit/internal/text/text-view.h>
38 #include <dali-toolkit/internal/text/text-definitions.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/public-api/align-enumerations.h>
42 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
43 #include <dali-toolkit/devel-api/controls/control-devel.h>
44 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
45 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
46 #include <dali-toolkit/public-api/visuals/visual-properties.h>
47 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
49 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
51 using namespace Dali::Toolkit::Text;
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
67 * @brief How the text visual should be aligned vertically inside the control.
69 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
70 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
72 const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
74 0.0f, // VerticalAlignment::TOP
75 0.5f, // VerticalAlignment::CENTER
76 1.0f // VerticalAlignment::BOTTOM
79 const std::string TEXT_FIT_ENABLE_KEY( "enable" );
80 const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
81 const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
82 const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
83 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
89 #if defined ( DEBUG_ENABLED )
90 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
93 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
95 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
96 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
98 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
103 return Toolkit::TextLabel::New();
106 // Setup properties, signals and actions using the type-registry.
107 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
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, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
130 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
132 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
141 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
142 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
143 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
144 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
145 DALI_TYPE_REGISTRATION_END()
149 Toolkit::TextLabel TextLabel::New()
151 // Create the implementation, temporarily owned by this handle on stack
152 IntrusivePtr< TextLabel > impl = new TextLabel();
154 // Pass ownership to CustomActor handle
155 Toolkit::TextLabel handle( *impl );
157 // Second-phase init of the implementation
158 // This can only be done after the CustomActor connection has been made...
164 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
166 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
170 TextLabel& impl( GetImpl( label ) );
173 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
175 int backend = value.Get< int >();
177 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
178 if( DevelText::RENDERING_VECTOR_BASED == backend )
180 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
183 if( impl.mRenderingBackend != backend )
185 impl.mRenderingBackend = backend;
186 impl.mTextUpdateNeeded = true;
188 if( impl.mController )
190 // When using the vector-based rendering, the size of the GLyphs are different
191 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
192 impl.mController->SetGlyphType( glyphType );
197 case Toolkit::TextLabel::Property::TEXT:
199 if( impl.mController )
201 impl.mController->SetText( value.Get< std::string >() );
205 case Toolkit::TextLabel::Property::FONT_FAMILY:
207 if( impl.mController )
209 const std::string& fontFamily = value.Get< std::string >();
211 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
212 impl.mController->SetDefaultFontFamily( fontFamily );
216 case Toolkit::TextLabel::Property::FONT_STYLE:
218 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
221 case Toolkit::TextLabel::Property::POINT_SIZE:
223 if( impl.mController )
225 const float pointSize = value.Get< float >();
227 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
229 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
234 case Toolkit::TextLabel::Property::MULTI_LINE:
236 if( impl.mController )
238 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
242 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
244 if( impl.mController )
246 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
247 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
249 impl.mController->SetHorizontalAlignment( alignment );
254 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
256 if( impl.mController )
258 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
259 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
261 impl.mController->SetVerticalAlignment( alignment );
266 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
268 if( impl.mController )
270 const bool enableMarkup = value.Get<bool>();
271 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
275 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
277 if( impl.mController )
279 const bool enableAutoScroll = value.Get<bool>();
280 // If request to auto scroll is the same as current state then do nothing.
281 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
283 // If request is disable (false) and auto scrolling is enabled then need to stop it
284 if ( enableAutoScroll == false )
286 if( impl.mTextScroller )
288 impl.mTextScroller->StopScrolling();
291 // If request is enable (true) then start autoscroll as not already running
294 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
300 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
302 if( !impl.mTextScroller )
304 impl.mTextScroller = Text::TextScroller::New( impl );
306 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
307 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
308 AUTO_SCROLL_STOP_MODE_TABLE,
309 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
312 impl.mTextScroller->SetStopMode( stopMode );
316 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
318 if( !impl.mTextScroller )
320 impl.mTextScroller = Text::TextScroller::New( impl );
322 impl.mTextScroller->SetSpeed( value.Get<int>() );
325 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
327 if( !impl.mTextScroller )
329 impl.mTextScroller = Text::TextScroller::New( impl );
331 impl.mTextScroller->SetLoopCount( value.Get<int>() );
334 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
336 if( !impl.mTextScroller )
338 impl.mTextScroller = Text::TextScroller::New( impl );
340 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
343 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
345 if( !impl.mTextScroller )
347 impl.mTextScroller = Text::TextScroller::New( impl );
349 impl.mTextScroller->SetGap( value.Get<float>() );
352 case Toolkit::TextLabel::Property::LINE_SPACING:
354 if( impl.mController )
356 const float lineSpacing = value.Get<float>();
358 // Don't trigger anything if the line spacing didn't change
359 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
361 impl.mTextUpdateNeeded = true;
366 case Toolkit::TextLabel::Property::UNDERLINE:
368 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
371 impl.mTextUpdateNeeded = true;
375 case Toolkit::TextLabel::Property::SHADOW:
377 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
380 impl.mTextUpdateNeeded = true;
384 case Toolkit::TextLabel::Property::EMBOSS:
386 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
389 impl.mTextUpdateNeeded = true;
393 case Toolkit::TextLabel::Property::OUTLINE:
395 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
398 impl.mTextUpdateNeeded = true;
402 case Toolkit::TextLabel::Property::PIXEL_SIZE:
404 if( impl.mController )
406 const float pixelSize = value.Get< float >();
407 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
409 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
411 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
416 case Toolkit::TextLabel::Property::ELLIPSIS:
418 if( impl.mController )
420 const bool ellipsis = value.Get<bool>();
421 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
423 impl.mController->SetTextElideEnabled( ellipsis );
427 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
429 if( impl.mController )
431 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
432 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
434 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
435 impl.mController->SetLineWrapMode( lineWrapMode );
440 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
442 if( impl.mController && impl.mController->GetTextModel() )
444 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
446 impl.mController->SetVerticalLineAlignment( alignment );
448 // Property doesn't affect the layout, only Visual must be updated
449 TextVisual::EnableRendererUpdate( impl.mVisual );
451 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
452 TextVisual::UpdateRenderer( impl.mVisual );
456 case Toolkit::DevelTextLabel::Property::BACKGROUND:
458 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
461 impl.mTextUpdateNeeded = true;
465 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
467 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
470 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
472 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
475 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
477 const Property::Map& propertiesMap = value.Get<Property::Map>();
479 bool enabled = false;
482 float stepSize = 0.f;
483 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
484 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
486 if ( !propertiesMap.Empty() )
488 const unsigned int numberOfItems = propertiesMap.Count();
490 // Parses and applies
491 for( unsigned int index = 0u; index < numberOfItems; ++index )
493 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
495 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
498 enabled = valueGet.second.Get< bool >();
500 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
503 minSize = valueGet.second.Get< float >();
506 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
509 maxSize = valueGet.second.Get< float >();
512 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
515 stepSize = valueGet.second.Get< float >();
516 isStepSizeSet = true;
518 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
520 if( "pixelSize" == valueGet.second.Get< std::string >() )
522 type = Controller::FontSizeType::PIXEL_SIZE;
527 impl.mController->SetTextFitEnabled( enabled );
530 impl.mController->SetTextFitMinSize( minSize, type );
534 impl.mController->SetTextFitMaxSize( maxSize, type );
538 impl.mController->SetTextFitStepSize( stepSize, type );
543 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
545 if( impl.mController )
547 const float lineSize = value.Get<float>();
549 if( impl.mController->SetDefaultLineSize( lineSize ) )
551 impl.mTextUpdateNeeded = true;
558 // Request relayout when text update is needed. It's necessary to call it
559 // as changing the property not via UI interaction brings no effect if only
560 // the mTextUpdateNeeded is changed.
561 if( impl.mTextUpdateNeeded )
563 // need to request relayout as size of text may have changed
564 impl.RequestTextRelayout();
569 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
571 Property::Value value;
573 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
577 TextLabel& impl( GetImpl( label ) );
580 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
582 value = impl.mRenderingBackend;
585 case Toolkit::TextLabel::Property::TEXT:
587 if( impl.mController )
590 impl.mController->GetText( text );
595 case Toolkit::TextLabel::Property::FONT_FAMILY:
597 if( impl.mController )
599 value = impl.mController->GetDefaultFontFamily();
603 case Toolkit::TextLabel::Property::FONT_STYLE:
605 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
608 case Toolkit::TextLabel::Property::POINT_SIZE:
610 if( impl.mController )
612 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
616 case Toolkit::TextLabel::Property::MULTI_LINE:
618 if( impl.mController )
620 value = impl.mController->IsMultiLineEnabled();
624 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
626 if( impl.mController )
628 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
632 value = std::string( name );
637 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
639 if( impl.mController )
641 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
644 value = std::string( name );
649 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
651 if( impl.mController )
653 value = impl.mController->IsMarkupProcessorEnabled();
657 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
659 if( impl.mController )
661 value = impl.mController->IsAutoScrollEnabled();
665 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
667 if( impl.mTextScroller )
669 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
670 AUTO_SCROLL_STOP_MODE_TABLE,
671 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
674 value = std::string( mode );
679 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
681 TextLabel& impl( GetImpl( label ) );
682 if ( impl.mTextScroller )
684 value = impl.mTextScroller->GetSpeed();
688 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
690 if( impl.mController )
692 TextLabel& impl( GetImpl( label ) );
693 if ( impl.mTextScroller )
695 value = impl.mTextScroller->GetLoopCount();
700 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
702 if( impl.mController )
704 TextLabel& impl( GetImpl( label ) );
705 if ( impl.mTextScroller )
707 value = impl.mTextScroller->GetLoopDelay();
712 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
714 TextLabel& impl( GetImpl( label ) );
715 if ( impl.mTextScroller )
717 value = impl.mTextScroller->GetGap();
721 case Toolkit::TextLabel::Property::LINE_SPACING:
723 if( impl.mController )
725 value = impl.mController->GetDefaultLineSpacing();
729 case Toolkit::TextLabel::Property::UNDERLINE:
731 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
734 case Toolkit::TextLabel::Property::SHADOW:
736 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
739 case Toolkit::TextLabel::Property::EMBOSS:
741 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
744 case Toolkit::TextLabel::Property::OUTLINE:
746 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
749 case Toolkit::TextLabel::Property::PIXEL_SIZE:
751 if( impl.mController )
753 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
757 case Toolkit::TextLabel::Property::ELLIPSIS:
759 if( impl.mController )
761 value = impl.mController->IsTextElideEnabled();
765 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
767 if( impl.mController )
769 value = impl.mController->GetLineWrapMode();
773 case Toolkit::TextLabel::Property::LINE_COUNT:
775 if( impl.mController )
777 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
778 value = impl.mController->GetLineCount( width );
782 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
784 if( impl.mController )
786 value = impl.mController->GetTextDirection();
790 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
792 if( impl.mController )
794 value = impl.mController->GetVerticalLineAlignment();
798 case Toolkit::DevelTextLabel::Property::BACKGROUND:
800 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
803 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
805 value = impl.mController->IsIgnoreSpacesAfterText();
808 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
810 value = impl.mController->IsMatchSystemLanguageDirection();
813 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
815 const bool enabled = impl.mController->IsTextFitEnabled();
816 const float minSize = impl.mController->GetTextFitMinSize();
817 const float maxSize = impl.mController->GetTextFitMaxSize();
818 const float stepSize = impl.mController->GetTextFitStepSize();
821 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
822 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
823 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
824 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
825 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
830 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
832 if( impl.mController )
834 value = impl.mController->GetDefaultLineSize();
844 void TextLabel::OnInitialize()
848 Property::Map propertyMap;
849 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
851 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
852 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
854 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
856 mController = TextVisual::GetController(mVisual);
859 mController->SetControlInterface(this);
862 // Use height-for-width negotiation by default
863 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
864 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
866 // Enable the text ellipsis.
867 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
869 // Sets layoutDirection value
870 Dali::Stage stage = Dali::Stage::GetCurrent();
871 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
872 mController->SetLayoutDirection( layoutDirection );
874 Layout::Engine& engine = mController->GetLayoutEngine();
875 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
878 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
880 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
884 case StyleChange::DEFAULT_FONT_CHANGE:
886 // Property system did not set the font so should update it.
887 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
888 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
889 mController->UpdateAfterFontChange( newFont );
893 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
895 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
899 case StyleChange::THEME_CHANGE:
901 // Nothing to do, let control base class handle this
906 // Up call to Control
907 Control::OnStyleChange( styleManager, change );
910 Vector3 TextLabel::GetNaturalSize()
913 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
915 Vector3 naturalSize = mController->GetNaturalSize();
916 naturalSize.width += ( padding.start + padding.end );
917 naturalSize.height += ( padding.top + padding.bottom );
922 float TextLabel::GetHeightForWidth( float width )
925 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
927 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
930 void TextLabel::OnPropertySet( Property::Index index, const Property::Value& propertyValue )
932 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
936 case Toolkit::TextLabel::Property::TEXT_COLOR:
938 const Vector4& textColor = propertyValue.Get< Vector4 >();
939 if( mController->GetDefaultColor() != textColor )
941 mController->SetDefaultColor( textColor );
942 mTextUpdateNeeded = true;
948 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
954 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
956 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
959 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
961 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
963 if( mController->IsTextFitEnabled() )
965 mController->FitPointSizeforLayout( contentSize );
966 mController->SetTextFitContentSize( contentSize );
969 // Support Right-To-Left
970 Dali::LayoutDirection::Type layoutDirection;
971 if( mController->IsMatchSystemLanguageDirection() )
973 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( Self() ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
977 layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
979 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
981 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
982 || mTextUpdateNeeded )
984 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
987 TextVisual::EnableRendererUpdate( mVisual );
989 // Support Right-To-Left of padding
990 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
992 std::swap( padding.start, padding.end );
995 // Calculate the size of the visual that can fit the text
996 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
997 layoutSize.x = contentSize.x;
999 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
1000 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
1002 layoutSize.y += shadowOffset.y;
1005 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1006 layoutSize.y += outlineWidth * 2.0f;
1007 layoutSize.y = std::min( layoutSize.y, contentSize.y );
1009 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1010 Vector2 alignmentOffset;
1011 alignmentOffset.x = 0.0f;
1012 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1014 Property::Map visualTransform;
1015 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1016 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1017 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1018 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1019 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1020 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1021 mVisual.SetTransformAndSize( visualTransform, size );
1023 if ( mController->IsAutoScrollEnabled() )
1025 SetUpAutoScrolling();
1028 mTextUpdateNeeded = false;
1032 void TextLabel::RequestTextRelayout()
1035 // Signal that a Relayout may be needed
1038 void TextLabel::SetUpAutoScrolling()
1040 const Size& controlSize = mController->GetView().GetControlSize();
1041 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.
1042 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1044 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1045 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1047 if ( !mTextScroller )
1049 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1051 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1052 mTextScroller = Text::TextScroller::New( *this );
1055 // Calculate the actual gap before scrolling wraps.
1056 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1057 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1058 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1060 // Create a texture of the text for scrolling
1061 Size verifiedSize = textureSize;
1062 const int maxTextureSize = Dali::GetMaxTextureSize();
1064 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1065 bool actualellipsis = mController->IsTextElideEnabled();
1066 if( verifiedSize.width > maxTextureSize )
1068 verifiedSize.width = maxTextureSize;
1069 if( textNaturalSize.width > maxTextureSize )
1071 mController->SetTextElideEnabled( true );
1073 GetHeightForWidth( maxTextureSize );
1074 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1077 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1079 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1080 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1081 data.GetPixelFormat(),
1084 texture.Upload( data );
1086 TextureSet textureSet = TextureSet::New();
1087 textureSet.SetTexture( 0u, texture );
1089 // Filter mode needs to be set to linear to produce better quality while scaling.
1090 Sampler sampler = Sampler::New();
1091 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1092 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1093 textureSet.SetSampler( 0u, sampler );
1095 // Set parameters for scrolling
1096 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1097 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1098 mController->SetTextElideEnabled( actualellipsis );
1101 void TextLabel::ScrollingFinished()
1103 // Pure Virtual from TextScroller Interface
1104 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1105 mController->SetAutoScrollEnabled( false );
1106 RequestTextRelayout();
1109 TextLabel::TextLabel()
1110 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1111 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1112 mTextUpdateNeeded( false )
1116 TextLabel::~TextLabel()
1120 } // namespace Internal
1122 } // namespace Toolkit