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_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
145 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
146 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
147 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
148 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
149 DALI_TYPE_REGISTRATION_END()
153 Toolkit::TextLabel TextLabel::New()
155 // Create the implementation, temporarily owned by this handle on stack
156 IntrusivePtr< TextLabel > impl = new TextLabel();
158 // Pass ownership to CustomActor handle
159 Toolkit::TextLabel handle( *impl );
161 // Second-phase init of the implementation
162 // This can only be done after the CustomActor connection has been made...
168 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
170 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
174 TextLabel& impl( GetImpl( label ) );
177 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
179 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
181 int backend = value.Get< int >();
183 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
184 if( Text::RENDERING_VECTOR_BASED == backend )
186 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
189 if( impl.mRenderingBackend != backend )
191 impl.mRenderingBackend = backend;
192 impl.mTextUpdateNeeded = true;
194 if( impl.mController )
196 // When using the vector-based rendering, the size of the GLyphs are different
197 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
198 impl.mController->SetGlyphType( glyphType );
203 case Toolkit::TextLabel::Property::TEXT:
205 if( impl.mController )
207 impl.mController->SetText( value.Get< std::string >() );
211 case Toolkit::TextLabel::Property::FONT_FAMILY:
213 if( impl.mController )
215 const std::string& fontFamily = value.Get< std::string >();
217 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
218 impl.mController->SetDefaultFontFamily( fontFamily );
222 case Toolkit::TextLabel::Property::FONT_STYLE:
224 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
227 case Toolkit::TextLabel::Property::POINT_SIZE:
229 if( impl.mController )
231 const float pointSize = value.Get< float >();
233 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
235 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
240 case Toolkit::TextLabel::Property::MULTI_LINE:
242 if( impl.mController )
244 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
248 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
250 if( impl.mController )
252 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
253 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
255 impl.mController->SetHorizontalAlignment( alignment );
260 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
262 if( impl.mController )
264 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
265 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
267 impl.mController->SetVerticalAlignment( alignment );
273 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
275 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
276 impl.mTextUpdateNeeded = true;
279 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
281 if( impl.mController )
283 const bool enableMarkup = value.Get<bool>();
284 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
288 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
290 if( impl.mController )
292 const bool enableAutoScroll = value.Get<bool>();
293 // If request to auto scroll is the same as current state then do nothing.
294 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
296 // If request is disable (false) and auto scrolling is enabled then need to stop it
297 if ( enableAutoScroll == false )
299 if( impl.mTextScroller )
301 impl.mTextScroller->StopScrolling();
304 // If request is enable (true) then start autoscroll as not already running
307 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
313 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
315 if( !impl.mTextScroller )
317 impl.mTextScroller = Text::TextScroller::New( impl );
319 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
320 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
321 AUTO_SCROLL_STOP_MODE_TABLE,
322 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
325 impl.mTextScroller->SetStopMode( stopMode );
329 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
331 if( !impl.mTextScroller )
333 impl.mTextScroller = Text::TextScroller::New( impl );
335 impl.mTextScroller->SetSpeed( value.Get<int>() );
338 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
340 if( !impl.mTextScroller )
342 impl.mTextScroller = Text::TextScroller::New( impl );
344 impl.mTextScroller->SetLoopCount( value.Get<int>() );
347 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
349 if( !impl.mTextScroller )
351 impl.mTextScroller = Text::TextScroller::New( impl );
353 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
356 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
358 if( !impl.mTextScroller )
360 impl.mTextScroller = Text::TextScroller::New( impl );
362 impl.mTextScroller->SetGap( value.Get<float>() );
365 case Toolkit::TextLabel::Property::LINE_SPACING:
367 if( impl.mController )
369 const float lineSpacing = value.Get<float>();
371 // Don't trigger anything if the line spacing didn't change
372 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
374 impl.mTextUpdateNeeded = true;
379 case Toolkit::TextLabel::Property::UNDERLINE:
381 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
384 impl.mTextUpdateNeeded = true;
388 case Toolkit::TextLabel::Property::SHADOW:
390 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
393 impl.mTextUpdateNeeded = true;
397 case Toolkit::TextLabel::Property::EMBOSS:
399 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
402 impl.mTextUpdateNeeded = true;
406 case Toolkit::TextLabel::Property::OUTLINE:
408 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
411 impl.mTextUpdateNeeded = true;
415 case Toolkit::TextLabel::Property::PIXEL_SIZE:
417 if( impl.mController )
419 const float pixelSize = value.Get< float >();
420 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
422 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
424 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
429 case Toolkit::TextLabel::Property::ELLIPSIS:
431 if( impl.mController )
433 const bool ellipsis = value.Get<bool>();
434 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
436 impl.mController->SetTextElideEnabled( ellipsis );
440 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
442 if( impl.mController )
444 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
445 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
447 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
448 impl.mController->SetLineWrapMode( lineWrapMode );
453 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
455 if( impl.mController && impl.mController->GetTextModel() )
457 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
459 impl.mController->SetVerticalLineAlignment( alignment );
461 // Property doesn't affect the layout, only Visual must be updated
462 TextVisual::EnableRendererUpdate( impl.mVisual );
464 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
465 TextVisual::UpdateRenderer( impl.mVisual );
469 case Toolkit::DevelTextLabel::Property::BACKGROUND:
471 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
474 impl.mTextUpdateNeeded = true;
478 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
480 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
483 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
485 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
488 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
490 const Property::Map& propertiesMap = value.Get<Property::Map>();
492 bool enabled = false;
495 float stepSize = 0.f;
496 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
497 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
499 if ( !propertiesMap.Empty() )
501 const unsigned int numberOfItems = propertiesMap.Count();
503 // Parses and applies
504 for( unsigned int index = 0u; index < numberOfItems; ++index )
506 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
508 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
511 enabled = valueGet.second.Get< bool >();
513 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
516 minSize = valueGet.second.Get< float >();
519 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
522 maxSize = valueGet.second.Get< float >();
525 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
528 stepSize = valueGet.second.Get< float >();
529 isStepSizeSet = true;
531 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
533 if( "pixelSize" == valueGet.second.Get< std::string >() )
535 type = Controller::FontSizeType::PIXEL_SIZE;
540 impl.mController->SetTextFitEnabled( enabled );
543 impl.mController->SetTextFitMinSize( minSize, type );
547 impl.mController->SetTextFitMaxSize( maxSize, type );
551 impl.mController->SetTextFitStepSize( stepSize, type );
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::TextLabel::Property::RENDERING_BACKEND:
582 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
584 value = impl.mRenderingBackend;
587 case Toolkit::TextLabel::Property::TEXT:
589 if( impl.mController )
592 impl.mController->GetText( text );
597 case Toolkit::TextLabel::Property::FONT_FAMILY:
599 if( impl.mController )
601 value = impl.mController->GetDefaultFontFamily();
605 case Toolkit::TextLabel::Property::FONT_STYLE:
607 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
610 case Toolkit::TextLabel::Property::POINT_SIZE:
612 if( impl.mController )
614 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
618 case Toolkit::TextLabel::Property::MULTI_LINE:
620 if( impl.mController )
622 value = impl.mController->IsMultiLineEnabled();
626 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
628 if( impl.mController )
630 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
634 value = std::string( name );
639 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
641 if( impl.mController )
643 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
646 value = std::string( name );
651 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
653 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
656 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
658 if( impl.mController )
660 value = impl.mController->IsMarkupProcessorEnabled();
664 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
666 if( impl.mController )
668 value = impl.mController->IsAutoScrollEnabled();
672 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
674 if( impl.mTextScroller )
676 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
677 AUTO_SCROLL_STOP_MODE_TABLE,
678 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
681 value = std::string( mode );
686 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
688 TextLabel& impl( GetImpl( label ) );
689 if ( impl.mTextScroller )
691 value = impl.mTextScroller->GetSpeed();
695 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
697 if( impl.mController )
699 TextLabel& impl( GetImpl( label ) );
700 if ( impl.mTextScroller )
702 value = impl.mTextScroller->GetLoopCount();
707 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
709 if( impl.mController )
711 TextLabel& impl( GetImpl( label ) );
712 if ( impl.mTextScroller )
714 value = impl.mTextScroller->GetLoopDelay();
719 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
721 TextLabel& impl( GetImpl( label ) );
722 if ( impl.mTextScroller )
724 value = impl.mTextScroller->GetGap();
728 case Toolkit::TextLabel::Property::LINE_SPACING:
730 if( impl.mController )
732 value = impl.mController->GetDefaultLineSpacing();
736 case Toolkit::TextLabel::Property::UNDERLINE:
738 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
741 case Toolkit::TextLabel::Property::SHADOW:
743 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
746 case Toolkit::TextLabel::Property::EMBOSS:
748 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
751 case Toolkit::TextLabel::Property::OUTLINE:
753 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
756 case Toolkit::TextLabel::Property::PIXEL_SIZE:
758 if( impl.mController )
760 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
764 case Toolkit::TextLabel::Property::ELLIPSIS:
766 if( impl.mController )
768 value = impl.mController->IsTextElideEnabled();
772 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
774 if( impl.mController )
776 value = impl.mController->GetLineWrapMode();
780 case Toolkit::TextLabel::Property::LINE_COUNT:
782 if( impl.mController )
784 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
785 value = impl.mController->GetLineCount( width );
789 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
791 if( impl.mController )
793 value = impl.mController->GetTextDirection();
797 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
799 if( impl.mController )
801 value = impl.mController->GetVerticalLineAlignment();
805 case Toolkit::DevelTextLabel::Property::BACKGROUND:
807 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
810 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
812 value = impl.mController->IsIgnoreSpacesAfterText();
815 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
817 value = impl.mController->IsMatchSystemLanguageDirection();
820 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
822 const bool enabled = impl.mController->IsTextFitEnabled();
823 const float minSize = impl.mController->GetTextFitMinSize();
824 const float maxSize = impl.mController->GetTextFitMaxSize();
825 const float stepSize = impl.mController->GetTextFitStepSize();
828 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
829 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
830 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
831 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
832 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
843 void TextLabel::OnInitialize()
847 Property::Map propertyMap;
848 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
850 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
851 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
853 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
855 mController = TextVisual::GetController(mVisual);
858 mController->SetControlInterface(this);
861 // Use height-for-width negotiation by default
862 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
863 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
865 // Enable the text ellipsis.
866 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
868 // Sets layoutDirection value
869 Dali::Stage stage = Dali::Stage::GetCurrent();
870 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
871 mController->SetLayoutDirection( layoutDirection );
873 Layout::Engine& engine = mController->GetLayoutEngine();
874 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
877 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
879 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
883 case StyleChange::DEFAULT_FONT_CHANGE:
885 // Property system did not set the font so should update it.
886 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
887 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
888 mController->UpdateAfterFontChange( newFont );
892 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
894 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
898 case StyleChange::THEME_CHANGE:
900 // Nothing to do, let control base class handle this
905 // Up call to Control
906 Control::OnStyleChange( styleManager, change );
909 Vector3 TextLabel::GetNaturalSize()
912 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
914 Vector3 naturalSize = mController->GetNaturalSize();
915 naturalSize.width += ( padding.start + padding.end );
916 naturalSize.height += ( padding.top + padding.bottom );
921 float TextLabel::GetHeightForWidth( float width )
924 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
926 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
929 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
931 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
935 case Toolkit::TextLabel::Property::TEXT_COLOR:
937 const Vector4& textColor = propertyValue.Get< Vector4 >();
938 if( mController->GetDefaultColor() != textColor )
940 mController->SetDefaultColor( textColor );
941 mTextUpdateNeeded = true;
947 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
953 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
955 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
958 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
960 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
962 if( mController->IsTextFitEnabled() )
964 mController->FitPointSizeforLayout( contentSize );
965 mController->SetTextFitContentSize( contentSize );
968 // Support Right-To-Left
969 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
971 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
973 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
974 || mTextUpdateNeeded )
976 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
979 TextVisual::EnableRendererUpdate( mVisual );
981 // Support Right-To-Left of padding
982 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
984 std::swap( padding.start, padding.end );
987 // Calculate the size of the visual that can fit the text
988 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
989 layoutSize.x = contentSize.x;
991 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
992 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
994 layoutSize.y += shadowOffset.y;
997 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
998 layoutSize.y += outlineWidth * 2.0f;
999 layoutSize.y = std::min( layoutSize.y, contentSize.y );
1001 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1002 Vector2 alignmentOffset;
1003 alignmentOffset.x = 0.0f;
1004 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1006 Property::Map visualTransform;
1007 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1008 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1009 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1010 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1011 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1012 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1013 mVisual.SetTransformAndSize( visualTransform, size );
1015 if ( mController->IsAutoScrollEnabled() )
1017 SetUpAutoScrolling();
1020 mTextUpdateNeeded = false;
1024 void TextLabel::RequestTextRelayout()
1027 // Signal that a Relayout may be needed
1030 void TextLabel::SetUpAutoScrolling()
1032 const Size& controlSize = mController->GetView().GetControlSize();
1033 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.
1034 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1036 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1037 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1039 if ( !mTextScroller )
1041 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1043 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1044 mTextScroller = Text::TextScroller::New( *this );
1047 // Calculate the actual gap before scrolling wraps.
1048 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1049 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1050 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1052 // Create a texture of the text for scrolling
1053 Size verifiedSize = textureSize;
1054 const int maxTextureSize = Dali::GetMaxTextureSize();
1056 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1057 if( verifiedSize.width > maxTextureSize )
1059 verifiedSize.width = maxTextureSize;
1060 if( textNaturalSize.width > maxTextureSize )
1062 mController->SetTextElideEnabled( true );
1064 GetHeightForWidth( maxTextureSize );
1065 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1068 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1070 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1071 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1072 data.GetPixelFormat(),
1075 texture.Upload( data );
1077 TextureSet textureSet = TextureSet::New();
1078 textureSet.SetTexture( 0u, texture );
1080 // Filter mode needs to be set to linear to produce better quality while scaling.
1081 Sampler sampler = Sampler::New();
1082 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1083 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1084 textureSet.SetSampler( 0u, sampler );
1086 // Set parameters for scrolling
1087 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1088 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1091 void TextLabel::ScrollingFinished()
1093 // Pure Virtual from TextScroller Interface
1094 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1095 mController->SetAutoScrollEnabled( false );
1096 mController->SetTextElideEnabled( true );
1097 RequestTextRelayout();
1100 TextLabel::TextLabel()
1101 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1102 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1103 mTextUpdateNeeded( false )
1107 TextLabel::~TextLabel()
1111 } // namespace Internal
1113 } // namespace Toolkit