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-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
23 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
24 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
27 #include <dali/public-api/animation/animation.h>
37 typedef Dali::IntrusivePtr<ProgressBar> ProgressBarPtr;
40 * @copydoc Toolkit::ProgressBar
42 class ProgressBar : public Control
46 * Create a new ProgressBar with predefined style.
47 * @param[in] progressBarStyle A style value that determines the shape of the progress bar.
48 * @return A public handle to the newly allocated ProgressBar.
50 static Dali::Toolkit::ProgressBar New(DevelProgressBar::Style progressBarStyle = DevelProgressBar::Style::LINEAR);
56 * Set the value of the ProgressBar
58 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
60 void SetProgressValue(float value);
63 * Get the value of the ProgressBar
65 * @return The current value of the ProgressBar
67 float GetProgressValue() const;
70 * Set the secondary progress value of the ProgressBar
72 * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
74 void SetSecondaryProgressValue(float value);
77 * Get the secondary progress value of the ProgressBar
79 * @return The current secondary progress value of the ProgressBar
81 float GetSecondaryProgressValue() const;
84 * Set the indeterminate state of the ProgressBar
86 * @param[in] value The value to set.
88 void SetIndeterminate(bool value);
91 * Get the indeterminate state value of the ProgressBar
93 * @return The current determined state of the ProgressBar
95 bool GetIndeterminate() const;
98 * Set the indeterminate visual transition of the ProgressBar
100 * @param[in] Transition data map to set.
102 void SetIndeterminateVisualTransition(Property::Map transtion);
105 * Get the indeterminate visual transition data map of the ProgressBar
107 * @return The current indeterminate visual transition data map of the ProgressBar
109 Property::Map GetIndeterminateVisualTransition() const;
112 * Play the indeterminate visual transition
114 void PlayIndeterminateVisualTransition();
120 * @copydoc toolkit::progressbar::valuechangedsignal()
122 Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
125 * Connects a callback function with the object's signals.
126 * @param[in] object The object providing the signal.
127 * @param[in] tracker Used to disconnect the signal.
128 * @param[in] signalName The signal to connect to.
129 * @param[in] functor A newly allocated FunctorDelegate.
130 * @return True if the signal was connected.
131 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
133 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
138 * Called when a property of an object of this type is set.
139 * @param[in] object The object whose property is set.
140 * @param[in] index The property index.
141 * @param[in] value The new property value.
143 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
146 * Called to retrieve a property of an object of this type.
147 * @param[in] object The object whose property is to be retrieved.
148 * @param[in] index The property index.
149 * @return The current value of the property.
151 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
155 * Construct a new ProgressBar.
160 * A reference counted object may only be deleted by calling Unreference()
162 virtual ~ProgressBar();
165 * @copydoc CustomActorImpl::OnRelayout()
167 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
170 * @copydoc CustomActorImpl::GetNaturalSize()
172 Vector3 GetNaturalSize() override;
176 * Domain is a from/to pair
186 Domain(Vector2 fromVal, Vector2 toVal)
195 * @copydoc Toolkit::Control::OnInitialize()
197 void OnInitialize() override;
200 * Get the range of the valid values the ProgressBar handle can move between
202 * @param[in] currentSize The current size of the ProgressBar
203 * @return The range as a domain pair
205 Domain CalcDomain(const Vector2& currentSize);
208 * Set indeterminate visual transition animation
210 void SetIndeterminateVisualTransition(Toolkit::TransitionData transtion);
213 * Convert value to transition data
215 Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value);
218 * Update progress bar label when progress value is changed
220 void CreateVisualsForComponent(Property::Index index, const Property::Value& value, const int visualDepth);
223 * Update progress bar label when progress value is changed
225 bool GetPropertyMapForVisual(Property::Index visualIndex, Property::Map& retreivedMap) const;
228 * Apply progress value to visual
230 void ApplyProgressToVisual(float progress, Property::Index index, int depth);
233 * Apply progress value to visual transform
235 void ApplyProgressToVisualTransform(float progress, Vector2 trackSize, Property::Index index);
238 * Check if we should start animating
240 void OnSceneConnection(int depth) override;
244 ProgressBar(const ProgressBar&);
247 ProgressBar& operator=(const ProgressBar& rhs);
250 Domain mDomain; ///< Current domain of the handle
252 Animation mIndeterminateVisualAni; ///< Animation for indetrminate visual. Transition animation.
253 Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
255 Toolkit::TransitionData mIndeterminateVisualTransition; ///< Transition data map for mIndeterminateVisualAni
256 float mProgressValue; ///< Current value of ProgressBar
257 float mSecondaryProgressValue; ///< Current loading value of ProgressBar
258 bool mIndeterminate; ///< Whether the progress state is determined or not
259 Property::Map mTrackVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
260 Property::Map mProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
261 Property::Map mSecondaryProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
264 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
265 public virtual Dali::Accessibility::Value
267 using Control::Impl::AccessibleImpl::AccessibleImpl;
268 double GetMinimum() override;
269 double GetCurrent() override;
270 double GetMaximum() override;
271 bool SetCurrent(double) override;
272 double GetMinimumIncrement() override;
276 } // namespace Internal
278 // Helpers for public-api forwarding methods
280 inline Toolkit::Internal::ProgressBar& GetImpl(Toolkit::ProgressBar& pub)
282 DALI_ASSERT_ALWAYS(pub);
284 Dali::RefObject& handle = pub.GetImplementation();
286 return static_cast<Toolkit::Internal::ProgressBar&>(handle);
289 inline const Toolkit::Internal::ProgressBar& GetImpl(const Toolkit::ProgressBar& pub)
291 DALI_ASSERT_ALWAYS(pub);
293 const Dali::RefObject& handle = pub.GetImplementation();
295 return static_cast<const Toolkit::Internal::ProgressBar&>(handle);
298 } // namespace Toolkit
302 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H