From 37cb9a8e7c94ea7153434d6b0b87a6f08bb9191f Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Mon, 1 Nov 2021 14:54:57 +0900 Subject: [PATCH] Fix text constraint issue Not to create new Constraints when the visual is added to the Scene again Change-Id: I19d30064d9f8cd08ca500a5ad2dee17b4b775b5a --- dali-toolkit/internal/visuals/text/text-visual.cpp | 34 +++++++++++++++------- dali-toolkit/internal/visuals/text/text-visual.h | 3 ++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 19ecb5c..ee31d1f 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include // INTERNAL HEADER @@ -291,22 +290,28 @@ void TextVisual::DoSetOnScene(Actor& actor) // Enable the pre-multiplied alpha to improve the text quality EnablePreMultipliedAlpha(true); - const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); - Dali::Property::Index shaderTextColorIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor); - if(mAnimatableTextColorPropertyIndex != Property::INVALID_INDEX) { + const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); + Dali::Property::Index shaderTextColorIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor); + // Create constraint for the animatable text's color Property with uTextColorAnimatable in the renderer. if(shaderTextColorIndex != Property::INVALID_INDEX) { - Constraint colorConstraint = Constraint::New(mImpl->mRenderer, shaderTextColorIndex, TextColorConstraint); - colorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); - colorConstraint.Apply(); + if(!mColorConstraint) + { + mColorConstraint = Constraint::New(mImpl->mRenderer, shaderTextColorIndex, TextColorConstraint); + mColorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); + } + mColorConstraint.Apply(); // Make zero if the alpha value of text color is zero to skip rendering text - Constraint opacityConstraint = Constraint::New(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint); - opacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); - opacityConstraint.Apply(); + if(!mOpacityConstraint) + { + mOpacityConstraint = Constraint::New(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint); + mOpacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); + } + mOpacityConstraint.Apply(); } } @@ -335,6 +340,15 @@ void TextVisual::RemoveRenderer(Actor& actor) void TextVisual::DoSetOffScene(Actor& actor) { + if(mColorConstraint) + { + mColorConstraint.Remove(); + } + if(mOpacityConstraint) + { + mOpacityConstraint.Remove(); + } + RemoveRenderer(actor); // Resets the control handle. diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 7ae5e4e..7304f0f 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -19,6 +19,7 @@ */ // EXTERNAL INCLUDES +#include #include #include @@ -332,6 +333,8 @@ private: Text::ControllerPtr mController; ///< The text's controller. Text::TypesetterPtr mTypesetter; ///< The text's typesetter. WeakHandle mControl; ///< The control where the renderer is added. + Constraint mColorConstraint{}; ///< Color constraint + Constraint mOpacityConstraint{}; ///< Opacity constraint Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control. bool mRendererUpdateNeeded : 1; ///< The flag to indicate whether the renderer needs to be updated. RendererContainer mRendererList; -- 2.7.4