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/integration-api/debug.h>
29 #include <dali-toolkit/public-api/text/text-enumerations.h>
30 #include <dali-toolkit/devel-api/text/rendering-backend.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::DevelText::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, "text", STRING, TEXT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
129 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
131 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
139 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
140 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
141 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
142 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
143 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
144 DALI_TYPE_REGISTRATION_END()
148 Toolkit::TextLabel TextLabel::New()
150 // Create the implementation, temporarily owned by this handle on stack
151 IntrusivePtr< TextLabel > impl = new TextLabel();
153 // Pass ownership to CustomActor handle
154 Toolkit::TextLabel handle( *impl );
156 // Second-phase init of the implementation
157 // This can only be done after the CustomActor connection has been made...
163 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
165 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
169 TextLabel& impl( GetImpl( label ) );
172 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
174 int backend = value.Get< int >();
176 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
177 if( DevelText::RENDERING_VECTOR_BASED == backend )
179 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
182 if( impl.mRenderingBackend != backend )
184 impl.mRenderingBackend = backend;
185 impl.mTextUpdateNeeded = true;
187 if( impl.mController )
189 // When using the vector-based rendering, the size of the GLyphs are different
190 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
191 impl.mController->SetGlyphType( glyphType );
196 case Toolkit::TextLabel::Property::TEXT:
198 if( impl.mController )
200 impl.mController->SetText( value.Get< std::string >() );
204 case Toolkit::TextLabel::Property::FONT_FAMILY:
206 if( impl.mController )
208 const std::string& fontFamily = value.Get< std::string >();
210 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
211 impl.mController->SetDefaultFontFamily( fontFamily );
215 case Toolkit::TextLabel::Property::FONT_STYLE:
217 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
220 case Toolkit::TextLabel::Property::POINT_SIZE:
222 if( impl.mController )
224 const float pointSize = value.Get< float >();
226 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
228 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
233 case Toolkit::TextLabel::Property::MULTI_LINE:
235 if( impl.mController )
237 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
241 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
243 if( impl.mController )
245 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
246 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
248 impl.mController->SetHorizontalAlignment( alignment );
253 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
255 if( impl.mController )
257 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
258 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
260 impl.mController->SetVerticalAlignment( alignment );
265 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
267 if( impl.mController )
269 const bool enableMarkup = value.Get<bool>();
270 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
274 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
276 if( impl.mController )
278 const bool enableAutoScroll = value.Get<bool>();
279 // If request to auto scroll is the same as current state then do nothing.
280 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
282 // If request is disable (false) and auto scrolling is enabled then need to stop it
283 if ( enableAutoScroll == false )
285 if( impl.mTextScroller )
287 impl.mTextScroller->StopScrolling();
290 // If request is enable (true) then start autoscroll as not already running
293 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
299 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
301 if( !impl.mTextScroller )
303 impl.mTextScroller = Text::TextScroller::New( impl );
305 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
306 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
307 AUTO_SCROLL_STOP_MODE_TABLE,
308 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
311 impl.mTextScroller->SetStopMode( stopMode );
315 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
317 if( !impl.mTextScroller )
319 impl.mTextScroller = Text::TextScroller::New( impl );
321 impl.mTextScroller->SetSpeed( value.Get<int>() );
324 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
326 if( !impl.mTextScroller )
328 impl.mTextScroller = Text::TextScroller::New( impl );
330 impl.mTextScroller->SetLoopCount( value.Get<int>() );
333 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
335 if( !impl.mTextScroller )
337 impl.mTextScroller = Text::TextScroller::New( impl );
339 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
342 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
344 if( !impl.mTextScroller )
346 impl.mTextScroller = Text::TextScroller::New( impl );
348 impl.mTextScroller->SetGap( value.Get<float>() );
351 case Toolkit::TextLabel::Property::LINE_SPACING:
353 if( impl.mController )
355 const float lineSpacing = value.Get<float>();
357 // Don't trigger anything if the line spacing didn't change
358 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
360 impl.mTextUpdateNeeded = true;
365 case Toolkit::TextLabel::Property::UNDERLINE:
367 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
370 impl.mTextUpdateNeeded = true;
374 case Toolkit::TextLabel::Property::SHADOW:
376 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
379 impl.mTextUpdateNeeded = true;
383 case Toolkit::TextLabel::Property::EMBOSS:
385 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
388 impl.mTextUpdateNeeded = true;
392 case Toolkit::TextLabel::Property::OUTLINE:
394 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
397 impl.mTextUpdateNeeded = true;
401 case Toolkit::TextLabel::Property::PIXEL_SIZE:
403 if( impl.mController )
405 const float pixelSize = value.Get< float >();
406 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
408 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
410 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
415 case Toolkit::TextLabel::Property::ELLIPSIS:
417 if( impl.mController )
419 const bool ellipsis = value.Get<bool>();
420 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
422 impl.mController->SetTextElideEnabled( ellipsis );
426 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
428 if( impl.mController )
430 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
431 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
433 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
434 impl.mController->SetLineWrapMode( lineWrapMode );
439 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
441 if( impl.mController && impl.mController->GetTextModel() )
443 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
445 impl.mController->SetVerticalLineAlignment( alignment );
447 // Property doesn't affect the layout, only Visual must be updated
448 TextVisual::EnableRendererUpdate( impl.mVisual );
450 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
451 TextVisual::UpdateRenderer( impl.mVisual );
455 case Toolkit::DevelTextLabel::Property::BACKGROUND:
457 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
460 impl.mTextUpdateNeeded = true;
464 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
466 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
469 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
471 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
474 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
476 const Property::Map& propertiesMap = value.Get<Property::Map>();
478 bool enabled = false;
481 float stepSize = 0.f;
482 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
483 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
485 if ( !propertiesMap.Empty() )
487 const unsigned int numberOfItems = propertiesMap.Count();
489 // Parses and applies
490 for( unsigned int index = 0u; index < numberOfItems; ++index )
492 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
494 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
497 enabled = valueGet.second.Get< bool >();
499 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
502 minSize = valueGet.second.Get< float >();
505 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
508 maxSize = valueGet.second.Get< float >();
511 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
514 stepSize = valueGet.second.Get< float >();
515 isStepSizeSet = true;
517 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
519 if( "pixelSize" == valueGet.second.Get< std::string >() )
521 type = Controller::FontSizeType::PIXEL_SIZE;
526 impl.mController->SetTextFitEnabled( enabled );
529 impl.mController->SetTextFitMinSize( minSize, type );
533 impl.mController->SetTextFitMaxSize( maxSize, type );
537 impl.mController->SetTextFitStepSize( stepSize, type );
542 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
544 if( impl.mController )
546 const float lineSize = value.Get<float>();
548 if( impl.mController->SetDefaultLineSize( lineSize ) )
550 impl.mTextUpdateNeeded = true;
557 // Request relayout when text update is needed. It's necessary to call it
558 // as changing the property not via UI interaction brings no effect if only
559 // the mTextUpdateNeeded is changed.
560 if( impl.mTextUpdateNeeded )
562 // need to request relayout as size of text may have changed
563 impl.RequestTextRelayout();
568 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
570 Property::Value value;
572 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
576 TextLabel& impl( GetImpl( label ) );
579 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
581 value = impl.mRenderingBackend;
584 case Toolkit::TextLabel::Property::TEXT:
586 if( impl.mController )
589 impl.mController->GetText( text );
594 case Toolkit::TextLabel::Property::FONT_FAMILY:
596 if( impl.mController )
598 value = impl.mController->GetDefaultFontFamily();
602 case Toolkit::TextLabel::Property::FONT_STYLE:
604 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
607 case Toolkit::TextLabel::Property::POINT_SIZE:
609 if( impl.mController )
611 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
615 case Toolkit::TextLabel::Property::MULTI_LINE:
617 if( impl.mController )
619 value = impl.mController->IsMultiLineEnabled();
623 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
625 if( impl.mController )
627 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
631 value = std::string( name );
636 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
638 if( impl.mController )
640 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
643 value = std::string( name );
648 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
650 if( impl.mController )
652 value = impl.mController->IsMarkupProcessorEnabled();
656 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
658 if( impl.mController )
660 value = impl.mController->IsAutoScrollEnabled();
664 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
666 if( impl.mTextScroller )
668 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
669 AUTO_SCROLL_STOP_MODE_TABLE,
670 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
673 value = std::string( mode );
678 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
680 TextLabel& impl( GetImpl( label ) );
681 if ( impl.mTextScroller )
683 value = impl.mTextScroller->GetSpeed();
687 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
689 if( impl.mController )
691 TextLabel& impl( GetImpl( label ) );
692 if ( impl.mTextScroller )
694 value = impl.mTextScroller->GetLoopCount();
699 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
701 if( impl.mController )
703 TextLabel& impl( GetImpl( label ) );
704 if ( impl.mTextScroller )
706 value = impl.mTextScroller->GetLoopDelay();
711 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
713 TextLabel& impl( GetImpl( label ) );
714 if ( impl.mTextScroller )
716 value = impl.mTextScroller->GetGap();
720 case Toolkit::TextLabel::Property::LINE_SPACING:
722 if( impl.mController )
724 value = impl.mController->GetDefaultLineSpacing();
728 case Toolkit::TextLabel::Property::UNDERLINE:
730 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
733 case Toolkit::TextLabel::Property::SHADOW:
735 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
738 case Toolkit::TextLabel::Property::EMBOSS:
740 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
743 case Toolkit::TextLabel::Property::OUTLINE:
745 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
748 case Toolkit::TextLabel::Property::PIXEL_SIZE:
750 if( impl.mController )
752 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
756 case Toolkit::TextLabel::Property::ELLIPSIS:
758 if( impl.mController )
760 value = impl.mController->IsTextElideEnabled();
764 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
766 if( impl.mController )
768 value = impl.mController->GetLineWrapMode();
772 case Toolkit::TextLabel::Property::LINE_COUNT:
774 if( impl.mController )
776 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
777 value = impl.mController->GetLineCount( width );
781 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
783 if( impl.mController )
785 value = impl.mController->GetTextDirection();
789 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
791 if( impl.mController )
793 value = impl.mController->GetVerticalLineAlignment();
797 case Toolkit::DevelTextLabel::Property::BACKGROUND:
799 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
802 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
804 value = impl.mController->IsIgnoreSpacesAfterText();
807 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
809 value = impl.mController->IsMatchSystemLanguageDirection();
812 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
814 const bool enabled = impl.mController->IsTextFitEnabled();
815 const float minSize = impl.mController->GetTextFitMinSize();
816 const float maxSize = impl.mController->GetTextFitMaxSize();
817 const float stepSize = impl.mController->GetTextFitStepSize();
820 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
821 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
822 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
823 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
824 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
829 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
831 if( impl.mController )
833 value = impl.mController->GetDefaultLineSize();
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 bool actualellipsis = mController->IsTextElideEnabled();
1058 if( verifiedSize.width > maxTextureSize )
1060 verifiedSize.width = maxTextureSize;
1061 if( textNaturalSize.width > maxTextureSize )
1063 mController->SetTextElideEnabled( true );
1065 GetHeightForWidth( maxTextureSize );
1066 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1069 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1071 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1072 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1073 data.GetPixelFormat(),
1076 texture.Upload( data );
1078 TextureSet textureSet = TextureSet::New();
1079 textureSet.SetTexture( 0u, texture );
1081 // Filter mode needs to be set to linear to produce better quality while scaling.
1082 Sampler sampler = Sampler::New();
1083 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1084 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1085 textureSet.SetSampler( 0u, sampler );
1087 // Set parameters for scrolling
1088 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1089 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1090 mController->SetTextElideEnabled( actualellipsis );
1093 void TextLabel::ScrollingFinished()
1095 // Pure Virtual from TextScroller Interface
1096 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1097 mController->SetAutoScrollEnabled( false );
1098 RequestTextRelayout();
1101 TextLabel::TextLabel()
1102 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1103 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1104 mTextUpdateNeeded( false )
1108 TextLabel::~TextLabel()
1112 } // namespace Internal
1114 } // namespace Toolkit