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/common/dali-common.h>
23 #include <dali/public-api/object/type-registry-helper.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/devel-api/adaptor-framework/image-loading.h>
27 #include <dali/devel-api/adaptor-framework/window-devel.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/text/text-enumerations.h>
32 #include <dali-toolkit/devel-api/text/rendering-backend.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/text/property-string-parser.h>
35 #include <dali-toolkit/internal/text/rendering/text-backend.h>
36 #include <dali-toolkit/internal/text/text-effects-style.h>
37 #include <dali-toolkit/internal/text/text-font-style.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/text/text-definitions.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/public-api/align-enumerations.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
46 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
47 #include <dali-toolkit/public-api/visuals/visual-properties.h>
48 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
50 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
52 using namespace Dali::Toolkit::Text;
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
68 * @brief How the text visual should be aligned vertically inside the control.
70 * 0.0f aligns the text to the top, 0.5f aligns the text to the center, 1.0f aligns the text to the bottom.
71 * The alignment depends on the alignment value of the text label (Use Text::VerticalAlignment enumerations).
73 const float VERTICAL_ALIGNMENT_TABLE[ Text::VerticalAlignment::BOTTOM + 1 ] =
75 0.0f, // VerticalAlignment::TOP
76 0.5f, // VerticalAlignment::CENTER
77 1.0f // VerticalAlignment::BOTTOM
80 const std::string TEXT_FIT_ENABLE_KEY( "enable" );
81 const std::string TEXT_FIT_MIN_SIZE_KEY( "minSize" );
82 const std::string TEXT_FIT_MAX_SIZE_KEY( "maxSize" );
83 const std::string TEXT_FIT_STEP_SIZE_KEY( "stepSize" );
84 const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY( "fontSizeType" );
86 #if defined ( DEBUG_ENABLED )
87 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
90 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
92 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
93 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
95 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
100 return Toolkit::TextLabel::New();
103 // Setup properties, signals and actions using the type-registry.
104 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
127 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
129 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
130 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textFit", MAP, TEXT_FIT )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "minLineSize", FLOAT, MIN_LINE_SIZE )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
137 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
138 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
139 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
140 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
141 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
142 DALI_TYPE_REGISTRATION_END()
144 /// Parses the property map for the TEXT_FIT property
145 void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* propertiesMap)
147 if ( propertiesMap && !propertiesMap->Empty() )
149 bool enabled = false;
152 float stepSize = 0.f;
153 bool isMinSizeSet = false, isMaxSizeSet = false, isStepSizeSet = false;
154 Controller::FontSizeType type = Controller::FontSizeType::POINT_SIZE;
156 const unsigned int numberOfItems = propertiesMap->Count();
158 // Parses and applies
159 for( unsigned int index = 0u; index < numberOfItems; ++index )
161 const KeyValuePair& valueGet = propertiesMap->GetKeyValue( index );
163 if( ( Controller::TextFitInfo::Property::TEXT_FIT_ENABLE == valueGet.first.indexKey ) || ( TEXT_FIT_ENABLE_KEY == valueGet.first.stringKey ) )
166 enabled = valueGet.second.Get< bool >();
168 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MIN_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MIN_SIZE_KEY == valueGet.first.stringKey ) )
171 minSize = valueGet.second.Get< float >();
174 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_MAX_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_MAX_SIZE_KEY == valueGet.first.stringKey ) )
177 maxSize = valueGet.second.Get< float >();
180 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_STEP_SIZE == valueGet.first.indexKey ) || ( TEXT_FIT_STEP_SIZE_KEY == valueGet.first.stringKey ) )
183 stepSize = valueGet.second.Get< float >();
184 isStepSizeSet = true;
186 else if( ( Controller::TextFitInfo::Property::TEXT_FIT_FONT_SIZE_TYPE == valueGet.first.indexKey ) || ( TEXT_FIT_FONT_SIZE_TYPE_KEY == valueGet.first.stringKey ) )
188 if( "pixelSize" == valueGet.second.Get< std::string >() )
190 type = Controller::FontSizeType::PIXEL_SIZE;
195 controller->SetTextFitEnabled( enabled );
198 controller->SetTextFitMinSize( minSize, type );
202 controller->SetTextFitMaxSize( maxSize, type );
206 controller->SetTextFitStepSize( stepSize, type );
213 Toolkit::TextLabel TextLabel::New()
215 // Create the implementation, temporarily owned by this handle on stack
216 IntrusivePtr< TextLabel > impl = new TextLabel();
218 // Pass ownership to CustomActor handle
219 Toolkit::TextLabel handle( *impl );
221 // Second-phase init of the implementation
222 // This can only be done after the CustomActor connection has been made...
228 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
230 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
234 TextLabel& impl( GetImpl( label ) );
235 DALI_ASSERT_ALWAYS( impl.mController && "No text contoller" );
239 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
241 int backend = value.Get< int >();
243 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
244 if( DevelText::RENDERING_VECTOR_BASED == backend )
246 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
249 if( impl.mRenderingBackend != backend )
251 impl.mRenderingBackend = backend;
252 impl.mTextUpdateNeeded = true;
254 // When using the vector-based rendering, the size of the GLyphs are different
255 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
256 impl.mController->SetGlyphType( glyphType );
260 case Toolkit::TextLabel::Property::TEXT:
262 impl.mController->SetText( value.Get< std::string >() );
265 case Toolkit::TextLabel::Property::FONT_FAMILY:
267 const std::string& fontFamily = value.Get< std::string >();
269 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
270 impl.mController->SetDefaultFontFamily( fontFamily );
273 case Toolkit::TextLabel::Property::FONT_STYLE:
275 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
278 case Toolkit::TextLabel::Property::POINT_SIZE:
280 const float pointSize = value.Get< float >();
282 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
284 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
288 case Toolkit::TextLabel::Property::MULTI_LINE:
290 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
293 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
295 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
296 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
298 impl.mController->SetHorizontalAlignment( alignment );
302 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
304 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
305 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
307 impl.mController->SetVerticalAlignment( alignment );
311 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
313 const bool enableMarkup = value.Get<bool>();
314 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
317 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
319 const bool enableAutoScroll = value.Get<bool>();
320 // If request to auto scroll is the same as current state then do nothing.
321 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
323 // If request is disable (false) and auto scrolling is enabled then need to stop it
324 if ( enableAutoScroll == false )
326 if( impl.mTextScroller )
328 impl.mTextScroller->StopScrolling();
331 // If request is enable (true) then start autoscroll as not already running
334 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
339 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
341 Text::TextScrollerPtr textScroller = impl.GetTextScroller();
342 Toolkit::TextLabel::AutoScrollStopMode::Type stopMode = textScroller->GetStopMode();
343 if( Scripting::GetEnumerationProperty< Toolkit::TextLabel::AutoScrollStopMode::Type >( value,
344 AUTO_SCROLL_STOP_MODE_TABLE,
345 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
348 textScroller->SetStopMode( stopMode );
352 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
354 impl.GetTextScroller()->SetSpeed( value.Get<int>() );
357 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
359 impl.GetTextScroller()->SetLoopCount( value.Get<int>() );
362 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
364 impl.GetTextScroller()->SetLoopDelay( value.Get<float>() );
367 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
369 impl.GetTextScroller()->SetGap( value.Get<float>() );
372 case Toolkit::TextLabel::Property::LINE_SPACING:
374 const float lineSpacing = value.Get<float>();
375 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSpacing( lineSpacing ) || impl.mTextUpdateNeeded;
378 case Toolkit::TextLabel::Property::UNDERLINE:
380 impl.mTextUpdateNeeded = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT ) || impl.mTextUpdateNeeded;
383 case Toolkit::TextLabel::Property::SHADOW:
385 impl.mTextUpdateNeeded = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT ) || impl.mTextUpdateNeeded;
388 case Toolkit::TextLabel::Property::EMBOSS:
390 impl.mTextUpdateNeeded = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT ) || impl.mTextUpdateNeeded;
393 case Toolkit::TextLabel::Property::OUTLINE:
395 impl.mTextUpdateNeeded = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT ) || impl.mTextUpdateNeeded;
398 case Toolkit::TextLabel::Property::PIXEL_SIZE:
400 const float pixelSize = value.Get< float >();
401 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
403 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
405 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
409 case Toolkit::TextLabel::Property::ELLIPSIS:
411 const bool ellipsis = value.Get<bool>();
412 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
414 impl.mController->SetTextElideEnabled( ellipsis );
417 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
419 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
420 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
422 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
423 impl.mController->SetLineWrapMode( lineWrapMode );
427 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
429 if( impl.mController->GetTextModel() )
431 DevelText::VerticalLineAlignment::Type alignment = static_cast<DevelText::VerticalLineAlignment::Type>( value.Get<int>() );
433 impl.mController->SetVerticalLineAlignment( alignment );
435 // Property doesn't affect the layout, only Visual must be updated
436 TextVisual::EnableRendererUpdate( impl.mVisual );
438 // No need to trigger full re-layout. Instead call UpdateRenderer() directly
439 TextVisual::UpdateRenderer( impl.mVisual );
443 case Toolkit::DevelTextLabel::Property::BACKGROUND:
445 impl.mTextUpdateNeeded = SetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT ) || impl.mTextUpdateNeeded;
448 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
450 impl.mController->SetIgnoreSpacesAfterText(value.Get< bool >());
453 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
455 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
458 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
460 ParseTextFitProperty(impl.mController, value.GetMap());
463 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
465 const float lineSize = value.Get<float>();
466 impl.mTextUpdateNeeded = impl.mController->SetDefaultLineSize( lineSize ) || impl.mTextUpdateNeeded;
471 // Request relayout when text update is needed. It's necessary to call it
472 // as changing the property not via UI interaction brings no effect if only
473 // the mTextUpdateNeeded is changed.
474 if( impl.mTextUpdateNeeded )
476 // need to request relayout as size of text may have changed
477 impl.RequestTextRelayout();
482 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
484 Property::Value value;
486 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
490 TextLabel& impl( GetImpl( label ) );
491 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
495 case Toolkit::DevelTextLabel::Property::RENDERING_BACKEND:
497 value = impl.mRenderingBackend;
500 case Toolkit::TextLabel::Property::TEXT:
503 impl.mController->GetText( text );
507 case Toolkit::TextLabel::Property::FONT_FAMILY:
509 value = impl.mController->GetDefaultFontFamily();
512 case Toolkit::TextLabel::Property::FONT_STYLE:
514 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
517 case Toolkit::TextLabel::Property::POINT_SIZE:
519 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
522 case Toolkit::TextLabel::Property::MULTI_LINE:
524 value = impl.mController->IsMultiLineEnabled();
527 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
529 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
533 value = std::string( name );
537 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
539 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
542 value = std::string( name );
546 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
548 value = impl.mController->IsMarkupProcessorEnabled();
551 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
553 value = impl.mController->IsAutoScrollEnabled();
556 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
558 if( impl.mTextScroller )
560 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
561 AUTO_SCROLL_STOP_MODE_TABLE,
562 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
565 value = std::string( mode );
570 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
572 if ( impl.mTextScroller )
574 value = impl.mTextScroller->GetSpeed();
578 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
580 if ( impl.mTextScroller )
582 value = impl.mTextScroller->GetLoopCount();
586 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
588 if ( impl.mTextScroller )
590 value = impl.mTextScroller->GetLoopDelay();
594 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
596 if ( impl.mTextScroller )
598 value = impl.mTextScroller->GetGap();
602 case Toolkit::TextLabel::Property::LINE_SPACING:
604 value = impl.mController->GetDefaultLineSpacing();
607 case Toolkit::TextLabel::Property::UNDERLINE:
609 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
612 case Toolkit::TextLabel::Property::SHADOW:
614 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
617 case Toolkit::TextLabel::Property::EMBOSS:
619 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
622 case Toolkit::TextLabel::Property::OUTLINE:
624 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
627 case Toolkit::TextLabel::Property::PIXEL_SIZE:
629 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
632 case Toolkit::TextLabel::Property::ELLIPSIS:
634 value = impl.mController->IsTextElideEnabled();
637 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
639 value = impl.mController->GetLineWrapMode();
642 case Toolkit::TextLabel::Property::LINE_COUNT:
644 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
645 value = impl.mController->GetLineCount( width );
648 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
650 value = impl.mController->GetTextDirection();
653 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
655 value = impl.mController->GetVerticalLineAlignment();
658 case Toolkit::DevelTextLabel::Property::BACKGROUND:
660 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
663 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
665 value = impl.mController->IsIgnoreSpacesAfterText();
668 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
670 value = impl.mController->IsMatchSystemLanguageDirection();
673 case Toolkit::DevelTextLabel::Property::TEXT_FIT:
675 const bool enabled = impl.mController->IsTextFitEnabled();
676 const float minSize = impl.mController->GetTextFitMinSize();
677 const float maxSize = impl.mController->GetTextFitMaxSize();
678 const float stepSize = impl.mController->GetTextFitStepSize();
681 map.Insert( TEXT_FIT_ENABLE_KEY, enabled );
682 map.Insert( TEXT_FIT_MIN_SIZE_KEY, minSize );
683 map.Insert( TEXT_FIT_MAX_SIZE_KEY, maxSize );
684 map.Insert( TEXT_FIT_STEP_SIZE_KEY, stepSize );
685 map.Insert( TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize" );
690 case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE:
692 value = impl.mController->GetDefaultLineSize();
701 void TextLabel::OnInitialize()
705 Property::Map propertyMap;
706 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
708 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
709 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
711 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
713 mController = TextVisual::GetController(mVisual);
714 DALI_ASSERT_DEBUG( mController && "Invalid Text Controller")
716 mController->SetControlInterface(this);
718 // Use height-for-width negotiation by default
719 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
720 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
722 // Enable the text ellipsis.
723 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
725 // Sets layoutDirection value
726 Dali::Stage stage = Dali::Stage::GetCurrent();
727 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
728 mController->SetLayoutDirection( layoutDirection );
730 Layout::Engine& engine = mController->GetLayoutEngine();
731 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
734 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
736 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
740 case StyleChange::DEFAULT_FONT_CHANGE:
742 // Property system did not set the font so should update it.
743 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
744 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
745 mController->UpdateAfterFontChange( newFont );
749 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
751 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
755 case StyleChange::THEME_CHANGE:
757 // Nothing to do, let control base class handle this
762 // Up call to Control
763 Control::OnStyleChange( styleManager, change );
766 Vector3 TextLabel::GetNaturalSize()
769 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
771 Vector3 naturalSize = mController->GetNaturalSize();
772 naturalSize.width += ( padding.start + padding.end );
773 naturalSize.height += ( padding.top + padding.bottom );
778 float TextLabel::GetHeightForWidth( float width )
781 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
783 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
786 void TextLabel::OnPropertySet( Property::Index index, const Property::Value& propertyValue )
788 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
792 case Toolkit::TextLabel::Property::TEXT_COLOR:
794 const Vector4& textColor = propertyValue.Get< Vector4 >();
795 if( mController->GetDefaultColor() != textColor )
797 mController->SetDefaultColor( textColor );
798 mTextUpdateNeeded = true;
804 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
810 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
812 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
815 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
817 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
819 if( mController->IsTextFitEnabled() )
821 mController->FitPointSizeforLayout( contentSize );
822 mController->SetTextFitContentSize( contentSize );
825 // Support Right-To-Left
826 Dali::LayoutDirection::Type layoutDirection;
827 if( mController->IsMatchSystemLanguageDirection() )
829 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( Self() ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
833 layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
835 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
837 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
838 || mTextUpdateNeeded )
840 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
843 TextVisual::EnableRendererUpdate( mVisual );
845 // Support Right-To-Left of padding
846 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
848 std::swap( padding.start, padding.end );
851 // Calculate the size of the visual that can fit the text
852 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
853 layoutSize.x = contentSize.x;
855 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
856 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
858 layoutSize.y += shadowOffset.y;
861 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
862 layoutSize.y += outlineWidth * 2.0f;
863 layoutSize.y = std::min( layoutSize.y, contentSize.y );
865 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
866 Vector2 alignmentOffset;
867 alignmentOffset.x = 0.0f;
868 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
870 Property::Map visualTransform;
871 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
872 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
873 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
874 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
875 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
876 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
877 mVisual.SetTransformAndSize( visualTransform, size );
879 if ( mController->IsAutoScrollEnabled() )
881 SetUpAutoScrolling();
884 mTextUpdateNeeded = false;
888 void TextLabel::RequestTextRelayout()
891 // Signal that a Relayout may be needed
894 void TextLabel::SetUpAutoScrolling()
896 const Size& controlSize = mController->GetView().GetControlSize();
897 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.
898 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
900 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
901 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
903 if ( !mTextScroller )
905 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
907 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
908 mTextScroller = Text::TextScroller::New( *this );
911 // Calculate the actual gap before scrolling wraps.
912 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
913 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
914 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
916 // Create a texture of the text for scrolling
917 Size verifiedSize = textureSize;
918 const int maxTextureSize = Dali::GetMaxTextureSize();
920 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
921 bool actualellipsis = mController->IsTextElideEnabled();
922 if( verifiedSize.width > maxTextureSize )
924 verifiedSize.width = maxTextureSize;
925 if( textNaturalSize.width > maxTextureSize )
927 mController->SetTextElideEnabled( true );
929 GetHeightForWidth( maxTextureSize );
930 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
933 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
935 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
936 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
937 data.GetPixelFormat(),
940 texture.Upload( data );
942 TextureSet textureSet = TextureSet::New();
943 textureSet.SetTexture( 0u, texture );
945 // Filter mode needs to be set to linear to produce better quality while scaling.
946 Sampler sampler = Sampler::New();
947 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
948 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
949 textureSet.SetSampler( 0u, sampler );
951 // Set parameters for scrolling
952 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
953 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
954 mController->SetTextElideEnabled( actualellipsis );
957 void TextLabel::ScrollingFinished()
959 // Pure Virtual from TextScroller Interface
960 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
961 mController->SetAutoScrollEnabled( false );
962 RequestTextRelayout();
965 TextLabel::TextLabel()
966 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
967 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
968 mTextUpdateNeeded( false )
972 TextLabel::~TextLabel()
976 } // namespace Internal
978 } // namespace Toolkit