1 #ifndef DALI_INTERNAL_TOOLTIP_H
2 #define DALI_INTERNAL_TOOLTIP_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/adaptor-framework/timer.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/object/property-array.h>
25 #include <dali/public-api/object/property-map.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/object/weak-handle.h>
28 #include <dali/public-api/signals/connection-tracker.h>
32 #include <dali-toolkit/devel-api/controls/popup/popup.h>
33 #include <dali-toolkit/devel-api/controls/tooltip/tooltip-properties.h>
34 #include <dali-toolkit/public-api/controls/control.h>
43 typedef IntrusivePtr<Tooltip> TooltipPtr;
46 * @brief Handles all the required tooltip related functionality for a control.
48 * Connects to the Hovered signal of the control.
49 * Styling is achieved by merging the properties set so that new properties override previous but existing properties are still kept.
51 class Tooltip : public RefObject, public ConnectionTracker
55 * @brief Creates an instance of the Tooltip class.
56 * @param[in] control The control the tooltip should be shown on.
58 static TooltipPtr New(Toolkit::Control control);
61 * @brief Sets the properties of the Tooltip.
62 * @details The properties are merged over the currently stored properties.
63 * If a Property::STRING is passed, then the style set previously by the stylesheet is used.
64 * If a Property::MAP then the map is merged.
65 * If a Property::ARRAY of Visuals then all are displayed in one row.
66 * @param[in] value This can either be a Property::STRING, Property::MAP or Property::ARRAY.
68 void SetProperties(const Property::Value& value);
71 * @brief Creates a property map of the tooltip properties.
72 * @param[out] map Filled with all the properties of the tooltip.
73 * @note map should be empty.
75 void CreatePropertyMap(Property::Map& map) const;
79 * @brief Private constructor.
81 Tooltip(Toolkit::Control control);
84 * @brief Private destructor.
88 Tooltip(const Tooltip&); ///< Undefined
89 Tooltip& operator=(const Tooltip&); ///< ///< Undefined
92 * @brief Sets the content of the tooltip.
93 * @details Connects to the signals if there is real content to display.
94 * @param[in] control Is used to connect to this control's signals.
95 * @param[in] value The content property value.
97 void SetContent(Toolkit::Control& control, const Property::Value& value);
100 * @brief Sets the background properties of the tooltip.
101 * @param[in] value The background property value.
103 void SetBackground(const Property::Value& value);
106 * @brief Sets the tail properties of the tooltip.
107 * @param[in] value The tail property value.
109 void SetTail(const Property::Value& value);
112 * @brief Method used to connect to the control's Hovered signal.
113 * @param[in] hover The hover event.
115 bool OnHovered(Actor /* actor */, const HoverEvent& hover);
118 * @brief Method used to connect to the internal timer used by Tooltip.
119 * @return Always return false as we're only interested in one timeout.
124 * @brief Used to know when the we're laying out the actor used to display the tooltip.
125 * @details This is required so we can appropriately position it.
126 * @param[in] actor The actor being laid out.
128 void OnRelayout(Actor actor);
132 Toolkit::Popup mPopup; ///< The Popup class is used to display the actual tooltip.
133 Timer mTooltipTimer; ///< Timer used to wait a certain length of time before we display the tooltip.
135 WeakHandle<Toolkit::Control> mControl; ///< A weak handle to the control we are setting the tooltip on.
137 Property::Map mContentTextVisual; ///< If using just one visual, then this is set.
138 Property::Map mTailImages; ///< The different images used by the tail.
139 Property::Array mContentArray; ///< If using an array of visuals, then this is used.
141 Rect<int> mBackgroundBorder; ///< The size of the background border in the order: left, right, bottom, top. @see Toolkit::Tooltip::Border::Property::BORDER
143 Vector2 mLayout; ///< The layout of the content if using an array.
144 Vector2 mHoverPoint; ///< The first point where hover starts.
145 Vector2 mHoverPointOffset; ///< The tooltip is displayed with this offset from hover point if using Toolkit::Tooltip::Position::HOVER_POINT.
147 std::string mBackgroundImage; ///< The path to the background image used for the tooltip.
149 float mMovementThreshold; ///< This is the allowable movement of the hover before the tooltip processing is cancelled.
151 int mWaitTime; ///< Time in milliseconds to wait before we display the tooltip.
153 Toolkit::Tooltip::Position::Type mPositionType; ///< The position of the tooltip.
154 bool mTailVisibility; ///< Whether we are showing a tail or not.
155 bool mDisappearOnMovement; ///< Whether the tooltip is set to disappear on movement or when we go out of the bounds of mControl.
156 bool mSignalsConnected; ///< Whether any signals required for Tooltip functionality have been connected.
159 } // namespace Internal
161 } // namespace Toolkit
165 #endif // DALI_INTERNAL_TOOLTIP_H