From: joogab.yun Date: Mon, 15 Nov 2021 02:21:54 +0000 (+0900) Subject: Add a callback to get textfitted font size. X-Git-Tag: dali_2.1.0~8^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=c2a64c99bfb51070915cdb15559bd3be5d2f9998 Add a callback to get textfitted font size. Change-Id: I1aea1a5d5b03a27c89feb709d4877369c29290bb --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index c9453e1..aa7f5bd 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -82,6 +82,8 @@ const unsigned int EMOJI_FONT_SIZE = 3840u; // 60 * 64 static bool gAnchorClickedCallBackCalled; static bool gAnchorClickedCallBackNotCalled; +static bool gTextFitChangedCallBackCalled; + struct CallbackFunctor { CallbackFunctor(bool* callbackFlag) @@ -108,6 +110,12 @@ static void TestAnchorClickedCallback(TextLabel control, const char* href, unsig } } +static void TestTextFitChangedCallback(TextLabel control) +{ + tet_infoline(" TestTextFitChangedCallback"); + gTextFitChangedCallBackCalled = true; +} + bool DaliTestCheckMaps( const Property::Map& mapGet, const Property::Map& mapSet, const std::vector& indexConversionTable = std::vector() ) { const Property::Map::SizeType size = mapGet.Count(); @@ -1632,6 +1640,13 @@ int UtcDaliToolkitTextlabelTextFit(void) label.SetProperty( Actor::Property::SIZE, size ); label.SetProperty( TextLabel::Property::TEXT, "Hello world" ); + // connect to the text git changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextLabel::TextFitChangedSignal(label).Connect(&TestTextFitChangedCallback); + bool textFitChangedSignal = false; + label.ConnectSignal(testTracker, "textFitChanged", CallbackFunctor(&textFitChangedSignal)); + gTextFitChangedCallBackCalled = false; + // check point size Property::Map textFitMapSet; textFitMapSet["enable"] = true; @@ -1651,6 +1666,9 @@ int UtcDaliToolkitTextlabelTextFit(void) const Vector3 EXPECTED_NATURAL_SIZE( 450.0f, 96.0f, 0.0f ); DALI_TEST_EQUALS( EXPECTED_NATURAL_SIZE, label.GetNaturalSize(), TEST_LOCATION ); + DALI_TEST_CHECK(gTextFitChangedCallBackCalled); + DALI_TEST_CHECK(textFitChangedSignal); + // check pixel size textFitMapSet.Clear(); textFitMapSet["enable"] = true; @@ -2027,4 +2045,4 @@ int UtcDaliToolkitTextlabelEllipsisPositionProperty(void) END_TEST; -} \ No newline at end of file +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp index 0d6cd0b..c117152 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp @@ -30,6 +30,11 @@ AnchorClickedSignalType& AnchorClickedSignal(TextLabel textLabel) return GetImpl(textLabel).AnchorClickedSignal(); } +TextFitChangedSignalType& TextFitChangedSignal(TextLabel textLabel) +{ + return GetImpl(textLabel).TextFitChangedSignal(); +} + } // namespace DevelTextLabel } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index ac0f30c..6bcbdd0 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -176,6 +176,11 @@ enum Type using AnchorClickedSignalType = Signal; /** + * @brief TextFit property changed signal type. + */ +using TextFitChangedSignalType = Signal; + +/** * @brief This signal is emitted when the anchor is clicked. * * A callback of the following type may be connected: @@ -187,6 +192,18 @@ using AnchorClickedSignalType = Signal; */ DALI_TOOLKIT_API AnchorClickedSignalType& AnchorClickedSignal(TextLabel textLabel); +/** + * @brief This signal is emitted when the textfit property is changed. + * + * A callback of the following type may be connected: + * @code + * void YourCallbackName(TextLabel textLabel); + * @endcode + * @param[in] textLabel The instance of TextLabel. + * @return The signal to connect to. + */ +DALI_TOOLKIT_API TextFitChangedSignalType& TextFitChangedSignal(TextLabel textLabel); + } // namespace DevelTextLabel } // namespace Toolkit 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 21e13c8..a98ef9b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -79,6 +79,7 @@ const std::string TEXT_FIT_ENABLE_KEY("enable"); const std::string TEXT_FIT_MIN_SIZE_KEY("minSize"); const std::string TEXT_FIT_MAX_SIZE_KEY("maxSize"); const std::string TEXT_FIT_STEP_SIZE_KEY("stepSize"); +const std::string TEXT_FIT_FONT_SIZE_KEY("fontSize"); const std::string TEXT_FIT_FONT_SIZE_TYPE_KEY("fontSizeType"); #if defined(DEBUG_ENABLED) @@ -143,6 +144,7 @@ DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColo DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3) DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED) DALI_TYPE_REGISTRATION_END() // clang-format on @@ -485,6 +487,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro case Toolkit::DevelTextLabel::Property::TEXT_FIT: { ParseTextFitProperty(impl.mController, value.GetMap()); + impl.mController->SetTextFitChanged(true); break; } case Toolkit::DevelTextLabel::Property::MIN_LINE_SIZE: @@ -729,12 +732,14 @@ Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index const float minSize = impl.mController->GetTextFitMinSize(); const float maxSize = impl.mController->GetTextFitMaxSize(); const float stepSize = impl.mController->GetTextFitStepSize(); + const float pointSize = impl.mController->GetTextFitPointSize(); Property::Map map; map.Insert(TEXT_FIT_ENABLE_KEY, enabled); map.Insert(TEXT_FIT_MIN_SIZE_KEY, minSize); map.Insert(TEXT_FIT_MAX_SIZE_KEY, maxSize); map.Insert(TEXT_FIT_STEP_SIZE_KEY, stepSize); + map.Insert(TEXT_FIT_FONT_SIZE_KEY, pointSize); map.Insert(TEXT_FIT_FONT_SIZE_TYPE_KEY, "pointSize"); value = map; @@ -776,6 +781,14 @@ bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* labelImpl.AnchorClickedSignal().Connect(tracker, functor); } } + else if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_FIT_CHANGED)) + { + if(label) + { + Internal::TextLabel& labelImpl(GetImpl(label)); + labelImpl.TextFitChangedSignal().Connect(tracker, functor); + } + } else { // signalName does not match any signal @@ -790,6 +803,11 @@ DevelTextLabel::AnchorClickedSignalType& TextLabel::AnchorClickedSignal() return mAnchorClickedSignal; } +DevelTextLabel::TextFitChangedSignalType& TextLabel::TextFitChangedSignal() +{ + return mTextFitChangedSignal; +} + void TextLabel::OnInitialize() { Actor self = Self(); @@ -997,6 +1015,12 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container) mTextUpdateNeeded = false; } + + if(mController->IsTextFitChanged()) + { + EmitTextFitChangedSignal(); + mController->SetTextFitChanged(false); + } } void TextLabel::RequestTextRelayout() @@ -1080,6 +1104,12 @@ void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type mController->ChangedLayoutDirection(); } +void TextLabel::EmitTextFitChangedSignal() +{ + Dali::Toolkit::TextLabel handle(GetOwner()); + mTextFitChangedSignal.Emit(handle); +} + TextLabel::TextLabel() : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mRenderingBackend(DEFAULT_RENDERING_BACKEND), 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 01e003b..d345d21 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -76,6 +76,11 @@ public: DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal(); /** + * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal() + */ + DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal(); + + /** * Connects a callback function with the object's signals. * @param[in] object The object providing the signal. * @param[in] tracker Used to disconnect the signal. @@ -189,6 +194,11 @@ private: */ void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type); + /** + * @brief Emits TextFitChanged signal. + */ + void EmitTextFitChangedSignal(); + private: // Data Text::ControllerPtr mController; Text::TextScrollerPtr mTextScroller; @@ -197,6 +207,7 @@ private: // Data // Signals Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal; + Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal; int mRenderingBackend; bool mTextUpdateNeeded : 1; diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 0c6297f..51e0438 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -841,6 +841,7 @@ public: float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. + float mTextFitChanged; ///< Whether the text fit property has changed. float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 bool mIsLayoutDirectionChanged : 1; ///< Whether the layout has changed. diff --git a/dali-toolkit/internal/text/text-controller-relayouter.cpp b/dali-toolkit/internal/text/text-controller-relayouter.cpp index 4c71934..ed0ddc6 100644 --- a/dali-toolkit/internal/text/text-controller-relayouter.cpp +++ b/dali-toolkit/internal/text/text-controller-relayouter.cpp @@ -216,6 +216,7 @@ void Controller::Relayouter::FitPointSizeforLayout(Controller& controller, const float minPointSize = impl.mTextFitMinSize; float maxPointSize = impl.mTextFitMaxSize; float pointInterval = impl.mTextFitStepSize; + float currentFitPointSize = impl.mFontDefaults->mFitPointSize; model->mElideEnabled = false; Vector pointSizeArray; @@ -255,6 +256,10 @@ void Controller::Relayouter::FitPointSizeforLayout(Controller& controller, const } model->mElideEnabled = actualellipsis; + if(currentFitPointSize != pointSizeArray[bestSizeIndex]) + { + impl.mTextFitChanged = true; + } impl.mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex]; impl.mFontDefaults->sizeDefined = true; controller.ClearFontData(); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 6e4d361..832f09a 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -469,6 +469,16 @@ bool Controller::IsTextFitEnabled() const return mImpl->mTextFitEnabled; } +void Controller::SetTextFitChanged(bool changed) +{ + mImpl->mTextFitChanged = changed; +} + +bool Controller::IsTextFitChanged() const +{ + return mImpl->mTextFitChanged; +} + void Controller::SetTextFitMinSize(float minSize, FontSizeType type) { mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize); @@ -509,6 +519,11 @@ Vector2 Controller::GetTextFitContentSize() const return mImpl->mTextFitContentSize; } +float Controller::GetTextFitPointSize() const +{ + return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFitPointSize : 0.0f; +} + void Controller::SetPlaceholderTextElideEnabled(bool enabled) { PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 3240384..149e788 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -482,6 +482,27 @@ public: // Configure the text controller. Vector2 GetTextFitContentSize() const; /** + * @brief Retrieve the fited point size. + * + * @return The fited point size. + */ + float GetTextFitPointSize() const; + + /** + * @brief Sets whether the text fit properties have changed. + * + * @param[in] changed Whether to changed the text fit. + */ + void SetTextFitChanged(bool changed); + + /** + * @brief Whether the text fit properties are changed or not. + * + * @return True if the text fit properties are changed + */ + bool IsTextFitChanged() const; + + /** * @brief Enable or disable the placeholder text elide. * @param enabled Whether to enable the placeholder text elide. */