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] );
87 return Toolkit::TextLabel::New();
90 // Setup properties, signals and actions using the type-registry.
91 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend", INTEGER, RENDERING_BACKEND )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text", STRING, TEXT )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle", MAP, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine", BOOLEAN, MULTI_LINE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor", VECTOR4, TEXT_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset", VECTOR2, SHADOW_OFFSET )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor", VECTOR4, SHADOW_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled", BOOLEAN, UNDERLINE_ENABLED )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor", VECTOR4, UNDERLINE_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight", FLOAT, UNDERLINE_HEIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll", BOOLEAN, ENABLE_AUTO_SCROLL )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed", INTEGER, AUTO_SCROLL_SPEED )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount", INTEGER, AUTO_SCROLL_LOOP_COUNT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap", FLOAT, AUTO_SCROLL_GAP )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing", FLOAT, LINE_SPACING )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline", MAP, UNDERLINE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow", MAP, SHADOW )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss", MAP, EMBOSS )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline", MAP, OUTLINE )
117 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize", FLOAT, PIXEL_SIZE )
118 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOOLEAN, ELLIPSIS )
119 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY )
120 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE )
121 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT )
123 DALI_TYPE_REGISTRATION_END()
127 Toolkit::TextLabel TextLabel::New()
129 // Create the implementation, temporarily owned by this handle on stack
130 IntrusivePtr< TextLabel > impl = new TextLabel();
132 // Pass ownership to CustomActor handle
133 Toolkit::TextLabel handle( *impl );
135 // Second-phase init of the implementation
136 // This can only be done after the CustomActor connection has been made...
142 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
144 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
148 TextLabel& impl( GetImpl( label ) );
151 case Toolkit::TextLabel::Property::RENDERING_BACKEND:
153 int backend = value.Get< int >();
155 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
156 if( Text::RENDERING_VECTOR_BASED == backend )
158 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
161 if( impl.mRenderingBackend != backend )
163 impl.mRenderingBackend = backend;
164 impl.mRenderer.Reset();
166 if( impl.mController )
168 // When using the vector-based rendering, the size of the GLyphs are different
169 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
170 impl.mController->SetGlyphType( glyphType );
175 case Toolkit::TextLabel::Property::TEXT:
177 if( impl.mController )
179 impl.mController->SetText( value.Get< std::string >() );
183 case Toolkit::TextLabel::Property::FONT_FAMILY:
185 if( impl.mController )
187 const std::string& fontFamily = value.Get< std::string >();
189 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
190 impl.mController->SetDefaultFontFamily( fontFamily );
194 case Toolkit::TextLabel::Property::FONT_STYLE:
196 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
199 case Toolkit::TextLabel::Property::POINT_SIZE:
201 if( impl.mController )
203 const float pointSize = value.Get< float >();
205 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
207 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
212 case Toolkit::TextLabel::Property::MULTI_LINE:
214 if( impl.mController )
216 impl.mController->SetMultiLineEnabled( value.Get< bool >() );
220 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
222 if( impl.mController )
224 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
225 if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
226 HORIZONTAL_ALIGNMENT_STRING_TABLE,
227 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
230 impl.mController->SetHorizontalAlignment( alignment );
235 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
237 if( impl.mController )
239 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
240 if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
241 VERTICAL_ALIGNMENT_STRING_TABLE,
242 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
245 impl.mController->SetVerticalAlignment( alignment );
251 case Toolkit::TextLabel::Property::TEXT_COLOR:
253 if( impl.mController )
255 const Vector4& textColor = value.Get< Vector4 >();
256 if( impl.mController->GetDefaultColor() != textColor )
258 impl.mController->SetDefaultColor( textColor );
259 impl.mRenderer.Reset();
265 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
267 if( impl.mController )
269 const Vector2& shadowOffset = value.Get< Vector2 >();
270 if ( impl.mController->GetShadowOffset() != shadowOffset )
272 impl.mController->SetShadowOffset( shadowOffset );
273 impl.mRenderer.Reset();
278 case Toolkit::TextLabel::Property::SHADOW_COLOR:
280 if( impl.mController )
282 const Vector4& shadowColor = value.Get< Vector4 >();
283 if ( impl.mController->GetShadowColor() != shadowColor )
285 impl.mController->SetShadowColor( shadowColor );
286 impl.mRenderer.Reset();
291 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
293 if( impl.mController )
295 const Vector4& color = value.Get< Vector4 >();
296 if ( impl.mController->GetUnderlineColor() != color )
298 impl.mController->SetUnderlineColor( color );
299 impl.mRenderer.Reset();
304 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
306 if( impl.mController )
308 const bool enabled = value.Get< bool >();
309 if ( impl.mController->IsUnderlineEnabled() != enabled )
311 impl.mController->SetUnderlineEnabled( enabled );
312 impl.mRenderer.Reset();
318 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
320 if( impl.mController )
322 float height = value.Get< float >();
323 if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
325 impl.mController->SetUnderlineHeight( height );
326 impl.mRenderer.Reset();
331 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
333 if( impl.mController )
335 const bool enableMarkup = value.Get<bool>();
336 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
340 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
342 if( impl.mController )
344 const bool enableAutoScroll = value.Get<bool>();
345 // If request to auto scroll is the same as current state then do nothing.
346 if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
348 // If request is disable (false) and auto scrolling is enabled then need to stop it
349 if ( enableAutoScroll == false )
351 if( impl.mTextScroller )
353 impl.mTextScroller->StopScrolling();
356 // If request is enable (true) then start autoscroll as not already running
359 impl.mController->SetTextElideEnabled( false );
360 impl.mController->SetAutoScrollEnabled( enableAutoScroll );
366 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
368 if( !impl.mTextScroller )
370 impl.mTextScroller = Text::TextScroller::New( impl );
372 DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
373 if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
374 AUTO_SCROLL_STOP_MODE_TABLE,
375 AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
378 impl.mTextScroller->SetStopMode( stopMode );
382 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
384 if( !impl.mTextScroller )
386 impl.mTextScroller = Text::TextScroller::New( impl );
388 impl.mTextScroller->SetSpeed( value.Get<int>() );
391 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
393 if( !impl.mTextScroller )
395 impl.mTextScroller = Text::TextScroller::New( impl );
397 impl.mTextScroller->SetLoopCount( value.Get<int>() );
400 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
402 if( !impl.mTextScroller )
404 impl.mTextScroller = Text::TextScroller::New( impl );
406 impl.mTextScroller->SetLoopDelay( value.Get<float>() );
409 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
411 if( !impl.mTextScroller )
413 impl.mTextScroller = Text::TextScroller::New( impl );
415 impl.mTextScroller->SetGap( value.Get<float>() );
418 case Toolkit::TextLabel::Property::LINE_SPACING:
420 if( impl.mController )
422 const float lineSpacing = value.Get<float>();
423 impl.mController->SetDefaultLineSpacing( lineSpacing );
424 impl.mRenderer.Reset();
428 case Toolkit::TextLabel::Property::UNDERLINE:
430 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
433 impl.mRenderer.Reset();
437 case Toolkit::TextLabel::Property::SHADOW:
439 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
442 impl.mRenderer.Reset();
446 case Toolkit::TextLabel::Property::EMBOSS:
448 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
451 impl.mRenderer.Reset();
455 case Toolkit::TextLabel::Property::OUTLINE:
457 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
460 impl.mRenderer.Reset();
464 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
466 if( impl.mController )
468 const float pixelSize = value.Get< float >();
469 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
471 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
473 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
478 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
480 if( impl.mController )
482 const bool ellipsis = value.Get<bool>();
483 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
485 impl.mController->SetTextElideEnabled( ellipsis );
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 value = impl.mRenderingBackend;
509 case Toolkit::TextLabel::Property::TEXT:
511 if( impl.mController )
514 impl.mController->GetText( text );
519 case Toolkit::TextLabel::Property::FONT_FAMILY:
521 if( impl.mController )
523 value = impl.mController->GetDefaultFontFamily();
527 case Toolkit::TextLabel::Property::FONT_STYLE:
529 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
532 case Toolkit::TextLabel::Property::POINT_SIZE:
534 if( impl.mController )
536 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
540 case Toolkit::TextLabel::Property::MULTI_LINE:
542 if( impl.mController )
544 value = impl.mController->IsMultiLineEnabled();
548 case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
550 if( impl.mController )
552 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
553 HORIZONTAL_ALIGNMENT_STRING_TABLE,
554 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
557 value = std::string( name );
562 case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
564 if( impl.mController )
566 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
567 VERTICAL_ALIGNMENT_STRING_TABLE,
568 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
571 value = std::string( name );
576 case Toolkit::TextLabel::Property::TEXT_COLOR:
578 if ( impl.mController )
580 value = impl.mController->GetDefaultColor();
584 case Toolkit::TextLabel::Property::SHADOW_OFFSET:
586 if ( impl.mController )
588 value = impl.mController->GetShadowOffset();
592 case Toolkit::TextLabel::Property::SHADOW_COLOR:
594 if ( impl.mController )
596 value = impl.mController->GetShadowColor();
600 case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
602 if ( impl.mController )
604 value = impl.mController->GetUnderlineColor();
608 case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
610 if ( impl.mController )
612 value = impl.mController->IsUnderlineEnabled();
616 case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
618 if ( impl.mController )
620 value = impl.mController->GetUnderlineHeight();
624 case Toolkit::TextLabel::Property::ENABLE_MARKUP:
626 if( impl.mController )
628 value = impl.mController->IsMarkupProcessorEnabled();
632 case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
634 if( impl.mController )
636 value = impl.mController->IsAutoScrollEnabled();
640 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
642 if( impl.mTextScroller )
644 const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
645 AUTO_SCROLL_STOP_MODE_TABLE,
646 AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
649 value = std::string( mode );
654 case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
656 TextLabel& impl( GetImpl( label ) );
657 if ( impl.mTextScroller )
659 value = impl.mTextScroller->GetSpeed();
663 case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
665 if( impl.mController )
667 TextLabel& impl( GetImpl( label ) );
668 if ( impl.mTextScroller )
670 value = impl.mTextScroller->GetLoopCount();
675 case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
677 if( impl.mController )
679 TextLabel& impl( GetImpl( label ) );
680 if ( impl.mTextScroller )
682 value = impl.mTextScroller->GetLoopDelay();
687 case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
689 TextLabel& impl( GetImpl( label ) );
690 if ( impl.mTextScroller )
692 value = impl.mTextScroller->GetGap();
696 case Toolkit::TextLabel::Property::LINE_SPACING:
698 if( impl.mController )
700 value = impl.mController->GetDefaultLineSpacing();
704 case Toolkit::TextLabel::Property::UNDERLINE:
706 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
709 case Toolkit::TextLabel::Property::SHADOW:
711 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
714 case Toolkit::TextLabel::Property::EMBOSS:
716 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
719 case Toolkit::TextLabel::Property::OUTLINE:
721 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
724 case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
726 if( impl.mController )
728 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
732 case Toolkit::DevelTextLabel::Property::ELLIPSIS:
734 if( impl.mController )
736 value = impl.mController->IsTextElideEnabled();
740 case Toolkit::DevelTextLabel::Property::LINE_COUNT:
742 if( impl.mController )
744 float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
745 value = impl.mController->GetLineCount( width );
755 void TextLabel::OnInitialize()
759 mController = Text::Controller::New( this );
761 // When using the vector-based rendering, the size of the GLyphs are different
762 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
763 mController->SetGlyphType( glyphType );
765 // Use height-for-width negotiation by default
766 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
767 self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
769 // Enable the text ellipsis.
770 mController->SetTextElideEnabled( true ); // If false then text larger than control will overflow
772 Layout::Engine& engine = mController->GetLayoutEngine();
773 engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
775 self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
778 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
780 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
784 case StyleChange::DEFAULT_FONT_CHANGE:
786 // Property system did not set the font so should update it.
787 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
788 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
789 mController->UpdateAfterFontChange( newFont );
793 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
795 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
799 case StyleChange::THEME_CHANGE:
801 // Nothing to do, let control base class handle this
806 // Up call to Control
807 Control::OnStyleChange( styleManager, change );
810 Vector3 TextLabel::GetNaturalSize()
812 return mController->GetNaturalSize();
815 float TextLabel::GetHeightForWidth( float width )
817 return mController->GetHeightForWidth( width );
820 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
822 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
824 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
826 if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
831 mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
837 void TextLabel::RequestTextRelayout()
842 void TextLabel::RenderText()
844 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
847 Actor renderableActor;
849 float alignmentOffset = 0.f;
852 renderableActor = mRenderer->Render( mController->GetView(),
854 DepthIndex::CONTENT );
857 if( renderableActor != mRenderableActor )
859 UnparentAndReset( mRenderableActor );
861 if( renderableActor )
863 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
864 renderableActor.SetPosition( scrollOffset.x + alignmentOffset, scrollOffset.y );
866 self.Add( renderableActor );
868 mRenderableActor = renderableActor;
870 if ( mController->IsAutoScrollEnabled() )
872 SetUpAutoScrolling();
877 void TextLabel::SetUpAutoScrolling()
879 const Size& controlSize = mController->GetView().GetControlSize();
880 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.
881 const float alignmentOffset = mController->GetAutoScrollLineAlignment();
882 const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
884 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
885 alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
887 if ( !mTextScroller )
889 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
891 // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
892 mTextScroller = Text::TextScroller::New( *this );
894 mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset, mController->GetHorizontalAlignment() );
897 self.Add( mTextScroller->GetScrollingText() );
898 self.Add( mTextScroller->GetSourceCamera() );
901 void TextLabel::OnStageConnect( Dali::Actor actor )
903 if ( mHasBeenStaged )
909 mHasBeenStaged = true;
913 void TextLabel::ScrollingFinished()
915 // Pure Virtual from TextScroller Interface
916 DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
917 mController->SetAutoScrollEnabled( false );
918 mController->SetTextElideEnabled( true );
919 RequestTextRelayout();
922 TextLabel::TextLabel()
923 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
924 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
925 mHasBeenStaged( false )
929 TextLabel::~TextLabel()
933 } // namespace Internal
935 } // namespace Toolkit