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/atspi-interfaces/hypertext.h>
23 #include <dali/devel-api/atspi-interfaces/text.h>
24 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
29 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
30 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/controller/text-controller.h>
33 #include <dali-toolkit/internal/text/text-scroller-interface.h>
34 #include <dali-toolkit/internal/text/text-scroller.h>
35 #include <dali-toolkit/internal/visuals/text/text-visual.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
46 * @brief A control which renders a short text string.
48 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface, public Text::AnchorControlInterface
52 * @copydoc Dali::Toollkit::TextLabel::New()
53 * @param[in] additionalBehaviour custom behavior flags for this TextLabel. Default is CONTROL_BEHAVIOUR_DEFAULT
55 static Toolkit::TextLabel New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
60 * @brief Called when a property of an object of this type is set.
62 * @param[in] object The object whose property is set.
63 * @param[in] index The property index.
64 * @param[in] value The new property value.
66 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
69 * @brief Called to retrieve a property of an object of this type.
71 * @param[in] object The object whose property is to be retrieved.
72 * @param[in] index The property index.
73 * @return The current value of the property.
75 static Property::Value GetProperty(BaseObject* object, Property::Index index);
78 * @copydoc Dali::Toollkit::TextLabel::AnchorClickedSignal()
80 DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal();
83 * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal()
85 DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal();
88 * Connects a callback function with the object's signals.
89 * @param[in] object The object providing the signal.
90 * @param[in] tracker Used to disconnect the signal.
91 * @param[in] signalName The signal to connect to.
92 * @param[in] functor A newly allocated FunctorDelegate.
93 * @return True if the signal was connected.
94 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
96 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
99 * @brief Gets text controller
101 * @return The text controller
103 Text::ControllerPtr GetTextController();
106 * @brief Get the rendered size of a specific text range.
107 * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
108 * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
110 * @param[in] startIndex start index of the text requested to calculate size for.
111 * @param[in] endIndex end index(included) of the text requested to calculate size for.
112 * @return list of sizes of the reuested text.
114 Vector<Vector2> GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const;
117 * @brief Get the top/left rendered position of a specific text range.
118 * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
119 * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
121 * @param[in] startIndex start index of the text requested to get position to.
122 * @param[in] endIndex end index(included) of the text requested to get position to.
123 * @return list of positions of the requested text.
125 Vector<Vector2> GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const;
127 private: // From Control
129 * @copydoc Control::OnInitialize()
131 void OnInitialize() override;
134 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
136 DevelControl::ControlAccessible* CreateAccessibleObject() override;
139 * @copydoc Control::OnStyleChange()
141 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
144 * @copydoc Control::OnRelayout()
146 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
149 * @copydoc Control::OnTap()
151 void OnTap(const TapGesture& tap) override;
154 * @copydoc Control::GetNaturalSize()
156 Vector3 GetNaturalSize() override;
159 * @copydoc Control::GetHeightForWidth()
161 float GetHeightForWidth(float width) override;
164 * @copydoc Control::OnPropertySet()
166 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
168 // From ControlInterface
171 * @copydoc Text::ControlInterface::RequestTextRelayout()
173 void RequestTextRelayout() override;
175 private: // from TextScroller
177 * @copydoc Text::ScrollerInterface::ScrollingFinished()
179 void ScrollingFinished() override;
181 public: // From AnchorControlInterface
183 * @copydoc Text::AnchorControlInterface::AnchorClicked()
185 void AnchorClicked(const std::string& href) override;
187 private: // Implementation
189 * Construct a new TextLabel.
191 * @param[in] additionalBehaviour additional behaviour flags for this TextLabel
193 TextLabel(ControlBehaviour additionalBehaviour);
196 * A reference counted object may only be deleted by calling Unreference()
198 virtual ~TextLabel();
201 // Undefined copy constructor and assignment operators
202 TextLabel(const TextLabel&);
203 TextLabel& operator=(const TextLabel& rhs);
206 * @brief Set up Autoscrolling
208 void SetUpAutoScrolling();
211 * Creates a text-scroller if one has not been created.
212 * @return The text scroller.
214 Text::TextScrollerPtr GetTextScroller()
218 mTextScroller = Text::TextScroller::New(*this);
220 return mTextScroller;
224 * @brief Callback function for when the layout is changed.
225 * @param[in] actor The actor whose layoutDirection is changed.
226 * @param[in] type The layoutDirection.
228 void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
231 * @brief Emits TextFitChanged signal.
233 void EmitTextFitChangedSignal();
234 void OnAccessibilityStatusChanged();
237 Text::ControllerPtr mController;
238 Text::TextScrollerPtr mTextScroller;
240 Toolkit::Visual::Base mVisual;
242 std::vector<Toolkit::TextAnchor> mAnchorActors;
245 Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal;
246 Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
248 int mRenderingBackend;
249 bool mTextUpdateNeeded : 1;
253 * @brief This structure is to connect TextLabel with Accessible functions.
255 class TextLabelAccessible : public TextControlAccessible
258 using TextControlAccessible::TextControlAccessible;
261 * @copydoc Dali::Accessibility::Text::GetNameRaw()
263 std::string GetNameRaw() const override;
266 * @copydoc Dali::Accessibility::Text::GetNamePropertyIndex()
268 Property::Index GetNamePropertyIndex() override;
272 * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextAnchors()
274 const std::vector<Toolkit::TextAnchor>& GetTextAnchors() const override;
277 * @copydoc Dali::Toolkit::Internal::TextControlAccessible::GetTextController()
279 Toolkit::Text::ControllerPtr GetTextController() const override;
283 } // namespace Internal
285 // Helpers for public-api forwarding methods
287 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
289 DALI_ASSERT_ALWAYS(textLabel);
291 Dali::RefObject& handle = textLabel.GetImplementation();
293 return static_cast<Toolkit::Internal::TextLabel&>(handle);
296 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
298 DALI_ASSERT_ALWAYS(textLabel);
300 const Dali::RefObject& handle = textLabel.GetImplementation();
302 return static_cast<const Toolkit::Internal::TextLabel&>(handle);
305 } // namespace Toolkit
309 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H