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, "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_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::TextLabel::Property::RENDERING_BACKEND:
174 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
176 int backend = value.Get< int >();
178 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
179 if( Text::RENDERING_VECTOR_BASED == backend )
181 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
184 if( impl.mRenderingBackend != backend )
186 impl.mRenderingBackend = backend;
187 impl.mTextUpdateNeeded = true;
189 if( impl.mController )
191 // When using the vector-based rendering, the size of the GLyphs are different
192 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193 impl.mController->SetGlyphType( glyphType );
198 case Toolkit::TextLabel::Property::TEXT:
200 if( impl.mController )
202 impl.mController->SetText( value.Get< std::string >() );
206 case Toolkit::TextLabel::Property::FONT_FAMILY:
208 if( impl.mController )
210 const std::string& fontFamily = value.Get< std::string >();
212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
213 impl.mController->SetDefaultFontFamily( fontFamily );
217 case Toolkit::TextLabel::Property::FONT_STYLE:
219 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
222 case Toolkit::TextLabel::Property::POINT_SIZE:
224 if( impl.mController )
226 const float pointSize = value.Get< float >();
228 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
230 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
235 case Toolkit::TextLabel::Property::MULTI_LINE:
237 if( impl.mController )
239 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
243 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
245 if( impl.mController )
247 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
248 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
250 impl.mController->SetHorizontalAlignment( alignment );
255 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
257 if( impl.mController )
259 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
260 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
262 impl.mController->SetVerticalAlignment( alignment );
267 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
269 if( impl.mController )
271 const bool enableMarkup = value.Get<bool>();
272 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
276 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
278 if( impl.mController )
280 const bool enableAutoScroll = value.Get<bool>();
281 // If request to auto scroll is the same as current state then do nothing.
282 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
284 // If request is disable (false) and auto scrolling is enabled then need to stop it
285 if ( enableAutoScroll == false )
287 if( impl.mTextScroller )
289 impl.mTextScroller->StopScrolling();
292 // If request is enable (true) then start autoscroll as not already running
295 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
301 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
303 if( !impl.mTextScroller )
305 impl.mTextScroller = Text::TextScroller::New( impl );
307 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
308 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
309 AUTO_SCROLL_STOP_MODE_TABLE,
310 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
313 impl.mTextScroller->SetStopMode( stopMode );
317 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
319 if( !impl.mTextScroller )
321 impl.mTextScroller = Text::TextScroller::New( impl );
323 impl.mTextScroller->SetSpeed( value.Get<int>() );
326 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
328 if( !impl.mTextScroller )
330 impl.mTextScroller = Text::TextScroller::New( impl );
332 impl.mTextScroller->SetLoopCount( value.Get<int>() );
335 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
337 if( !impl.mTextScroller )
339 impl.mTextScroller = Text::TextScroller::New( impl );
341 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
344 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
346 if( !impl.mTextScroller )
348 impl.mTextScroller = Text::TextScroller::New( impl );
350 impl.mTextScroller->SetGap( value.Get<float>() );
353 case Toolkit::TextLabel::Property::LINE_SPACING:
355 if( impl.mController )
357 const float lineSpacing = value.Get<float>();
359 // Don't trigger anything if the line spacing didn't change
360 if( impl.mController->SetDefaultLineSpacing( lineSpacing ) )
362 impl.mTextUpdateNeeded = true;
367 case Toolkit::TextLabel::Property::UNDERLINE:
369 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
372 impl.mTextUpdateNeeded = true;
376 case Toolkit::TextLabel::Property::SHADOW:
378 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
381 impl.mTextUpdateNeeded = true;
385 case Toolkit::TextLabel::Property::EMBOSS:
387 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
390 impl.mTextUpdateNeeded = true;
394 case Toolkit::TextLabel::Property::OUTLINE:
396 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
399 impl.mTextUpdateNeeded = true;
403 case Toolkit::TextLabel::Property::PIXEL_SIZE:
405 if( impl.mController )
407 const float pixelSize = value.Get< float >();
408 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
410 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
412 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
417 case Toolkit::TextLabel::Property::ELLIPSIS:
419 if( impl.mController )
421 const bool ellipsis = value.Get<bool>();
422 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
424 impl.mController->SetTextElideEnabled( ellipsis );
428 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
430 if( impl.mController )
432 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
433 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
435 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
436 impl.mController->SetLineWrapMode( lineWrapMode );
441 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
443 if( impl.mController && impl.mController->GetTextModel() )
445 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
447 impl.mController->SetVerticalLineAlignment( alignment );
449 // Property doesn't affect the layout, only Visual must be updated
450 TextVisual::EnableRendererUpdate( impl.mVisual );
452 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
453 TextVisual::UpdateRenderer( impl.mVisual );
457 case Toolkit::DevelTextLabel::Property::BACKGROUND:
459 const bool update = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
462 impl.mTextUpdateNeeded = true;
466 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
468 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
471 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
473 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
476 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
478 const Property::Map& propertiesMap = value.Get<Property::Map>();
480 bool enabled = false;
483 float stepSize = 0.f;
484 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
485 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
487 if ( !propertiesMap.Empty() )
489 const unsigned int numberOfItems = propertiesMap.Count();
491 // Parses and applies
492 for( unsigned int index = 0u; index < numberOfItems; ++index )
494 const KeyValuePair& valueGet = propertiesMap.GetKeyValue( index );
496 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
499 enabled = valueGet.second.Get< bool >();
501 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
504 minSize = valueGet.second.Get< float >();
507 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
510 maxSize = valueGet.second.Get< float >();
513 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
516 stepSize = valueGet.second.Get< float >();
517 isStepSizeSet = true;
519 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
521 if( "pixelSize" == valueGet.second.Get< std::string >() )
523 type = Controller::FontSizeType::PIXEL_SIZE;
528 impl.mController->SetTextFitEnabled( enabled );
531 impl.mController->SetTextFitMinSize( minSize, type );
535 impl.mController->SetTextFitMaxSize( maxSize, type );
539 impl.mController->SetTextFitStepSize( stepSize, type );
544 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
546 if( impl.mController )
548 const float lineSize = value.Get<float>();
550 if( impl.mController->SetDefaultLineSize( lineSize ) )
552 impl.mTextUpdateNeeded = true;
559 // Request relayout when text update is needed. It's necessary to call it
560 // as changing the property not via UI interaction brings no effect if only
561 // the mTextUpdateNeeded is changed.
562 if( impl.mTextUpdateNeeded )
564 // need to request relayout as size of text may have changed
565 impl.RequestTextRelayout();
570 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
572 Property::Value value;
574 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
578 TextLabel& impl( GetImpl( label ) );
581 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
583 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
585 value = impl.mRenderingBackend;
588 case Toolkit::TextLabel::Property::TEXT:
590 if( impl.mController )
593 impl.mController->GetText( text );
598 case Toolkit::TextLabel::Property::FONT_FAMILY:
600 if( impl.mController )
602 value = impl.mController->GetDefaultFontFamily();
606 case Toolkit::TextLabel::Property::FONT_STYLE:
608 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
611 case Toolkit::TextLabel::Property::POINT_SIZE:
613 if( impl.mController )
615 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
619 case Toolkit::TextLabel::Property::MULTI_LINE:
621 if( impl.mController )
623 value = impl.mController->IsMultiLineEnabled();
627 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
629 if( impl.mController )
631 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
635 value = std::string( name );
640 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
642 if( impl.mController )
644 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
647 value = std::string( name );
652 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
654 if( impl.mController )
656 value = impl.mController->IsMarkupProcessorEnabled();
660 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
662 if( impl.mController )
664 value = impl.mController->IsAutoScrollEnabled();
668 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
670 if( impl.mTextScroller )
672 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
673 AUTO_SCROLL_STOP_MODE_TABLE,
674 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
677 value = std::string( mode );
682 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
684 TextLabel& impl( GetImpl( label ) );
685 if ( impl.mTextScroller )
687 value = impl.mTextScroller->GetSpeed();
691 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
693 if( impl.mController )
695 TextLabel& impl( GetImpl( label ) );
696 if ( impl.mTextScroller )
698 value = impl.mTextScroller->GetLoopCount();
703 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
705 if( impl.mController )
707 TextLabel& impl( GetImpl( label ) );
708 if ( impl.mTextScroller )
710 value = impl.mTextScroller->GetLoopDelay();
715 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
717 TextLabel& impl( GetImpl( label ) );
718 if ( impl.mTextScroller )
720 value = impl.mTextScroller->GetGap();
724 case Toolkit::TextLabel::Property::LINE_SPACING:
726 if( impl.mController )
728 value = impl.mController->GetDefaultLineSpacing();
732 case Toolkit::TextLabel::Property::UNDERLINE:
734 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
737 case Toolkit::TextLabel::Property::SHADOW:
739 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
742 case Toolkit::TextLabel::Property::EMBOSS:
744 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
747 case Toolkit::TextLabel::Property::OUTLINE:
749 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
752 case Toolkit::TextLabel::Property::PIXEL_SIZE:
754 if( impl.mController )
756 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
760 case Toolkit::TextLabel::Property::ELLIPSIS:
762 if( impl.mController )
764 value = impl.mController->IsTextElideEnabled();
768 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
770 if( impl.mController )
772 value = impl.mController->GetLineWrapMode();
776 case Toolkit::TextLabel::Property::LINE_COUNT:
778 if( impl.mController )
780 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
781 value = impl.mController->GetLineCount( width );
785 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
787 if( impl.mController )
789 value = impl.mController->GetTextDirection();
793 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
795 if( impl.mController )
797 value = impl.mController->GetVerticalLineAlignment();
801 case Toolkit::DevelTextLabel::Property::BACKGROUND:
803 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
806 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
808 value = impl.mController->IsIgnoreSpacesAfterText();
811 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
813 value = impl.mController->IsMatchSystemLanguageDirection();
816 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
818 const bool enabled = impl.mController->IsTextFitEnabled();
819 const float minSize = impl.mController->GetTextFitMinSize();
820 const float maxSize = impl.mController->GetTextFitMaxSize();
821 const float stepSize = impl.mController->GetTextFitStepSize();
824 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
825 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
826 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
827 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
828 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
833 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
835 if( impl.mController )
837 value = impl.mController->GetDefaultLineSize();
847 void TextLabel::OnInitialize()
851 Property::Map propertyMap;
852 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
854 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
855 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
857 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
859 mController = TextVisual::GetController(mVisual);
862 mController->SetControlInterface(this);
865 // Use height-for-width negotiation by default
866 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
867 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
869 // Enable the text ellipsis.
870 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
872 // Sets layoutDirection value
873 Dali::Stage stage = Dali::Stage::GetCurrent();
874 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
875 mController->SetLayoutDirection( layoutDirection );
877 Layout::Engine& engine = mController->GetLayoutEngine();
878 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
881 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
883 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
887 case StyleChange::DEFAULT_FONT_CHANGE:
889 // Property system did not set the font so should update it.
890 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
891 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
892 mController->UpdateAfterFontChange( newFont );
896 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
898 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
902 case StyleChange::THEME_CHANGE:
904 // Nothing to do, let control base class handle this
909 // Up call to Control
910 Control::OnStyleChange( styleManager, change );
913 Vector3 TextLabel::GetNaturalSize()
916 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
918 Vector3 naturalSize = mController->GetNaturalSize();
919 naturalSize.width += ( padding.start + padding.end );
920 naturalSize.height += ( padding.top + padding.bottom );
925 float TextLabel::GetHeightForWidth( float width )
928 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
930 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
933 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
935 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
939 case Toolkit::TextLabel::Property::TEXT_COLOR:
941 const Vector4& textColor = propertyValue.Get< Vector4 >();
942 if( mController->GetDefaultColor() != textColor )
944 mController->SetDefaultColor( textColor );
945 mTextUpdateNeeded = true;
951 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
957 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
959 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
962 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
964 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
966 if( mController->IsTextFitEnabled() )
968 mController->FitPointSizeforLayout( contentSize );
969 mController->SetTextFitContentSize( contentSize );
972 // Support Right-To-Left
973 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
975 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
977 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
978 || mTextUpdateNeeded )
980 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
983 TextVisual::EnableRendererUpdate( mVisual );
985 // Support Right-To-Left of padding
986 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
988 std::swap( padding.start, padding.end );
991 // Calculate the size of the visual that can fit the text
992 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
993 layoutSize.x = contentSize.x;
995 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
996 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
998 layoutSize.y += shadowOffset.y;
1001 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
1002 layoutSize.y += outlineWidth * 2.0f;
1003 layoutSize.y = std::min( layoutSize.y, contentSize.y );
1005 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
1006 Vector2 alignmentOffset;
1007 alignmentOffset.x = 0.0f;
1008 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
1010 Property::Map visualTransform;
1011 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
1012 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1013 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
1014 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
1015 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
1016 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
1017 mVisual.SetTransformAndSize( visualTransform, size );
1019 if ( mController->IsAutoScrollEnabled() )
1021 SetUpAutoScrolling();
1024 mTextUpdateNeeded = false;
1028 void TextLabel::RequestTextRelayout()
1031 // Signal that a Relayout may be needed
1034 void TextLabel::SetUpAutoScrolling()
1036 const Size& controlSize = mController->GetView().GetControlSize();
1037 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.
1038 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
1040 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
1041 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
1043 if ( !mTextScroller )
1045 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
1047 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
1048 mTextScroller = Text::TextScroller::New( *this );
1051 // Calculate the actual gap before scrolling wraps.
1052 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
1053 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
1054 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
1056 // Create a texture of the text for scrolling
1057 Size verifiedSize = textureSize;
1058 const int maxTextureSize = Dali::GetMaxTextureSize();
1060 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
1061 bool actualellipsis = mController->IsTextElideEnabled();
1062 if( verifiedSize.width > maxTextureSize )
1064 verifiedSize.width = maxTextureSize;
1065 if( textNaturalSize.width > maxTextureSize )
1067 mController->SetTextElideEnabled( true );
1069 GetHeightForWidth( maxTextureSize );
1070 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
1073 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
1075 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
1076 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
1077 data.GetPixelFormat(),
1080 texture.Upload( data );
1082 TextureSet textureSet = TextureSet::New();
1083 textureSet.SetTexture( 0u, texture );
1085 // Filter mode needs to be set to linear to produce better quality while scaling.
1086 Sampler sampler = Sampler::New();
1087 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1088 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
1089 textureSet.SetSampler( 0u, sampler );
1091 // Set parameters for scrolling
1092 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
1093 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
1094 mController->SetTextElideEnabled( actualellipsis );
1097 void TextLabel::ScrollingFinished()
1099 // Pure Virtual from TextScroller Interface
1100 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
1101 mController->SetAutoScrollEnabled( false );
1102 RequestTextRelayout();
1105 TextLabel::TextLabel()
1106 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1107 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1108 mTextUpdateNeeded( false )
1112 TextLabel::~TextLabel()
1116 } // namespace Internal
1118 } // namespace Toolkit