1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
5 * Copyright (c) 2017 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/base-object.h>
25 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
26 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
39 typedef IntrusivePtr< TextVisual > TextVisualPtr;
42 * The visual which renders text
44 * The following properties are optional:
46 * | %Property Name | Type |
47 * |---------------------|---------|
48 * | renderingBackend | INTEGER |
50 * | fontFamily | STRING |
51 * | fontStyle | STRING |
52 * | pointSize | FLOAT |
53 * | multiLine | BOOLEAN |
54 * | horizontalAlignment | STRING |
55 * | verticalAlignment | STRING |
56 * | textColor | VECTOR4 |
57 * | enableMarkup | BOOLEAN |
58 * | enableAutoScroll | BOOLEAN |
59 * | autoScrollSpeed | INTEGER |
60 * | autoScrollLoopCount | INTEGER |
61 * | autoScrollGap | INTEGER |
62 * | lineSpacing | FLOAT |
63 * | underline | STRING |
65 * | outline | STRING |
68 class TextVisual : public Visual::Base
73 * @brief Create a new text visual.
75 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
76 * @param[in] properties A Property::Map containing settings for this visual
77 * @return A smart-pointer to the newly allocated visual.
79 static TextVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
82 * @brief Converts all strings keys in property map to index keys. Property Map can then be merged correctly.
83 * @param[in,out] propertyMap containing string keys or a mix of strings and indexes. Will be changed to index keys.
85 static void ConvertStringKeysToIndexKeys( Property::Map& propertyMap );
88 * @brief Retrieve the text's controller.
89 * @param[in] visual The text visual.
90 * @return The text controller
92 static Text::ControllerPtr GetController( Toolkit::Visual::Base visual )
94 return GetVisualObject( visual ).mController;
98 * @brief Set the index of the animatable text color property.
99 * @param[in] visual The text visual.
100 * @param[in] animatablePropertyIndex The index of the animatable property
102 static void SetAnimatableTextColorProperty( Toolkit::Visual::Base visual, Property::Index animatablePropertyIndex )
104 GetVisualObject( visual ).mAnimatableTextColorPropertyIndex = animatablePropertyIndex;
108 * @brief Set the flag to trigger the textures to be initialized and renderer to be added to the control.
109 * @param[in] visual The text visual.
111 static void EnableRendererUpdate( Toolkit::Visual::Base visual )
113 GetVisualObject( visual ).mRendererUpdateNeeded = true;
116 public: // from Visual::Base
119 * @copydoc Visual::Base::GetHeightForWidth()
121 virtual float GetHeightForWidth( float width );
124 * @copydoc Visual::Base::GetNaturalSize()
126 virtual void GetNaturalSize( Vector2& naturalSize );
129 * @copydoc Visual::Base::CreatePropertyMap()
131 virtual void DoCreatePropertyMap( Property::Map& map ) const;
134 * @copydoc Visual::Base::CreateInstancePropertyMap
136 virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
141 * @brief Constructor.
143 * @param[in] factoryCache The VisualFactoryCache object
145 TextVisual( VisualFactoryCache& factoryCache );
148 * @brief A reference counted object may only be deleted by calling Unreference().
150 virtual ~TextVisual();
155 * @copydoc Visual::Base::DoSetProperties()
157 virtual void DoSetProperties( const Property::Map& propertyMap );
160 * @copydoc Visual::Base::DoSetOnStage()
162 virtual void DoSetOnStage( Actor& actor );
165 * @copydoc Visual::Base::DoSetOffStage()
167 virtual void DoSetOffStage( Actor& actor );
170 * @copydoc Visual::Base::OnSetTransform
172 virtual void OnSetTransform();
176 * @brief Set the individual property to the given value.
178 * @param[in] index The index key used to reference this value within the initial property map.
180 * @param[in] propertyValue The value to set.
182 void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
185 * @brief Updates the text's renderer.
187 void UpdateRenderer();
190 * @brief Removes the texture set from the renderer.
192 void RemoveTextureSet();
195 * @brief Retrieve the text's controller.
196 * @param[in] visual The text visual.
197 * @return The text controller
199 static TextVisual& GetVisualObject( Toolkit::Visual::Base visual )
201 return static_cast<TextVisual&>( visual.GetBaseObject() );
205 Text::ControllerPtr mController; ///< The text's controller.
206 Text::TypesetterPtr mTypesetter; ///< The text's typesetter.
207 WeakHandle<Actor> mControl; ///< The control where the renderer is added.
208 Property::Index mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control.
209 bool mRendererUpdateNeeded:1; ///< The flag to indicate whether the renderer needs to be updated.
212 } // namespace Internal
214 } // namespace Toolkit
218 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */