// EXTERNAL HEADER
#include <dali/devel-api/scripting/enum-helper.h>
-// #include <dali/devel-api/scripting/scripting.h>
// INTERNAL HEADER
#include <dali-toolkit/public-api/text/rendering-backend.h>
#include <dali-toolkit/public-api/visuals/text-visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/internal/text/layouts/layout-alignment.h>
#include <dali-toolkit/internal/text/rendering/text-backend.h>
+#include <dali-toolkit/internal/text/text-effects-style.h>
+#include <dali-toolkit/internal/text/text-font-style.h>
#include <dali-toolkit/internal/text/text-view.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
-#include <dali-toolkit/internal/text/text-font-style.h>
-#include <dali-toolkit/internal/text/text-effects-style.h>
-
-using Dali::Toolkit::Text::LayoutEngine;
namespace Dali
{
const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
{
- { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
- { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
- { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
+ { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
+ { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
+ { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
};
const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
{
- { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
- { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
- { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+ { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
+ { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
+ { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
};
const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
-std::string GetHorizontalAlignment( LayoutEngine::HorizontalAlignment alignment )
+std::string GetHorizontalAlignment( Toolkit::Text::Layout::HorizontalAlignment alignment )
{
- const char* name = Scripting::GetEnumerationName<Toolkit::Text::LayoutEngine::HorizontalAlignment>( alignment,
- HORIZONTAL_ALIGNMENT_STRING_TABLE,
- HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
+ const char* name = Scripting::GetEnumerationName<Toolkit::Text::Layout::HorizontalAlignment>( alignment,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
return std::string( name );
}
-std::string GetVerticalAlignment( LayoutEngine::VerticalAlignment alignment )
+std::string GetVerticalAlignment( Toolkit::Text::Layout::VerticalAlignment alignment )
{
- const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( alignment,
- VERTICAL_ALIGNMENT_STRING_TABLE,
- VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+ const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( alignment,
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
return std::string( name );
}
return geometry;
}
-} // namespace
-
-TextVisual::TextVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
- mController( Text::Controller::New() ),
- mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
- mHasBeenStaged( false )
-{
-}
-
-TextVisual::~TextVisual()
-{
-}
+} // unnamed namespace
-void TextVisual::SetTextControlInterface( Text::ControlInterface* controlInterface )
+TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache )
{
- if( mController )
- {
- mController->SetTextControlInterface( controlInterface );
- }
-}
-
-void TextVisual::SetSize( const Vector2& size )
-{
- const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
-
- if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
- !mRenderer )
- {
- if( !mRenderer )
- {
- mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
- }
-
- RenderText();
- }
+ return new TextVisual( factoryCache );
}
float TextVisual::GetHeightForWidth( float width ) const
return mController->GetHeightForWidth( width );
}
-void TextVisual::GetNaturalSize( Vector2& naturalSize ) const
+void TextVisual::GetNaturalSize( Vector2& naturalSize )
{
naturalSize = mController->GetNaturalSize().GetVectorXY();
}
Property::Value value;
map.Clear();
- map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
+ map.Insert( Toolkit::VisualProperty::TYPE, Toolkit::Visual::TEXT );
map.Insert( Toolkit::TextVisual::Property::RENDERING_BACKEND, mRenderingBackend );
map.Insert( Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, GetVerticalAlignment( mController->GetVerticalAlignment() ) );
- map.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, mController->GetTextColor() );
+ map.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, mController->GetDefaultColor() );
map.Insert( Toolkit::TextVisual::Property::ENABLE_MARKUP, mController->IsMarkupProcessorEnabled() );
- map.Insert( Toolkit::TextVisual::Property::ENABLE_AUTO_SCROLL, mController->IsAutoScrollEnabled() );
-
- map.Insert( Toolkit::TextVisual::Property::AUTO_SCROLL_SPEED, mController->GetAutoScrollSpeed() );
-
- map.Insert( Toolkit::TextVisual::Property::AUTO_SCROLL_LOOP_COUNT, mController->GetAutoScrollLoopCount() );
-
- map.Insert( Toolkit::TextVisual::Property::AUTO_SCROLL_GAP, mController->GetAutoScrollWrapGap() );
-
map.Insert( Toolkit::TextVisual::Property::LINE_SPACING, mController->GetDefaultLineSpacing() );
GetUnderlineProperties( mController, value, Text::EffectStyle::DEFAULT );
map.Insert( Toolkit::TextVisual::Property::BATCHING_ENABLED, false ); // TODO
}
-void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
+TextVisual::TextVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache ),
+ mController( Text::Controller::New() ),
+ mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
+ mHasBeenStaged( false )
{
- mSelf = actor;
+}
+
+TextVisual::~TextVisual()
+{
+}
+void TextVisual::DoSetProperties( const Property::Map& propertyMap )
+{
for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index )
{
const KeyValuePair& keyValue = propertyMap.GetKeyValue( index );
{
case Property::Key::INDEX:
{
- if( Toolkit::Visual::Property::TYPE != keyValue.first.indexKey ) // Toolkit::Visual::Property::TYPE is not a TextVisual's property.
+ if( Toolkit::VisualProperty::TYPE != keyValue.first.indexKey ) // Toolkit::VisualProperty::TYPE is not a TextVisual's property.
{
DoSetProperty( keyValue.first.indexKey, keyValue.second );
}
}
}
- // Retrieve the layout engine to set whether to elide the text and set the cursor's width.
- Text::LayoutEngine& engine = mController->GetLayoutEngine();
-
// Elide the text if it exceeds the boundaries.
- engine.SetTextEllipsisEnabled( true );
+ mController->SetTextElideEnabled( true );
+
+ // Retrieve the layout engine to set the cursor's width.
+ Text::Layout::Engine& engine = mController->GetLayoutEngine();
// Sets 0 as cursor's width.
engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
}
case Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT:
{
- LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
- if( Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( propertyValue.Get< std::string >().c_str(),
- HORIZONTAL_ALIGNMENT_STRING_TABLE,
- HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
- alignment ) )
+ Toolkit::Text::Layout::HorizontalAlignment alignment( Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN );
+ if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( propertyValue.Get< std::string >().c_str(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
+ alignment ) )
{
mController->SetHorizontalAlignment( alignment );
}
}
case Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT:
{
- LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
- if( Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( propertyValue.Get< std::string >().c_str(),
- VERTICAL_ALIGNMENT_STRING_TABLE,
- VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
- alignment ) )
+ Toolkit::Text::Layout::VerticalAlignment alignment( Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM );
+ if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( propertyValue.Get< std::string >().c_str(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
+ alignment ) )
{
mController->SetVerticalAlignment( alignment );
}
}
case Toolkit::TextVisual::Property::TEXT_COLOR:
{
- const Vector4 textColor = propertyValue.Get< Vector4 >();
- if( mController->GetTextColor() != textColor )
+ const Vector4& textColor = propertyValue.Get< Vector4 >();
+ if( mController->GetDefaultColor() != textColor )
{
- mController->SetTextColor( textColor );
+ mController->SetDefaultColor( textColor );
mRenderer.Reset();
}
break;
}
case Toolkit::TextVisual::Property::ENABLE_AUTO_SCROLL:
{
- const bool enableAutoScroll = propertyValue.Get<bool>();
-
- // If request to auto scroll is the same as current state then do nothing.
- if( enableAutoScroll != mController->IsAutoScrollEnabled() )
- {
- // If request is disable (false) and auto scrolling is enabled then need to stop it
- if( !enableAutoScroll )
- {
- StopTextAutoScrolling(); // Causes the current animation to finish playing.
- }
- // If request is enable (true) then start autoscroll as not already running
- else
- {
- mController->GetLayoutEngine().SetTextEllipsisEnabled( false );
- mController->SetAutoScrollEnabled( enableAutoScroll );
- mController->RequestRelayout();
- }
- }
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_SPEED:
{
- mController->SetAutoscrollSpeed( propertyValue.Get<int>() );
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_LOOP_COUNT:
{
- const int loopCount = propertyValue.Get<int>();
- if( loopCount > 0 )
- {
- mController->SetAutoScrollLoopCount( loopCount );
- }
- else
- {
- StopTextAutoScrolling(); // Causes the current animation to finish playing.
- }
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_GAP:
{
- mController->SetAutoScrollWrapGap( propertyValue.Get<float>() );
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::LINE_SPACING:
case Toolkit::TextVisual::Property::UNDERLINE:
{
// TODO : This switch can be removed when the deprecated SHADOW_OFFSET and SHADOW_COLOR properties are finally removed.
- // Only the code for the STRING case should be kept.
+ // Only the code for the MAP case should be kept.
switch( propertyValue.GetType() )
{
case Property::VECTOR4:
{
- const Vector4 color = propertyValue.Get<Vector4>();
+ const Vector4& color = propertyValue.Get<Vector4>();
if( mController->GetUnderlineColor() != color )
{
mController->SetUnderlineColor( color );
}
break;
}
- case Property::STRING:
+ case Property::MAP:
{
const bool update = SetUnderlineProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
if( update )
case Toolkit::TextVisual::Property::SHADOW:
{
// TODO : This switch can be removed when the deprecated SHADOW_OFFSET and SHADOW_COLOR properties are finally removed.
- // Only the code for the STRING case should be kept.
+ // Only the code for the MAP case should be kept.
switch( propertyValue.GetType() )
{
case Property::VECTOR2:
{
- const Vector2 shadowOffset = propertyValue.Get<Vector2>();
+ const Vector2& shadowOffset = propertyValue.Get<Vector2>();
if( mController->GetShadowOffset() != shadowOffset )
{
mController->SetShadowOffset( shadowOffset );
}
case Property::VECTOR4:
{
- const Vector4 shadowColor = propertyValue.Get<Vector4>();
+ const Vector4& shadowColor = propertyValue.Get<Vector4>();
if( mController->GetShadowColor() != shadowColor )
{
mController->SetShadowColor( shadowColor );
}
break;
}
- case Property::STRING:
+ case Property::MAP:
{
const bool update = SetShadowProperties( mController, propertyValue, Text::EffectStyle::DEFAULT );
if( update )
}
case Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT:
{
- const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( mController->GetHorizontalAlignment(),
- HORIZONTAL_ALIGNMENT_STRING_TABLE,
- HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
+ const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( mController->GetHorizontalAlignment(),
+ HORIZONTAL_ALIGNMENT_STRING_TABLE,
+ HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
if( name )
{
value = std::string( name );
}
case Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT:
{
- const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( mController->GetVerticalAlignment(),
- VERTICAL_ALIGNMENT_STRING_TABLE,
- VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+ const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( mController->GetVerticalAlignment(),
+ VERTICAL_ALIGNMENT_STRING_TABLE,
+ VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
if( name )
{
value = std::string( name );
}
case Toolkit::TextVisual::Property::TEXT_COLOR:
{
- value = mController->GetTextColor();
+ value = mController->GetDefaultColor();
break;
}
case Toolkit::TextVisual::Property::ENABLE_MARKUP:
}
case Toolkit::TextVisual::Property::ENABLE_AUTO_SCROLL:
{
- value = mController->IsAutoScrollEnabled();
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_SPEED:
{
- value = mController->GetAutoScrollSpeed();
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_LOOP_COUNT:
{
- value = mController->GetAutoScrollLoopCount();
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::AUTO_SCROLL_GAP:
{
- value = mController->GetAutoScrollWrapGap();
+ // nothing to do.
break;
}
case Toolkit::TextVisual::Property::LINE_SPACING:
return value;
}
+void TextVisual::OnSetTransform()
+{
+ Vector2 visualSize = mImpl->mTransform.GetVisualSize( mImpl->mControlSize );
+
+ // Note, the direction should come from the layout of the parent control
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+
+ const Text::Controller::UpdateTextType updateTextType = mController->Relayout( visualSize );
+
+ if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
+ !mRenderer )
+ {
+ if( !mRenderer )
+ {
+ mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
+ }
+ RenderText();
+ }
+}
+
void TextVisual::RenderText()
{
+ Actor self = mSelf.GetHandle();
+ if( !self )
+ {
+ // Nothing to do if the handle is not initialized.
+ return;
+ }
+
Actor renderableActor;
if( mRenderer )
if( renderableActor )
{
- const Vector2& scrollOffset = mController->GetScrollPosition();
+ const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
renderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
- mSelf.Add( renderableActor );
+ self.Add( renderableActor );
}
mRenderableActor = renderableActor;
-
- if( mController->IsAutoScrollEnabled() )
- {
- SetUpAutoScrolling();
- }
- }
-}
-
-void TextVisual::StopTextAutoScrolling()
-{
- if( mTextScroller )
- {
- mTextScroller->StopScrolling();
- }
-}
-
-void TextVisual::SetUpAutoScrolling()
-{
- const Text::ScrollerData* const data = mController->GetAutoScrollData();
-
- if( NULL != data )
- {
- if( !mTextScroller )
- {
- // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
- mTextScroller = Text::TextScroller::New( *mController );
- }
-
- mTextScroller->StartScrolling( mRenderableActor,
- *data );
-
- mSelf.Add( mTextScroller->GetScrollingText() );
- mSelf.Add( mTextScroller->GetSourceCamera() );
}
}