1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
5 * Copyright (c) 2021 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/public-api/object/property-map.h>
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
27 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
28 #include <dali-toolkit/internal/text/text-control-interface.h>
29 #include <dali-toolkit/internal/text/text-controller.h>
30 #include <dali-toolkit/internal/text/text-scroller-interface.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
43 * @brief A control which renders a short text string.
45 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface, public Text::AnchorControlInterface
49 * @copydoc Dali::Toollkit::TextLabel::New()
51 static Toolkit::TextLabel New();
56 * @brief Called when a property of an object of this type is set.
58 * @param[in] object The object whose property is set.
59 * @param[in] index The property index.
60 * @param[in] value The new property value.
62 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
65 * @brief Called to retrieve a property of an object of this type.
67 * @param[in] object The object whose property is to be retrieved.
68 * @param[in] index The property index.
69 * @return The current value of the property.
71 static Property::Value GetProperty(BaseObject* object, Property::Index index);
74 * @copydoc Dali::Toollkit::TextLabel::AnchorClickedSignal()
76 DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal();
79 * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal()
81 DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal();
84 * Connects a callback function with the object's signals.
85 * @param[in] object The object providing the signal.
86 * @param[in] tracker Used to disconnect the signal.
87 * @param[in] signalName The signal to connect to.
88 * @param[in] functor A newly allocated FunctorDelegate.
89 * @return True if the signal was connected.
90 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
92 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
95 * @brief Gets text controller
97 * @return The text controller
99 Text::ControllerPtr GetTextController();
101 private: // From Control
103 * @copydoc Control::OnInitialize()
105 void OnInitialize() override;
108 * @copydoc Control::OnStyleChange()
110 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
113 * @copydoc Control::OnRelayout()
115 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
118 * @copydoc Control::OnTap()
120 void OnTap(const TapGesture& tap) override;
123 * @copydoc Control::GetNaturalSize()
125 Vector3 GetNaturalSize() override;
128 * @copydoc Control::GetHeightForWidth()
130 float GetHeightForWidth(float width) override;
133 * @copydoc Control::OnPropertySet()
135 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
137 // From ControlInterface
140 * @copydoc Text::ControlInterface::RequestTextRelayout()
142 void RequestTextRelayout() override;
144 private: // from TextScroller
146 * @copydoc Text::ScrollerInterface::ScrollingFinished()
148 void ScrollingFinished() override;
150 public: // From AnchorControlInterface
152 * @copydoc Text::AnchorControlInterface::AnchorClicked()
154 void AnchorClicked(const std::string& href) override;
156 private: // Implementation
158 * Construct a new TextLabel.
163 * A reference counted object may only be deleted by calling Unreference()
165 virtual ~TextLabel();
168 // Undefined copy constructor and assignment operators
169 TextLabel(const TextLabel&);
170 TextLabel& operator=(const TextLabel& rhs);
173 * @brief Set up Autoscrolling
175 void SetUpAutoScrolling();
178 * Creates a text-scroller if one has not been created.
179 * @return The text scroller.
181 Text::TextScrollerPtr GetTextScroller()
185 mTextScroller = Text::TextScroller::New(*this);
187 return mTextScroller;
191 * @brief Callback function for when the layout is changed.
192 * @param[in] actor The actor whose layoutDirection is changed.
193 * @param[in] type The layoutDirection.
195 void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
198 * @brief Emits TextFitChanged signal.
200 void EmitTextFitChangedSignal();
201 void OnAccessibilityStatusChanged();
204 Text::ControllerPtr mController;
205 Text::TextScrollerPtr mTextScroller;
207 Toolkit::Visual::Base mVisual;
209 std::vector<Toolkit::TextAnchor> mAnchorActors;
212 Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal;
213 Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
215 int mRenderingBackend;
216 bool mTextUpdateNeeded : 1;
220 * @brief This structure is to connect TextLabel with Accessible functions.
222 struct AccessibleImpl : public DevelControl::AccessibleImpl,
223 public virtual Dali::Accessibility::Text,
224 public virtual Dali::Accessibility::Hypertext
226 using DevelControl::AccessibleImpl::AccessibleImpl;
229 * @copydoc Dali::Accessibility::Text::GetText()
231 std::string GetText(size_t startOffset, size_t endOffset) override;
234 * @copydoc Dali::Accessibility::Text::GetCharacterCount()
236 size_t GetCharacterCount() override;
239 * @copydoc Dali::Accessibility::Text::GetCursorOffset()
241 size_t GetCursorOffset() override;
244 * @copydoc Dali::Accessibility::Text::SetCursorOffset()
246 bool SetCursorOffset(size_t offset) override;
249 * @copydoc Dali::Accessibility::Text::GetTextAtOffset()
251 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
254 * @copydoc Dali::Accessibility::Text::GetRangeOfSelection()
256 Accessibility::Range GetRangeOfSelection(size_t selectionIndex) override;
259 * @copydoc Dali::Accessibility::Text::RemoveSelection()
261 bool RemoveSelection(size_t selectionIndex) override;
264 * @copydoc Dali::Accessibility::Text::SetRangeOfSelection()
266 bool SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset) override;
269 * @copydoc Dali::Accessibility::Text::GetNameRaw()
271 std::string GetNameRaw() override;
274 * @copydoc Dali::Accessibility::Text::GetNamePropertyIndex()
276 Property::Index GetNamePropertyIndex() override;
279 * @copydoc Dali::Accessibility::Hypertext::GetLink()
281 Accessibility::Hyperlink* GetLink(int32_t linkIndex) const override;
284 * @copydoc Dali::Accessibility::Hypertext::GetLinkIndex()
286 int32_t GetLinkIndex(int32_t characterOffset) const override;
289 * @copydoc Dali::Accessibility::Hypertext::GetLinkCount()
291 int32_t GetLinkCount() 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