2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
22 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/public-api/text/rendering-backend.h>
28 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
29 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
30 #include <dali-toolkit/internal/text/property-string-parser.h>
31 #include <dali-toolkit/internal/text/rendering/text-backend.h>
32 #include <dali-toolkit/internal/text/text-effects-style.h>
33 #include <dali-toolkit/internal/text/text-font-style.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/text/text-definitions.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
51 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 #if defined ( DEBUG_ENABLED )
58 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
61 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
63 { "IMMEDIATE", Toolkit::DevelTextLabel::AutoScrollStopMode::IMMEDIATE },
64 { "FINISH_LOOP", Toolkit::DevelTextLabel::AutoScrollStopMode::FINISH_LOOP },
66 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
68 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
70 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
71 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
72 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
74 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
76 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
78 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
79 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
80 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
82 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
84 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
86 { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD },
87 { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
89 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
94 return Toolkit::TextLabel::New();
97 // Setup properties, signals and actions using the type-registry.
98 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
124 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
125 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
126 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
127 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
128 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
129 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE )
131 DALI_TYPE_REGISTRATION_END()
135 Toolkit::TextLabel TextLabel::New()
137 // Create the implementation, temporarily owned by this handle on stack
138 IntrusivePtr< TextLabel > impl = new TextLabel();
140 // Pass ownership to CustomActor handle
141 Toolkit::TextLabel handle( *impl );
143 // Second-phase init of the implementation
144 // This can only be done after the CustomActor connection has been made...
150 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
152 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
156 TextLabel& impl( GetImpl( label ) );
159 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
161 int backend = value.Get< int >();
163 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
164 if( Text::RENDERING_VECTOR_BASED == backend )
166 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
169 if( impl.mRenderingBackend != backend )
171 impl.mRenderingBackend = backend;
172 impl.mRenderer.Reset();
174 if( impl.mController )
176 // When using the vector-based rendering, the size of the GLyphs are different
177 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
178 impl.mController->SetGlyphType( glyphType );
183 case Toolkit::TextLabel::Property::TEXT:
185 if( impl.mController )
187 impl.mController->SetText( value.Get< std::string >() );
191 case Toolkit::TextLabel::Property::FONT_FAMILY:
193 if( impl.mController )
195 const std::string& fontFamily = value.Get< std::string >();
197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
198 impl.mController->SetDefaultFontFamily( fontFamily );
202 case Toolkit::TextLabel::Property::FONT_STYLE:
204 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
207 case Toolkit::TextLabel::Property::POINT_SIZE:
209 if( impl.mController )
211 const float pointSize = value.Get< float >();
213 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
215 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
220 case Toolkit::TextLabel::Property::MULTI_LINE:
222 if( impl.mController )
224 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
228 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
230 if( impl.mController )
232 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
233 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
234 HORIZONTAL_ALIGNMENT_STRING_TABLE,
235 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
238 impl.mController->SetHorizontalAlignment( alignment );
243 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
245 if( impl.mController )
247 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
248 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
249 VERTICAL_ALIGNMENT_STRING_TABLE,
250 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
253 impl.mController->SetVerticalAlignment( alignment );
259 case Toolkit::TextLabel::Property::TEXT_COLOR:
261 if( impl.mController )
263 const Vector4& textColor = value.Get< Vector4 >();
264 if( impl.mController->GetDefaultColor() != textColor )
266 impl.mController->SetDefaultColor( textColor );
267 impl.mRenderer.Reset();
273 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
275 if( impl.mController )
277 const Vector2& shadowOffset = value.Get< Vector2 >();
278 if ( impl.mController->GetShadowOffset() != shadowOffset )
280 impl.mController->SetShadowOffset( shadowOffset );
281 impl.mRenderer.Reset();
286 case Toolkit::TextLabel::Property::SHADOW_COLOR:
288 if( impl.mController )
290 const Vector4& shadowColor = value.Get< Vector4 >();
291 if ( impl.mController->GetShadowColor() != shadowColor )
293 impl.mController->SetShadowColor( shadowColor );
294 impl.mRenderer.Reset();
299 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
301 if( impl.mController )
303 const Vector4& color = value.Get< Vector4 >();
304 if ( impl.mController->GetUnderlineColor() != color )
306 impl.mController->SetUnderlineColor( color );
307 impl.mRenderer.Reset();
312 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
314 if( impl.mController )
316 const bool enabled = value.Get< bool >();
317 if ( impl.mController->IsUnderlineEnabled() != enabled )
319 impl.mController->SetUnderlineEnabled( enabled );
320 impl.mRenderer.Reset();
326 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
328 if( impl.mController )
330 float height = value.Get< float >();
331 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
333 impl.mController->SetUnderlineHeight( height );
334 impl.mRenderer.Reset();
339 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
341 if( impl.mController )
343 const bool enableMarkup = value.Get<bool>();
344 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
348 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
350 if( impl.mController )
352 const bool enableAutoScroll = value.Get<bool>();
353 // If request to auto scroll is the same as current state then do nothing.
354 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
356 // If request is disable (false) and auto scrolling is enabled then need to stop it
357 if ( enableAutoScroll == false )
359 if( impl.mTextScroller )
361 impl.mTextScroller->StopScrolling();
364 // If request is enable (true) then start autoscroll as not already running
367 impl.mController->SetTextElideEnabled( false );
368 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
374 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
376 if( !impl.mTextScroller )
378 impl.mTextScroller = Text::TextScroller::New( impl );
380 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
381 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
382 AUTO_SCROLL_STOP_MODE_TABLE,
383 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
386 impl.mTextScroller->SetStopMode( stopMode );
390 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
392 if( !impl.mTextScroller )
394 impl.mTextScroller = Text::TextScroller::New( impl );
396 impl.mTextScroller->SetSpeed( value.Get<int>() );
399 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
401 if( !impl.mTextScroller )
403 impl.mTextScroller = Text::TextScroller::New( impl );
405 impl.mTextScroller->SetLoopCount( value.Get<int>() );
408 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
410 if( !impl.mTextScroller )
412 impl.mTextScroller = Text::TextScroller::New( impl );
414 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
417 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
419 if( !impl.mTextScroller )
421 impl.mTextScroller = Text::TextScroller::New( impl );
423 impl.mTextScroller->SetGap( value.Get<float>() );
426 case Toolkit::TextLabel::Property::LINE_SPACING:
428 if( impl.mController )
430 const float lineSpacing = value.Get<float>();
431 impl.mController->SetDefaultLineSpacing( lineSpacing );
432 impl.mRenderer.Reset();
436 case Toolkit::TextLabel::Property::UNDERLINE:
438 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
441 impl.mRenderer.Reset();
445 case Toolkit::TextLabel::Property::SHADOW:
447 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
450 impl.mRenderer.Reset();
454 case Toolkit::TextLabel::Property::EMBOSS:
456 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
459 impl.mRenderer.Reset();
463 case Toolkit::TextLabel::Property::OUTLINE:
465 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
468 impl.mRenderer.Reset();
472 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
474 if( impl.mController )
476 const float pixelSize = value.Get< float >();
477 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
479 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
481 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
486 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
488 if( impl.mController )
490 const bool ellipsis = value.Get<bool>();
491 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
493 impl.mController->SetTextElideEnabled( ellipsis );
497 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
499 const std::string& wrapModeStr = value.Get< std::string >();
500 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
502 Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
503 if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
504 LINE_WRAP_MODE_STRING_TABLE,
505 LINE_WRAP_MODE_STRING_TABLE_COUNT,
508 impl.mController->SetLineWrapMode( lineWrapMode );
516 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
518 Property::Value value;
520 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
524 TextLabel& impl( GetImpl( label ) );
527 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
529 value = impl.mRenderingBackend;
532 case Toolkit::TextLabel::Property::TEXT:
534 if( impl.mController )
537 impl.mController->GetText( text );
542 case Toolkit::TextLabel::Property::FONT_FAMILY:
544 if( impl.mController )
546 value = impl.mController->GetDefaultFontFamily();
550 case Toolkit::TextLabel::Property::FONT_STYLE:
552 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
555 case Toolkit::TextLabel::Property::POINT_SIZE:
557 if( impl.mController )
559 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
563 case Toolkit::TextLabel::Property::MULTI_LINE:
565 if( impl.mController )
567 value = impl.mController->IsMultiLineEnabled();
571 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
573 if( impl.mController )
575 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
576 HORIZONTAL_ALIGNMENT_STRING_TABLE,
577 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
580 value = std::string( name );
585 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
587 if( impl.mController )
589 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
590 VERTICAL_ALIGNMENT_STRING_TABLE,
591 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
594 value = std::string( name );
599 case Toolkit::TextLabel::Property::TEXT_COLOR:
601 if ( impl.mController )
603 value = impl.mController->GetDefaultColor();
607 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
609 if ( impl.mController )
611 value = impl.mController->GetShadowOffset();
615 case Toolkit::TextLabel::Property::SHADOW_COLOR:
617 if ( impl.mController )
619 value = impl.mController->GetShadowColor();
623 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
625 if ( impl.mController )
627 value = impl.mController->GetUnderlineColor();
631 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
633 if ( impl.mController )
635 value = impl.mController->IsUnderlineEnabled();
639 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
641 if ( impl.mController )
643 value = impl.mController->GetUnderlineHeight();
647 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
649 if( impl.mController )
651 value = impl.mController->IsMarkupProcessorEnabled();
655 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
657 if( impl.mController )
659 value = impl.mController->IsAutoScrollEnabled();
663 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
665 if( impl.mTextScroller )
667 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
668 AUTO_SCROLL_STOP_MODE_TABLE,
669 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
672 value = std::string( mode );
677 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
679 TextLabel& impl( GetImpl( label ) );
680 if ( impl.mTextScroller )
682 value = impl.mTextScroller->GetSpeed();
686 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
688 if( impl.mController )
690 TextLabel& impl( GetImpl( label ) );
691 if ( impl.mTextScroller )
693 value = impl.mTextScroller->GetLoopCount();
698 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
700 if( impl.mController )
702 TextLabel& impl( GetImpl( label ) );
703 if ( impl.mTextScroller )
705 value = impl.mTextScroller->GetLoopDelay();
710 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
712 TextLabel& impl( GetImpl( label ) );
713 if ( impl.mTextScroller )
715 value = impl.mTextScroller->GetGap();
719 case Toolkit::TextLabel::Property::LINE_SPACING:
721 if( impl.mController )
723 value = impl.mController->GetDefaultLineSpacing();
727 case Toolkit::TextLabel::Property::UNDERLINE:
729 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
732 case Toolkit::TextLabel::Property::SHADOW:
734 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
737 case Toolkit::TextLabel::Property::EMBOSS:
739 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
742 case Toolkit::TextLabel::Property::OUTLINE:
744 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
747 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
749 if( impl.mController )
751 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
755 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
757 if( impl.mController )
759 value = impl.mController->IsTextElideEnabled();
763 case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
765 if( impl.mController )
767 value = impl.mController->GetLineWrapMode();
771 case Toolkit::DevelTextLabel::Property::LINE_COUNT:
773 if( impl.mController )
775 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
776 value = impl.mController->GetLineCount( width );
786 void TextLabel::OnInitialize()
790 mController = Text::Controller::New( this );
792 // When using the vector-based rendering, the size of the GLyphs are different
793 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
794 mController->SetGlyphType( glyphType );
796 // Use height-for-width negotiation by default
797 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
798 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
800 // Enable the text ellipsis.
801 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
803 Layout::Engine& engine = mController->GetLayoutEngine();
804 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
806 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
809 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
815 case StyleChange::DEFAULT_FONT_CHANGE:
817 // Property system did not set the font so should update it.
818 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
819 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
820 mController->UpdateAfterFontChange( newFont );
824 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
826 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
830 case StyleChange::THEME_CHANGE:
832 // Nothing to do, let control base class handle this
837 // Up call to Control
838 Control::OnStyleChange( styleManager, change );
841 Vector3 TextLabel::GetNaturalSize()
843 return mController->GetNaturalSize();
846 float TextLabel::GetHeightForWidth( float width )
849 Self().GetPadding( padding );
850 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
853 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
855 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
858 Self().GetPadding( padding );
859 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
862 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
864 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
869 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
875 void TextLabel::RequestTextRelayout()
880 void TextLabel::RenderText()
882 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
885 Actor renderableActor;
887 float alignmentOffset = 0.f;
890 renderableActor = mRenderer->Render( mController->GetView(),
892 DepthIndex::CONTENT );
895 if( renderableActor != mRenderableActor )
897 UnparentAndReset( mRenderableActor );
899 if( renderableActor )
901 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
903 self.GetPadding( padding );
904 renderableActor.SetPosition( scrollOffset.x + alignmentOffset + padding.left, scrollOffset.y + padding.top );
906 self.Add( renderableActor );
908 mRenderableActor = renderableActor;
910 if ( mController->IsAutoScrollEnabled() )
912 SetUpAutoScrolling();
917 void TextLabel::SetUpAutoScrolling()
919 const Size& controlSize = mController->GetView().GetControlSize();
920 const Size offScreenSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
921 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
922 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
924 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
925 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
927 if ( !mTextScroller )
929 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
931 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
932 mTextScroller = Text::TextScroller::New( *this );
934 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset, mController->GetHorizontalAlignment() );
937 self.Add( mTextScroller->GetScrollingText() );
938 self.Add( mTextScroller->GetSourceCamera() );
941 void TextLabel::OnStageConnect( Dali::Actor actor )
943 if ( mHasBeenStaged )
949 mHasBeenStaged = true;
953 void TextLabel::ScrollingFinished()
955 // Pure Virtual from TextScroller Interface
956 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
957 mController->SetAutoScrollEnabled( false );
958 mController->SetTextElideEnabled( true );
959 RequestTextRelayout();
962 TextLabel::TextLabel()
963 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
964 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
965 mHasBeenStaged( false )
969 TextLabel::~TextLabel()
973 } // namespace Internal
975 } // namespace Toolkit