1 #ifndef DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_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-toolkit/public-api/controls/control-impl.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
25 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
26 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
40 typedef Dali::IntrusivePtr< ProgressBar > ProgressBarPtr;
43 * @copydoc Toolkit::ProgressBar
45 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 );
61 * Set the value of the ProgressBar
63 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
65 void SetProgressValue( float value );
68 * Get the value of the ProgressBar
70 * @return The current value of the ProgressBar
72 float GetProgressValue() const;
75 * Set the secondary progress value of the ProgressBar
77 * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
79 void SetSecondaryProgressValue( float value );
82 * Get the secondary progress value of the ProgressBar
84 * @return The current secondary progress value of the ProgressBar
86 float GetSecondaryProgressValue() const;
89 * Set the indeterminate state of the ProgressBar
91 * @param[in] value The value to set.
93 void SetIndeterminate( bool value );
96 * Get the indeterminate state value of the ProgressBar
98 * @return The current determined state of the ProgressBar
100 bool GetIndeterminate() const;
103 * Set the indeterminate visual transition of the ProgressBar
105 * @param[in] Transition data map to set.
107 void SetIndeterminateVisualTransition( Property::Map transtion );
110 * Get the indeterminate visual transition data map of the ProgressBar
112 * @return The current indeterminate visual transition data map of the ProgressBar
114 Property::Map GetIndeterminateVisualTransition() const;
117 * Play the indeterminate visual transition
119 void PlayIndeterminateVisualTransition();
125 * @copydoc toolkit::progressbar::valuechangedsignal()
127 Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
131 * Connects a callback function with the object's signals.
132 * @param[in] object The object providing the signal.
133 * @param[in] tracker Used to disconnect the signal.
134 * @param[in] signalName The signal to connect to.
135 * @param[in] functor A newly allocated FunctorDelegate.
136 * @return True if the signal was connected.
137 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
139 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
140 FunctorDelegate* functor );
145 * Called when a property of an object of this type is set.
146 * @param[in] object The object whose property is set.
147 * @param[in] index The property index.
148 * @param[in] value The new property value.
150 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
153 * Called to retrieve a property of an object of this type.
154 * @param[in] object The object whose property is to be retrieved.
155 * @param[in] index The property index.
156 * @return The current value of the property.
158 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
163 * Construct a new ProgressBar.
168 * A reference counted object may only be deleted by calling Unreference()
170 virtual ~ProgressBar();
173 * @copydoc CustomActorImpl::OnRelayout()
175 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
178 * @copydoc CustomActorImpl::GetNaturalSize()
180 Vector3 GetNaturalSize() override;
185 * Domain is a from/to pair
195 Domain( Vector2 fromVal, Vector2 toVal )
196 : from( fromVal ), to( toVal )
204 * @copydoc Toolkit::Control::OnInitialize()
206 void OnInitialize() override;
209 * Get the range of the valid values the ProgressBar handle can move between
211 * @param[in] currentSize The current size of the ProgressBar
212 * @return The range as a domain pair
214 Domain CalcDomain( const Vector2& currentSize );
217 * Set indeterminate visual transition animation
219 void SetIndeterminateVisualTransition( Toolkit::TransitionData transtion );
222 * Convert value to transition data
224 Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value );
227 * Update progress bar label when progress value is changed
229 void CreateVisualsForComponent( Property::Index index, const Property::Value& value, const int visualDepth );
232 * Update progress bar label when progress value is changed
234 bool GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const;
237 * Apply progress value to visual
239 void ApplyProgressToVisual( float progress, Property::Index index, int depth );
242 * Apply progress value to visual transform
244 void ApplyProgressToVisualTransform( float progress, Vector2 trackSize, Property::Index index );
247 * Check if we should start animating
249 void OnSceneConnection( int depth ) override;
254 ProgressBar( const ProgressBar& );
257 ProgressBar& operator=( const ProgressBar& rhs );
261 Domain mDomain; ///< Current domain of the handle
263 Animation mIndeterminateVisualAni; ///< Animation for indetrminate visual. Transition animation.
264 Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
266 Toolkit::TransitionData mIndeterminateVisualTransition; ///< Transition data map for mIndeterminateVisualAni
267 float mProgressValue; ///< Current value of ProgressBar
268 float mSecondaryProgressValue; ///< Current loading value of ProgressBar
269 bool mIndeterminate; ///< Whether the progress state is determined or not
270 Property::Map mTrackVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
271 Property::Map mProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
272 Property::Map mSecondaryProgressVisualMap; ///< To backup visual properties when switching determinate/indeterminate.
275 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
276 public virtual Dali::Accessibility::Value
278 using Control::Impl::AccessibleImpl::AccessibleImpl;
279 double GetMinimum() override;
280 double GetCurrent() override;
281 double GetMaximum() override;
282 bool SetCurrent( double ) override;
283 double GetMinimumIncrement() override;
287 } // namespace Internal
289 // Helpers for public-api forwarding methods
291 inline Toolkit::Internal::ProgressBar& GetImpl( Toolkit::ProgressBar& pub )
293 DALI_ASSERT_ALWAYS( pub );
295 Dali::RefObject& handle = pub.GetImplementation();
297 return static_cast< Toolkit::Internal::ProgressBar& >( handle );
300 inline const Toolkit::Internal::ProgressBar& GetImpl( const Toolkit::ProgressBar& pub )
302 DALI_ASSERT_ALWAYS( pub );
304 const Dali::RefObject& handle = pub.GetImplementation();
306 return static_cast< const Toolkit::Internal::ProgressBar& >( handle );
309 } // namespace Toolkit
313 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H