1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
5 * Copyright (c) 2020 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/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-label.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/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
46 * @brief A control which renders a short text string.
48 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
53 * @copydoc Dali::Toollkit::TextLabel::New()
55 static Toolkit::TextLabel New();
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 );
77 Text::ControllerPtr getController();
79 private: // From Control
82 * @copydoc Control::OnInitialize()
84 void OnInitialize() override;
87 * @copydoc Control::OnStyleChange()
89 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
92 * @copydoc Control::OnRelayout()
94 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
97 * @copydoc Control::GetNaturalSize()
99 Vector3 GetNaturalSize() override;
102 * @copydoc Control::GetHeightForWidth()
104 float GetHeightForWidth( float width ) override;
107 * @copydoc Control::OnPropertySet()
109 void OnPropertySet( Property::Index index, const Property::Value& propertyValue ) override ;
111 // From ControlInterface
114 * @copydoc Text::ControlInterface::RequestTextRelayout()
116 void RequestTextRelayout() override;
118 private: // from TextScroller
121 * @copydoc Text::ScrollerInterface::ScrollingFinished()
123 void ScrollingFinished() override;
125 private: // Implementation
128 * Construct a new TextLabel.
133 * A reference counted object may only be deleted by calling Unreference()
135 virtual ~TextLabel();
139 // Undefined copy constructor and assignment operators
140 TextLabel(const TextLabel&);
141 TextLabel& operator=(const TextLabel& rhs);
144 * @brief Set up Autoscrolling
146 void SetUpAutoScrolling();
149 * Creates a text-scroller if one has not been created.
150 * @return The text scroller.
152 Text::TextScrollerPtr GetTextScroller()
156 mTextScroller = Text::TextScroller::New( *this );
158 return mTextScroller;
163 Text::ControllerPtr mController;
164 Text::TextScrollerPtr mTextScroller;
166 Toolkit::Visual::Base mVisual;
168 int mRenderingBackend;
169 bool mTextUpdateNeeded:1;
172 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
173 public virtual Dali::Accessibility::Text
175 using Control::Impl::AccessibleImpl::AccessibleImpl;
177 std::string GetText( size_t startOffset, size_t endOffset ) override;
178 size_t GetCharacterCount() override;
179 size_t GetCaretOffset() override;
180 bool SetCaretOffset(size_t offset) override;
181 Dali::Accessibility::Range
182 GetTextAtOffset( size_t offset,
183 Dali::Accessibility::TextBoundary boundary ) override;
184 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
185 bool RemoveSelection( size_t selectionNum ) override;
186 bool SetSelection( size_t selectionNum, size_t startOffset,
187 size_t endOffset ) override;
188 std::string GetNameRaw() override;
189 Property::Index GetNamePropertyIndex() override;
193 } // namespace Internal
195 // Helpers for public-api forwarding methods
197 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
199 DALI_ASSERT_ALWAYS(textLabel);
201 Dali::RefObject& handle = textLabel.GetImplementation();
203 return static_cast<Toolkit::Internal::TextLabel&>(handle);
206 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
208 DALI_ASSERT_ALWAYS(textLabel);
210 const Dali::RefObject& handle = textLabel.GetImplementation();
212 return static_cast<const Toolkit::Internal::TextLabel&>(handle);
215 } // namespace Toolkit
219 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H