1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/atspi-interfaces/hypertext.h>
24 #include <dali/devel-api/atspi-interfaces/text.h>
25 #include <dali/public-api/object/property-map.h>
28 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
29 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
32 #include <dali-toolkit/internal/text/text-control-interface.h>
33 #include <dali-toolkit/internal/text/controller/text-controller.h>
34 #include <dali-toolkit/internal/text/text-scroller-interface.h>
35 #include <dali-toolkit/internal/text/text-scroller.h>
36 #include <dali-toolkit/internal/visuals/text/text-visual.h>
37 #include <dali-toolkit/public-api/controls/control-impl.h>
38 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
47 * @brief A control which renders a short text string.
49 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface, public Text::AnchorControlInterface
53 * @copydoc Dali::Toollkit::TextLabel::New()
54 * @param[in] additionalBehaviour custom behavior flags for this TextLabel. Default is CONTROL_BEHAVIOUR_DEFAULT
56 static Toolkit::TextLabel New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
61 * @brief Called when a property of an object of this type is set.
63 * @param[in] object The object whose property is set.
64 * @param[in] index The property index.
65 * @param[in] value The new property value.
67 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
70 * @brief Called to retrieve a property of an object of this type.
72 * @param[in] object The object whose property is to be retrieved.
73 * @param[in] index The property index.
74 * @return The current value of the property.
76 static Property::Value GetProperty(BaseObject* object, Property::Index index);
79 * @copydoc Dali::Toollkit::TextLabel::AnchorClickedSignal()
81 DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal();
84 * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal()
86 DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal();
89 * Connects a callback function with the object's signals.
90 * @param[in] object The object providing the signal.
91 * @param[in] tracker Used to disconnect the signal.
92 * @param[in] signalName The signal to connect to.
93 * @param[in] functor A newly allocated FunctorDelegate.
94 * @return True if the signal was connected.
95 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
97 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
100 * @brief Gets text controller
102 * @return The text controller
104 Text::ControllerPtr GetTextController();
107 * @brief Get the rendered size of a specific text range.
108 * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
109 * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
111 * @param[in] startIndex start index of the text requested to calculate size for.
112 * @param[in] endIndex end index(included) of the text requested to calculate size for.
113 * @return list of sizes of the reuested text.
115 Vector<Vector2> GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const;
118 * @brief Get the top/left rendered position of a specific text range.
119 * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
120 * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
122 * @param[in] startIndex start index of the text requested to get position to.
123 * @param[in] endIndex end index(included) of the text requested to get position to.
124 * @return list of positions of the requested text.
126 Vector<Vector2> GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const;
128 private: // From Control
130 * @copydoc Control::OnInitialize()
132 void OnInitialize() override;
135 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
137 DevelControl::ControlAccessible* CreateAccessibleObject() override;
140 * @copydoc Control::OnStyleChange()
142 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
145 * @copydoc Control::OnRelayout()
147 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
150 * @copydoc Control::OnTap()
152 void OnTap(const TapGesture& tap) override;
155 * @copydoc Control::GetNaturalSize()
157 Vector3 GetNaturalSize() override;
160 * @copydoc Control::GetHeightForWidth()
162 float GetHeightForWidth(float width) override;
165 * @copydoc Control::OnPropertySet()
167 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
170 * @copydoc Control::OnSceneConnection()
172 void OnSceneConnection(int depth) override;
175 * @copydoc Control::OnSceneDisconnection()
177 void OnSceneDisconnection() override;
179 // From ControlInterface
182 * @copydoc Text::ControlInterface::RequestTextRelayout()
184 void RequestTextRelayout() override;
186 private: // from TextScroller
188 * @copydoc Text::ScrollerInterface::ScrollingFinished()
190 void ScrollingFinished() override;
192 public: // From AnchorControlInterface
194 * @copydoc Text::AnchorControlInterface::AnchorClicked()
196 void AnchorClicked(const std::string& href) override;
198 private: // Implementation
200 * Construct a new TextLabel.
202 * @param[in] additionalBehaviour additional behaviour flags for this TextLabel
204 TextLabel(ControlBehaviour additionalBehaviour);
207 * A reference counted object may only be deleted by calling Unreference()
209 virtual ~TextLabel();
212 // Undefined copy constructor and assignment operators
213 TextLabel(const TextLabel&);
214 TextLabel& operator=(const TextLabel& rhs);
217 * @brief Set up Autoscrolling
219 void SetUpAutoScrolling();
222 * Creates a text-scroller if one has not been created.
223 * @return The text scroller.
225 Text::TextScrollerPtr GetTextScroller()
229 mTextScroller = Text::TextScroller::New(*this);
231 return mTextScroller;
235 * @brief Callback function for when the layout is changed.
236 * @param[in] actor The actor whose layoutDirection is changed.
237 * @param[in] type The layoutDirection.
239 void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
242 * @brief Emits TextFitChanged signal.
244 void EmitTextFitChangedSignal();
245 void OnAccessibilityStatusChanged();
248 Text::ControllerPtr mController;
249 Text::TextScrollerPtr mTextScroller;
251 Toolkit::Visual::Base mVisual;
253 std::vector<Toolkit::TextAnchor> mAnchorActors;
256 Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal;
257 Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
259 int mRenderingBackend;
260 bool mTextUpdateNeeded : 1;
261 bool mLastAutoScrollEnabled : 1;
265 * @brief This structure is to connect TextLabel with Accessible functions.
267 class TextLabelAccessible : public TextControlAccessible
270 using TextControlAccessible::TextControlAccessible;
273 * @copydoc Dali::Accessibility::Text::GetNameRaw()
275 std::string GetNameRaw() const override;
278 * @copydoc Dali::Accessibility::Text::GetNamePropertyIndex()
280 Property::Index GetNamePropertyIndex() override;
284 * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextAnchors()
286 const std::vector<Toolkit::TextAnchor>& GetTextAnchors() const override;
289 * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextController()
291 Toolkit::Text::ControllerPtr GetTextController() const override;
295 } // namespace Internal
297 // Helpers for public-api forwarding methods
299 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
301 DALI_ASSERT_ALWAYS(textLabel);
303 Dali::RefObject& handle = textLabel.GetImplementation();
305 return static_cast<Toolkit::Internal::TextLabel&>(handle);
308 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
310 DALI_ASSERT_ALWAYS(textLabel);
312 const Dali::RefObject& handle = textLabel.GetImplementation();
314 return static_cast<const Toolkit::Internal::TextLabel&>(handle);
317 } // namespace Toolkit
321 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H