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/control-devel.h>
23 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
28 #include <dali/public-api/animation/animation.h>
38 typedef Dali::IntrusivePtr<ProgressBar> ProgressBarPtr;
41 * @copydoc Toolkit::ProgressBar
43 class ProgressBar : public Control
47 * Create a new ProgressBar with predefined style.
48 * @param[in] progressBarStyle A style value that determines the shape of the progress bar.
49 * @return A public handle to the newly allocated ProgressBar.
51 static Dali::Toolkit::ProgressBar New(DevelProgressBar::Style progressBarStyle = DevelProgressBar::Style::LINEAR);
57 * Set the value of the ProgressBar
59 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
61 void SetProgressValue(float value);
64 * Get the value of the ProgressBar
66 * @return The current value of the ProgressBar
68 float GetProgressValue() const;
71 * Set the secondary progress value of the ProgressBar
73 * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
75 void SetSecondaryProgressValue(float value);
78 * Get the secondary progress value of the ProgressBar
80 * @return The current secondary progress value of the ProgressBar
82 float GetSecondaryProgressValue() const;
85 * Set the indeterminate state of the ProgressBar
87 * @param[in] value The value to set.
89 void SetIndeterminate(bool value);
92 * Get the indeterminate state value of the ProgressBar
94 * @return The current determined state of the ProgressBar
96 bool GetIndeterminate() const;
99 * Set the indeterminate visual transition of the ProgressBar
101 * @param[in] Transition data map to set.
103 void SetIndeterminateVisualTransition(Property::Map transtion);
106 * Get the indeterminate visual transition data map of the ProgressBar
108 * @return The current indeterminate visual transition data map of the ProgressBar
110 Property::Map GetIndeterminateVisualTransition() const;
113 * Play the indeterminate visual transition
115 void PlayIndeterminateVisualTransition();
121 * @copydoc toolkit::progressbar::valuechangedsignal()
123 Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
126 * Connects a callback function with the object's signals.
127 * @param[in] object The object providing the signal.
128 * @param[in] tracker Used to disconnect the signal.
129 * @param[in] signalName The signal to connect to.
130 * @param[in] functor A newly allocated FunctorDelegate.
131 * @return True if the signal was connected.
132 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
134 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
139 * Called when a property of an object of this type is set.
140 * @param[in] object The object whose property is set.
141 * @param[in] index The property index.
142 * @param[in] value The new property value.
144 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
147 * Called to retrieve a property of an object of this type.
148 * @param[in] object The object whose property is to be retrieved.
149 * @param[in] index The property index.
150 * @return The current value of the property.
152 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
156 * Construct a new ProgressBar.
161 * A reference counted object may only be deleted by calling Unreference()
163 virtual ~ProgressBar();
166 * @copydoc CustomActorImpl::OnRelayout()
168 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
171 * @copydoc CustomActorImpl::GetNaturalSize()
173 Vector3 GetNaturalSize() override;
177 * Domain is a from/to pair
187 Domain(Vector2 fromVal, Vector2 toVal)
196 * @copydoc Toolkit::Control::OnInitialize()
198 void OnInitialize() override;
201 * Get the range of the valid values the ProgressBar handle can move between
203 * @param[in] currentSize The current size of the ProgressBar
204 * @return The range as a domain pair
206 Domain CalcDomain(const Vector2& currentSize);
209 * Set indeterminate visual transition animation
211 void SetIndeterminateVisualTransition(Toolkit::TransitionData transtion);
214 * Convert value to transition data
216 Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value);
219 * Update progress bar label when progress value is changed
221 void CreateVisualsForComponent(Property::Index index, const Property::Value& value, const int visualDepth);
224 * Update progress bar label when progress value is changed
226 bool GetPropertyMapForVisual(Property::Index visualIndex, Property::Map& retreivedMap) const;
229 * Apply progress value to visual
231 void ApplyProgressToVisual(float progress, Property::Index index, int depth);
234 * Apply progress value to visual transform
236 void ApplyProgressToVisualTransform(float progress, Vector2 trackSize, Property::Index index);
239 * Check if we should start animating
241 void OnSceneConnection(int depth) override;
245 ProgressBar(const ProgressBar&);
248 ProgressBar& operator=(const ProgressBar& rhs);
251 Domain mDomain; ///< Current domain of the handle
253 Animation mIndeterminateVisualAni; ///< Animation for indetrminate visual. Transition animation.
254 Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
256 Toolkit::TransitionData mIndeterminateVisualTransition; ///< Transition data map for mIndeterminateVisualAni
257 float mProgressValue; ///< Current value of ProgressBar
258 float mSecondaryProgressValue; ///< Current loading value of ProgressBar
259 bool mIndeterminate; ///< Whether the progress state is determined or not
260 Property::Map mTrackVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
261 Property::Map mProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
262 Property::Map mSecondaryProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
265 struct AccessibleImpl : public DevelControl::AccessibleImpl,
266 public virtual Dali::Accessibility::Value
268 using DevelControl::AccessibleImpl::AccessibleImpl;
269 double GetMinimum() override;
270 double GetCurrent() override;
271 double GetMaximum() override;
272 bool SetCurrent(double) override;
273 double GetMinimumIncrement() override;
277 } // namespace Internal
279 // Helpers for public-api forwarding methods
281 inline Toolkit::Internal::ProgressBar& GetImpl(Toolkit::ProgressBar& pub)
283 DALI_ASSERT_ALWAYS(pub);
285 Dali::RefObject& handle = pub.GetImplementation();
287 return static_cast<Toolkit::Internal::ProgressBar&>(handle);
290 inline const Toolkit::Internal::ProgressBar& GetImpl(const Toolkit::ProgressBar& pub)
292 DALI_ASSERT_ALWAYS(pub);
294 const Dali::RefObject& handle = pub.GetImplementation();
296 return static_cast<const Toolkit::Internal::ProgressBar&>(handle);
299 } // namespace Toolkit
303 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H