1 #ifndef DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_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/devel-api/atspi-interfaces/value.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
27 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
28 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
31 #include <dali/public-api/animation/animation.h>
41 typedef Dali::IntrusivePtr<ProgressBar> ProgressBarPtr;
44 * @copydoc Toolkit::ProgressBar
46 class ProgressBar : public Control
50 * Create a new ProgressBar with predefined style.
51 * @param[in] progressBarStyle A style value that determines the shape of the progress bar.
52 * @return A public handle to the newly allocated ProgressBar.
54 static Dali::Toolkit::ProgressBar New(DevelProgressBar::Style progressBarStyle = DevelProgressBar::Style::LINEAR);
60 * Set the value of the ProgressBar
62 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
64 void SetProgressValue(float value);
67 * Get the value of the ProgressBar
69 * @return The current value of the ProgressBar
71 float GetProgressValue() const;
74 * Set the secondary progress value of the ProgressBar
76 * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
78 void SetSecondaryProgressValue(float value);
81 * Get the secondary progress value of the ProgressBar
83 * @return The current secondary progress value of the ProgressBar
85 float GetSecondaryProgressValue() const;
88 * Set the indeterminate state of the ProgressBar
90 * @param[in] value The value to set.
92 void SetIndeterminate(bool value);
95 * Get the indeterminate state value of the ProgressBar
97 * @return The current determined state of the ProgressBar
99 bool GetIndeterminate() const;
102 * Set the indeterminate visual transition of the ProgressBar
104 * @param[in] Transition data map to set.
106 void SetIndeterminateVisualTransition(Property::Map transtion);
109 * Get the indeterminate visual transition data map of the ProgressBar
111 * @return The current indeterminate visual transition data map of the ProgressBar
113 Property::Map GetIndeterminateVisualTransition() const;
116 * Play the indeterminate visual transition
118 void PlayIndeterminateVisualTransition();
124 * @copydoc toolkit::progressbar::valuechangedsignal()
126 Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
129 * Connects a callback function with the object's signals.
130 * @param[in] object The object providing the signal.
131 * @param[in] tracker Used to disconnect the signal.
132 * @param[in] signalName The signal to connect to.
133 * @param[in] functor A newly allocated FunctorDelegate.
134 * @return True if the signal was connected.
135 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
137 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
142 * Called when a property of an object of this type is set.
143 * @param[in] object The object whose property is set.
144 * @param[in] index The property index.
145 * @param[in] value The new property value.
147 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
150 * Called to retrieve a property of an object of this type.
151 * @param[in] object The object whose property is to be retrieved.
152 * @param[in] index The property index.
153 * @return The current value of the property.
155 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
159 * Construct a new ProgressBar.
164 * A reference counted object may only be deleted by calling Unreference()
166 virtual ~ProgressBar();
169 * @copydoc CustomActorImpl::OnRelayout()
171 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
174 * @copydoc CustomActorImpl::GetNaturalSize()
176 Vector3 GetNaturalSize() override;
180 * Domain is a from/to pair
190 Domain(Vector2 fromVal, Vector2 toVal)
199 * @copydoc Toolkit::Control::OnInitialize()
201 void OnInitialize() override;
204 * Get the range of the valid values the ProgressBar handle can move between
206 * @param[in] currentSize The current size of the ProgressBar
207 * @return The range as a domain pair
209 Domain CalcDomain(const Vector2& currentSize);
212 * Set indeterminate visual transition animation
214 void SetIndeterminateVisualTransition(Toolkit::TransitionData transtion);
217 * Convert value to transition data
219 Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value);
222 * Update progress bar label when progress value is changed
224 void CreateVisualsForComponent(Property::Index index, const Property::Value& value, const int visualDepth);
227 * Update progress bar label when progress value is changed
229 bool GetPropertyMapForVisual(Property::Index visualIndex, Property::Map& retreivedMap) const;
232 * Apply progress value to visual
234 void ApplyProgressToVisual(float progress, Property::Index index, int depth);
237 * Apply progress value to visual transform
239 void ApplyProgressToVisualTransform(float progress, Vector2 trackSize, Property::Index index);
242 * Check if we should start animating
244 void OnSceneConnection(int depth) override;
248 ProgressBar(const ProgressBar&);
251 ProgressBar& operator=(const ProgressBar& rhs);
254 Domain mDomain; ///< Current domain of the handle
256 Animation mIndeterminateVisualAni; ///< Animation for indetrminate visual. Transition animation.
257 Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
259 Toolkit::TransitionData mIndeterminateVisualTransition; ///< Transition data map for mIndeterminateVisualAni
260 float mProgressValue; ///< Current value of ProgressBar
261 float mSecondaryProgressValue; ///< Current loading value of ProgressBar
262 bool mIndeterminate; ///< Whether the progress state is determined or not
263 Property::Map mTrackVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
264 Property::Map mProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
265 Property::Map mSecondaryProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
268 struct AccessibleImpl : public DevelControl::ControlAccessible,
269 public virtual Dali::Accessibility::Value
271 using DevelControl::ControlAccessible::ControlAccessible;
273 double GetMinimum() const override;
274 double GetCurrent() const override;
275 double GetMaximum() const override;
276 bool SetCurrent(double) override;
277 double GetMinimumIncrement() const override;
281 } // namespace Internal
283 // Helpers for public-api forwarding methods
285 inline Toolkit::Internal::ProgressBar& GetImpl(Toolkit::ProgressBar& pub)
287 DALI_ASSERT_ALWAYS(pub);
289 Dali::RefObject& handle = pub.GetImplementation();
291 return static_cast<Toolkit::Internal::ProgressBar&>(handle);
294 inline const Toolkit::Internal::ProgressBar& GetImpl(const Toolkit::ProgressBar& pub)
296 DALI_ASSERT_ALWAYS(pub);
298 const Dali::RefObject& handle = pub.GetImplementation();
300 return static_cast<const Toolkit::Internal::ProgressBar&>(handle);
303 } // namespace Toolkit
307 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H