// EXTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/text/layouts/layout-engine.h>
-#include <dali-toolkit/public-api/text/rendering/text-backend.h>
+#include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/text/rendering/text-backend.h>
using Dali::Toolkit::Text::LayoutEngine;
using Dali::Toolkit::Text::Backend;
namespace Toolkit
{
-const Property::Index TextLabel::PROPERTY_RENDERING_BACKEND( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX );
-const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 1 );
-const Property::Index TextLabel::PROPERTY_MULTI_LINE( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX + 2 );
-
namespace Internal
{
return Toolkit::TextLabel::New();
}
-TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create );
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
+
+DALI_PROPERTY_REGISTRATION( TextLabel, "rendering-backend", INTEGER, RENDERING_BACKEND )
+DALI_PROPERTY_REGISTRATION( TextLabel, "text", STRING, TEXT )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-family", STRING, FONT_FAMILY )
+DALI_PROPERTY_REGISTRATION( TextLabel, "font-style", STRING, FONT_STYLE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "point-size", FLOAT, POINT_SIZE )
+DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line", BOOLEAN, MULTI_LINE )
-PropertyRegistration property1( mType, "rendering-backend", Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND, Property::INTEGER, &TextLabel::SetProperty, &TextLabel::GetProperty );
-PropertyRegistration property2( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
-PropertyRegistration property3( mType, "multi-line", Toolkit::TextLabel::PROPERTY_MULTI_LINE, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
+DALI_TYPE_REGISTRATION_END()
} // namespace
TextLabel& impl( GetImpl( label ) );
switch( index )
{
- case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND:
+ case Toolkit::TextLabel::Property::RENDERING_BACKEND:
{
- unsigned int backend = value.Get< int >();
+ int backend = value.Get< int >();
if( impl.mRenderingBackend != backend )
{
- impl.mRenderingBackend = static_cast< unsigned int >( backend );
+ impl.mRenderingBackend = backend;
impl.mRenderer.Reset();
+ impl.RequestTextRelayout();
}
break;
}
- case Toolkit::TextLabel::PROPERTY_TEXT:
+ case Toolkit::TextLabel::Property::TEXT:
{
if( impl.mController )
{
impl.mController->SetText( value.Get< std::string >() );
+ impl.RequestTextRelayout();
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::FONT_FAMILY:
+ {
+ if( impl.mController )
+ {
+ std::string fontFamily = value.Get< std::string >();
+
+ if( impl.mController->GetDefaultFontFamily() != fontFamily )
+ {
+ impl.mController->SetDefaultFontFamily( fontFamily );
+ impl.RequestTextRelayout();
+ }
}
break;
}
- case Toolkit::TextLabel::PROPERTY_MULTI_LINE:
+ case Toolkit::TextLabel::Property::FONT_STYLE:
{
if( impl.mController )
{
+ std::string fontStyle = value.Get< std::string >();
+
+ if( impl.mController->GetDefaultFontStyle() != fontStyle )
+ {
+ impl.mController->SetDefaultFontStyle( fontStyle );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::POINT_SIZE:
+ {
+ if( impl.mController )
+ {
+ float pointSize = value.Get< float >();
+
+ if( impl.mController->GetDefaultPointSize() != pointSize /*TODO - epsilon*/ )
+ {
+ impl.mController->SetDefaultPointSize( pointSize );
+ impl.RequestTextRelayout();
+ }
+ }
+ break;
+ }
+ case Toolkit::TextLabel::Property::MULTI_LINE:
+ {
+ if( impl.mController )
+ {
+ LayoutEngine& engine = impl.mController->GetLayoutEngine();
LayoutEngine::Layout layout = value.Get< bool >() ? LayoutEngine::MULTI_LINE_BOX : LayoutEngine::SINGLE_LINE_BOX;
- impl.mController->GetLayoutEngine().SetLayout( layout );
+
+ if( engine.GetLayout() != layout )
+ {
+ impl.mController->GetLayoutEngine().SetLayout( layout );
+ impl.RequestTextRelayout();
+ }
}
break;
}
TextLabel& impl( GetImpl( label ) );
switch( index )
{
- case Toolkit::TextLabel::PROPERTY_RENDERING_BACKEND:
+ case Toolkit::TextLabel::Property::RENDERING_BACKEND:
{
value = impl.mRenderingBackend;
break;
}
-
- case Toolkit::TextLabel::PROPERTY_TEXT:
+ case Toolkit::TextLabel::Property::TEXT:
{
- DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
+ if( impl.mController )
+ {
+ std::string text;
+ impl.mController->GetText( text );
+ value = text;
+ }
break;
}
-
- case Toolkit::TextLabel::PROPERTY_MULTI_LINE:
+ case Toolkit::TextLabel::Property::MULTI_LINE:
{
if( impl.mController )
{
- value = impl.mController->GetLayoutEngine().GetLayout();
+ value = static_cast<bool>( LayoutEngine::MULTI_LINE_BOX == impl.mController->GetLayoutEngine().GetLayout() );
}
break;
}
void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container )
{
- if( mController->Relayout( size ) )
+ if( mController->Relayout( size ) ||
+ !mRenderer )
{
if( !mRenderer )
{
mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
}
+ RenderableActor renderableActor;
if( mRenderer )
{
- Actor renderableActor = mRenderer->Render( mController->GetView() );
+ renderableActor = mRenderer->Render( mController->GetView() );
+ }
+
+ if( renderableActor != mRenderableActor )
+ {
+ UnparentAndReset( mRenderableActor );
if( renderableActor )
{
Self().Add( renderableActor );
}
+
+ mRenderableActor = renderableActor;
}
}
}