From cf38a1c61a88e9431efa4201833e88703057c40e Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Mon, 22 Aug 2022 07:59:26 +0900 Subject: [PATCH] stop text scrolling when label is disconnected from scene Change-Id: I8909dc858467d85574310ba50c30ffa143b2eb8d Signed-off-by: Bowon Ryu --- .../controls/text-controls/text-label-impl.cpp | 24 ++++++++++++++++-- .../controls/text-controls/text-label-impl.h | 12 +++++++++ dali-toolkit/internal/text/text-scroller.cpp | 29 +++++++++------------- dali-toolkit/internal/text/text-scroller.h | 3 ++- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 2d2368b..8ba54b7 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -359,7 +359,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro { if(impl.mTextScroller) { - impl.mTextScroller->StopScrolling(); + impl.mTextScroller->StopScrolling(false); } } // If request is enable (true) then start autoscroll as not already running @@ -1008,6 +1008,25 @@ void TextLabel::OnPropertySet(Property::Index index, const Property::Value& prop } } +void TextLabel::OnSceneConnection(int depth) +{ + if(mController->IsAutoScrollEnabled() || mLastAutoScrollEnabled) + { + mController->SetAutoScrollEnabled(true); + } + Control::OnSceneConnection(depth); +} + +void TextLabel::OnSceneDisconnection() +{ + if(mTextScroller) + { + mLastAutoScrollEnabled = mController->IsAutoScrollEnabled(); + mTextScroller->StopScrolling(true); + } + Control::OnSceneDisconnection(); +} + void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n"); @@ -1190,7 +1209,8 @@ void TextLabel::OnAccessibilityStatusChanged() TextLabel::TextLabel(ControlBehaviour additionalBehavior) : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehavior)), mRenderingBackend(DEFAULT_RENDERING_BACKEND), - mTextUpdateNeeded(false) + mTextUpdateNeeded(false), + mLastAutoScrollEnabled(false) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index f4dac1d..31167d8 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -19,6 +19,7 @@ */ // EXTERNAL INCLUDES +#include #include #include #include @@ -165,6 +166,16 @@ private: // From Control */ void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override; + /** + * @copydoc Control::OnSceneConnection() + */ + void OnSceneConnection(int depth) override; + + /** + * @copydoc Control::OnSceneDisconnection() + */ + void OnSceneDisconnection() override; + // From ControlInterface /** @@ -247,6 +258,7 @@ private: // Data int mRenderingBackend; bool mTextUpdateNeeded : 1; + bool mLastAutoScrollEnabled : 1; protected: /** diff --git a/dali-toolkit/internal/text/text-scroller.cpp b/dali-toolkit/internal/text/text-scroller.cpp index cec4081..b97e502 100644 --- a/dali-toolkit/internal/text/text-scroller.cpp +++ b/dali-toolkit/internal/text/text-scroller.cpp @@ -142,27 +142,22 @@ void TextScroller::SetStopMode(TextLabel::AutoScrollStopMode::Type stopMode) mStopMode = stopMode; } -void TextScroller::StopScrolling() +void TextScroller::StopScrolling(bool immediate) { if(mScrollAnimation && mScrollAnimation.GetState() == Animation::PLAYING) { - switch(mStopMode) + if(mStopMode == TextLabel::AutoScrollStopMode::IMMEDIATE || immediate) { - case TextLabel::AutoScrollStopMode::IMMEDIATE: - { - mScrollAnimation.Stop(); - mScrollerInterface.ScrollingFinished(); - break; - } - case TextLabel::AutoScrollStopMode::FINISH_LOOP: - { - mScrollAnimation.SetLoopCount(1); // As animation already playing this allows the current animation to finish instead of trying to stop mid-way - break; - } - default: - { - DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Undifined AutoScrollStopMode\n"); - } + mScrollAnimation.Stop(); + mScrollerInterface.ScrollingFinished(); + } + else if(mStopMode == TextLabel::AutoScrollStopMode::FINISH_LOOP) + { + mScrollAnimation.SetLoopCount(1); // As animation already playing this allows the current animation to finish instead of trying to stop mid-way + } + else + { + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Undifined AutoScrollStopMode\n"); } } else diff --git a/dali-toolkit/internal/text/text-scroller.h b/dali-toolkit/internal/text/text-scroller.h index b93c2d2..01816ac 100644 --- a/dali-toolkit/internal/text/text-scroller.h +++ b/dali-toolkit/internal/text/text-scroller.h @@ -125,8 +125,9 @@ public: /** * @brief Stop the auto scrolling. + * @param[in] immediate Stop scrolling immediately. */ - void StopScrolling(); + void StopScrolling(bool immediate); /** * @brief Get the mode of scrolling stop -- 2.7.4