2 * Copyright (c) 2018 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
82 #if defined ( DEBUG_ENABLED )
83 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
86 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
88 { "IMMEDIATE", Toolkit::TextLabel::AutoScrollStopMode::IMMEDIATE },
89 { "FINISH_LOOP", Toolkit::TextLabel::AutoScrollStopMode::FINISH_LOOP },
91 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
96 return Toolkit::TextLabel::New();
99 // Setup properties, signals and actions using the type-registry.
100 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "unusedPropertyTextColor", VECTOR4, UNUSED_PROPERTY_TEXT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
125 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
127 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "textDirection", INTEGER, TEXT_DIRECTION )
128 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalLineAlignment", INTEGER, VERTICAL_LINE_ALIGNMENT )
129 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textBackground", MAP, BACKGROUND )
130 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ignoreSpacesAfterText", BOOLEAN, IGNORE_SPACES_AFTER_TEXT )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
132 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR )
133 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 )
134 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 )
135 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2 )
136 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3 )
137 DALI_TYPE_REGISTRATION_END()
141 Toolkit::TextLabel TextLabel::New()
143 // Create the implementation, temporarily owned by this handle on stack
144 IntrusivePtr< TextLabel > impl = new TextLabel();
146 // Pass ownership to CustomActor handle
147 Toolkit::TextLabel handle( *impl );
149 // Second-phase init of the implementation
150 // This can only be done after the CustomActor connection has been made...
156 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
158 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
162 TextLabel& impl( GetImpl( label ) );
165 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
167 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
169 int backend = value.Get< int >();
171 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
172 if( Text::RENDERING_VECTOR_BASED == backend )
174 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
177 if( impl.mRenderingBackend != backend )
179 impl.mRenderingBackend = backend;
180 impl.mTextUpdateNeeded = true;
182 if( impl.mController )
184 // When using the vector-based rendering, the size of the GLyphs are different
185 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
186 impl.mController->SetGlyphType( glyphType );
191 case Toolkit::TextLabel::Property::TEXT:
193 if( impl.mController )
195 impl.mController->SetText( value.Get< std::string >() );
199 case Toolkit::TextLabel::Property::FONT_FAMILY:
201 if( impl.mController )
203 const std::string& fontFamily = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
206 impl.mController->SetDefaultFontFamily( fontFamily );
210 case Toolkit::TextLabel::Property::FONT_STYLE:
212 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
215 case Toolkit::TextLabel::Property::POINT_SIZE:
217 if( impl.mController )
219 const float pointSize = value.Get< float >();
221 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
223 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
228 case Toolkit::TextLabel::Property::MULTI_LINE:
230 if( impl.mController )
232 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
236 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
238 if( impl.mController )
240 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
241 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
243 impl.mController->SetHorizontalAlignment( alignment );
248 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
250 if( impl.mController )
252 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
253 if( Text::GetVerticalAlignmentEnumeration( value, alignment ) )
255 impl.mController->SetVerticalAlignment( alignment );
261 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
263 label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, value );
264 impl.mTextUpdateNeeded = true;
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 >());
478 // Request relayout when text update is needed. It's necessary to call it
479 // as changing the property not via UI interaction brings no effect if only
480 // the mTextUpdateNeeded is changed.
481 if( impl.mTextUpdateNeeded )
483 // need to request relayout as size of text may have changed
484 impl.RequestTextRelayout();
493 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
495 Property::Value value;
497 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
501 TextLabel& impl( GetImpl( label ) );
504 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
506 DALI_LOG_WARNING("[%s] Using deprecated Property TextLabel::Property::RENDERING_BACKEND which is no longer supported and will be ignored\n", __FUNCTION__);
508 value = impl.mRenderingBackend;
511 case Toolkit::TextLabel::Property::TEXT:
513 if( impl.mController )
516 impl.mController->GetText( text );
521 case Toolkit::TextLabel::Property::FONT_FAMILY:
523 if( impl.mController )
525 value = impl.mController->GetDefaultFontFamily();
529 case Toolkit::TextLabel::Property::FONT_STYLE:
531 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
534 case Toolkit::TextLabel::Property::POINT_SIZE:
536 if( impl.mController )
538 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
542 case Toolkit::TextLabel::Property::MULTI_LINE:
544 if( impl.mController )
546 value = impl.mController->IsMultiLineEnabled();
550 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
552 if( impl.mController )
554 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
558 value = std::string( name );
563 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
565 if( impl.mController )
567 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
570 value = std::string( name );
575 case Toolkit::TextLabel::Property::UNUSED_PROPERTY_TEXT_COLOR:
577 value = label.GetProperty( Toolkit::TextLabel::Property::TEXT_COLOR );
580 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
582 if( impl.mController )
584 value = impl.mController->IsMarkupProcessorEnabled();
588 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
590 if( impl.mController )
592 value = impl.mController->IsAutoScrollEnabled();
596 case Toolkit::TextLabel::Property::AUTO_SCROLL_STOP_MODE:
598 if( impl.mTextScroller )
600 const char* mode = Scripting::GetEnumerationName< Toolkit::TextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
601 AUTO_SCROLL_STOP_MODE_TABLE,
602 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
605 value = std::string( mode );
610 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
612 TextLabel& impl( GetImpl( label ) );
613 if ( impl.mTextScroller )
615 value = impl.mTextScroller->GetSpeed();
619 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
621 if( impl.mController )
623 TextLabel& impl( GetImpl( label ) );
624 if ( impl.mTextScroller )
626 value = impl.mTextScroller->GetLoopCount();
631 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
633 if( impl.mController )
635 TextLabel& impl( GetImpl( label ) );
636 if ( impl.mTextScroller )
638 value = impl.mTextScroller->GetLoopDelay();
643 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
645 TextLabel& impl( GetImpl( label ) );
646 if ( impl.mTextScroller )
648 value = impl.mTextScroller->GetGap();
652 case Toolkit::TextLabel::Property::LINE_SPACING:
654 if( impl.mController )
656 value = impl.mController->GetDefaultLineSpacing();
660 case Toolkit::TextLabel::Property::UNDERLINE:
662 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
665 case Toolkit::TextLabel::Property::SHADOW:
667 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
670 case Toolkit::TextLabel::Property::EMBOSS:
672 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
675 case Toolkit::TextLabel::Property::OUTLINE:
677 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
680 case Toolkit::TextLabel::Property::PIXEL_SIZE:
682 if( impl.mController )
684 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
688 case Toolkit::TextLabel::Property::ELLIPSIS:
690 if( impl.mController )
692 value = impl.mController->IsTextElideEnabled();
696 case Toolkit::TextLabel::Property::LINE_WRAP_MODE:
698 if( impl.mController )
700 value = impl.mController->GetLineWrapMode();
704 case Toolkit::TextLabel::Property::LINE_COUNT:
706 if( impl.mController )
708 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
709 value = impl.mController->GetLineCount( width );
713 case Toolkit::DevelTextLabel::Property::TEXT_DIRECTION:
715 if( impl.mController )
717 value = impl.mController->GetTextDirection();
721 case Toolkit::DevelTextLabel::Property::VERTICAL_LINE_ALIGNMENT:
723 if( impl.mController )
725 value = impl.mController->GetVerticalLineAlignment();
729 case Toolkit::DevelTextLabel::Property::BACKGROUND:
731 GetBackgroundProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
734 case Toolkit::DevelTextLabel::Property::IGNORE_SPACES_AFTER_TEXT:
736 value = impl.mController->IsIgnoreSpacesAfterText();
739 case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
741 value = impl.mController->IsMatchSystemLanguageDirection();
750 void TextLabel::OnInitialize()
754 Property::Map propertyMap;
755 propertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
757 mVisual = Toolkit::VisualFactory::Get().CreateVisual( propertyMap );
758 DevelControl::RegisterVisual( *this, Toolkit::TextLabel::Property::TEXT, mVisual );
760 TextVisual::SetAnimatableTextColorProperty( mVisual, Toolkit::TextLabel::Property::TEXT_COLOR );
762 mController = TextVisual::GetController(mVisual);
765 mController->SetControlInterface(this);
768 // Use height-for-width negotiation by default
769 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
770 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
772 // Enable the text ellipsis.
773 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
775 // Sets layoutDirection value
776 Dali::Stage stage = Dali::Stage::GetCurrent();
777 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
778 mController->SetLayoutDirection( layoutDirection );
780 Layout::Engine& engine = mController->GetLayoutEngine();
781 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
784 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
786 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
790 case StyleChange::DEFAULT_FONT_CHANGE:
792 // Property system did not set the font so should update it.
793 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
794 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
795 mController->UpdateAfterFontChange( newFont );
799 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
801 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
805 case StyleChange::THEME_CHANGE:
807 // Nothing to do, let control base class handle this
812 // Up call to Control
813 Control::OnStyleChange( styleManager, change );
816 Vector3 TextLabel::GetNaturalSize()
819 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
821 Vector3 naturalSize = mController->GetNaturalSize();
822 naturalSize.width += ( padding.start + padding.end );
823 naturalSize.height += ( padding.top + padding.bottom );
828 float TextLabel::GetHeightForWidth( float width )
831 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
833 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
836 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
838 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
842 case Toolkit::TextLabel::Property::TEXT_COLOR:
844 const Vector4& textColor = propertyValue.Get< Vector4 >();
845 if( mController->GetDefaultColor() != textColor )
847 mController->SetDefaultColor( textColor );
848 mTextUpdateNeeded = true;
854 Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
860 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
862 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
865 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
867 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
869 // Support Right-To-Left
870 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
872 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
874 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
875 || mTextUpdateNeeded )
877 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
880 TextVisual::EnableRendererUpdate( mVisual );
882 // Support Right-To-Left of padding
883 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
885 std::swap( padding.start, padding.end );
888 // Calculate the size of the visual that can fit the text
889 Size layoutSize = mController->GetTextModel()->GetLayoutSize();
890 layoutSize.x = contentSize.x;
892 const Vector2& shadowOffset = mController->GetTextModel()->GetShadowOffset();
893 if ( shadowOffset.y > Math::MACHINE_EPSILON_1 )
895 layoutSize.y += shadowOffset.y;
898 float outlineWidth = mController->GetTextModel()->GetOutlineWidth();
899 layoutSize.y += outlineWidth * 2.0f;
900 layoutSize.y = std::min( layoutSize.y, contentSize.y );
902 // Calculate the offset for vertical alignment only, as the layout engine will do the horizontal alignment.
903 Vector2 alignmentOffset;
904 alignmentOffset.x = 0.0f;
905 alignmentOffset.y = ( contentSize.y - layoutSize.y ) * VERTICAL_ALIGNMENT_TABLE[mController->GetVerticalAlignment()];
907 Property::Map visualTransform;
908 visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, layoutSize )
909 .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
910 .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( padding.start, padding.top ) + alignmentOffset )
911 .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
912 .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
913 .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
914 mVisual.SetTransformAndSize( visualTransform, size );
916 if ( mController->IsAutoScrollEnabled() )
918 SetUpAutoScrolling();
921 mTextUpdateNeeded = false;
925 void TextLabel::RequestTextRelayout()
928 Toolkit::DevelControl::RequestLayout( *this );
931 void TextLabel::SetUpAutoScrolling()
933 const Size& controlSize = mController->GetView().GetControlSize();
934 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.
935 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
937 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling textNaturalSize[%f,%f] controlSize[%f,%f]\n",
938 textNaturalSize.x,textNaturalSize.y , controlSize.x,controlSize.y );
940 if ( !mTextScroller )
942 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
944 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
945 mTextScroller = Text::TextScroller::New( *this );
948 // Calculate the actual gap before scrolling wraps.
949 int textPadding = std::max( controlSize.x - textNaturalSize.x, 0.0f );
950 float wrapGap = std::max( mTextScroller->GetGap(), textPadding );
951 Vector2 textureSize = textNaturalSize + Vector2(wrapGap, 0.0f); // Add the gap as a part of the texture
953 // Create a texture of the text for scrolling
954 Size verifiedSize = textureSize;
955 const int maxTextureSize = Dali::GetMaxTextureSize();
957 //if the texture size width exceed maxTextureSize, modify the visual model size and enabled the ellipsis
958 if( verifiedSize.width > maxTextureSize )
960 verifiedSize.width = maxTextureSize;
961 if( textNaturalSize.width > maxTextureSize )
963 mController->SetTextElideEnabled( true );
965 GetHeightForWidth( maxTextureSize );
966 wrapGap = std::max( maxTextureSize - textNaturalSize.width, 0.0f );
969 Text::TypesetterPtr typesetter = Text::Typesetter::New( mController->GetTextModel() );
971 PixelData data = typesetter->Render( verifiedSize, mController->GetTextDirection(), Text::Typesetter::RENDER_TEXT_AND_STYLES, true, Pixel::RGBA8888 ); // ignore the horizontal alignment
972 Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D,
973 data.GetPixelFormat(),
976 texture.Upload( data );
978 TextureSet textureSet = TextureSet::New();
979 textureSet.SetTexture( 0u, texture );
981 // Filter mode needs to be set to linear to produce better quality while scaling.
982 Sampler sampler = Sampler::New();
983 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
984 sampler.SetWrapMode( Dali::WrapMode::DEFAULT, Dali::WrapMode::REPEAT, Dali::WrapMode::DEFAULT ); // Wrap the texture in the x direction
985 textureSet.SetSampler( 0u, sampler );
987 // Set parameters for scrolling
988 Renderer renderer = static_cast<Internal::Visual::Base&>( GetImplementation( mVisual ) ).GetRenderer();
989 mTextScroller->SetParameters( Self(), renderer, textureSet, controlSize, verifiedSize, wrapGap, direction, mController->GetHorizontalAlignment(), mController->GetVerticalAlignment() );
992 void TextLabel::ScrollingFinished()
994 // Pure Virtual from TextScroller Interface
995 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
996 mController->SetAutoScrollEnabled( false );
997 mController->SetTextElideEnabled( true );
998 RequestTextRelayout();
1001 TextLabel::TextLabel()
1002 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1003 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1004 mTextUpdateNeeded( false )
1008 TextLabel::~TextLabel()
1012 } // namespace Internal
1014 } // namespace Toolkit