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-control-interface.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller-interface.h>
30 #include <dali-toolkit/internal/text/text-scroller.h>
31 #include <dali-toolkit/internal/visuals/text/text-visual.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
42 * @brief A control which renders a short text string.
44 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
48 * @copydoc Dali::Toollkit::TextLabel::New()
50 static Toolkit::TextLabel New();
55 * @brief Called when a property of an object of this type is set.
57 * @param[in] object The object whose property is set.
58 * @param[in] index The property index.
59 * @param[in] value The new property value.
61 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
64 * @brief Called to retrieve a property of an object of this type.
66 * @param[in] object The object whose property is to be retrieved.
67 * @param[in] index The property index.
68 * @return The current value of the property.
70 static Property::Value GetProperty(BaseObject* object, Property::Index index);
72 Text::ControllerPtr getController();
74 private: // From Control
76 * @copydoc Control::OnInitialize()
78 void OnInitialize() override;
81 * @copydoc Control::OnStyleChange()
83 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
86 * @copydoc Control::OnRelayout()
88 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
91 * @copydoc Control::GetNaturalSize()
93 Vector3 GetNaturalSize() override;
96 * @copydoc Control::GetHeightForWidth()
98 float GetHeightForWidth(float width) override;
101 * @copydoc Control::OnPropertySet()
103 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
105 // From ControlInterface
108 * @copydoc Text::ControlInterface::RequestTextRelayout()
110 void RequestTextRelayout() override;
112 private: // from TextScroller
114 * @copydoc Text::ScrollerInterface::ScrollingFinished()
116 void ScrollingFinished() override;
118 private: // Implementation
120 * Construct a new TextLabel.
125 * A reference counted object may only be deleted by calling Unreference()
127 virtual ~TextLabel();
130 // Undefined copy constructor and assignment operators
131 TextLabel(const TextLabel&);
132 TextLabel& operator=(const TextLabel& rhs);
135 * @brief Set up Autoscrolling
137 void SetUpAutoScrolling();
140 * Creates a text-scroller if one has not been created.
141 * @return The text scroller.
143 Text::TextScrollerPtr GetTextScroller()
147 mTextScroller = Text::TextScroller::New(*this);
149 return mTextScroller;
153 Text::ControllerPtr mController;
154 Text::TextScrollerPtr mTextScroller;
156 Toolkit::Visual::Base mVisual;
158 int mRenderingBackend;
159 bool mTextUpdateNeeded : 1;
162 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
163 public virtual Dali::Accessibility::Text
165 using Control::Impl::AccessibleImpl::AccessibleImpl;
167 std::string GetText(size_t startOffset, size_t endOffset) override;
168 size_t GetCharacterCount() override;
169 size_t GetCaretOffset() override;
170 bool SetCaretOffset(size_t offset) override;
171 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
172 Accessibility::Range GetSelection(size_t selectionNum) override;
173 bool RemoveSelection(size_t selectionNum) override;
174 bool SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
175 std::string GetNameRaw() override;
176 Property::Index GetNamePropertyIndex() override;
180 } // namespace Internal
182 // Helpers for public-api forwarding methods
184 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
186 DALI_ASSERT_ALWAYS(textLabel);
188 Dali::RefObject& handle = textLabel.GetImplementation();
190 return static_cast<Toolkit::Internal::TextLabel&>(handle);
193 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
195 DALI_ASSERT_ALWAYS(textLabel);
197 const Dali::RefObject& handle = textLabel.GetImplementation();
199 return static_cast<const Toolkit::Internal::TextLabel&>(handle);
202 } // namespace Toolkit
206 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H