1 #ifndef __DALI_TOOLKIT_INTERNAL_SLIDER_H__
2 #define __DALI_TOOLKIT_INTERNAL_SLIDER_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/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/object/property-array.h>
24 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/slider/slider.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
30 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
45 typedef Dali::IntrusivePtr< Slider > SliderPtr;
48 * @copydoc Toolkit::Slider
50 class Slider : public Control
54 typedef Property::Array MarkList;
57 * Create a new Slider.
59 * @return A public handle to the newly allocated Slider.
61 static Dali::Toolkit::Slider New();
68 * Set marks from a list
70 * @param[in] marks The list of marks to set
72 void SetMarks( const MarkList& marks );
75 * Get the list of marks
77 * @return The marks list
79 const MarkList& GetMarks() const;
82 * Set if should snap to marks or not
84 * @param[in] snap Flag to snap to marks or not
86 void SetSnapToMarks( bool snap );
89 * Return if snap to marks is set or not
91 * @return If snap to marks is set
93 bool GetSnapToMarks() const;
96 * Set the value of the slider
98 * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
100 void SetValue( float value );
103 * Get the value of the slider
105 * @return The current value of the slider
107 float GetValue() const;
112 * @param[in] region The hit region
114 void SetHitRegion( const Vector2& region );
119 * @return The hit region
121 const Vector2& GetHitRegion() const;
124 * Set the track region
126 * @param[in] region The track region
128 void SetTrackRegion( const Vector2& region );
131 * Get the track region
133 * @return The track region
135 const Vector2& GetTrackRegion() const;
138 * @brief Set the disabled color.
140 * @param[in] color The disabled color.
142 void SetDisabledColor( const Vector4& color );
145 * @brief Get disabled color
147 * @return The disabled color
149 Vector4 GetDisabledColor() const;
152 * Set the value precision to be used for numbers in the slider
154 * @param[in] precision The number of decimal places to use for printing numbers
156 void SetValuePrecision( int precision );
159 * Get value precision
161 * @return The value precision
163 int GetValuePrecision() const;
168 * @param[in] showPopup The show popup flag
170 void SetShowPopup( bool showPopup );
173 * Get show value in popup
175 * @return The show value flag
177 bool GetShowPopup() const;
180 * Set show value on handle
182 * @param[in] showValue The show value flag
184 void SetShowValue( bool showValue );
187 * Get show value on handle
189 * @return The show value flag
191 bool GetShowValue() const;
196 * param[in] enabled Set the enabled flag
198 void SetEnabled( bool enabled );
201 * Return if enabled or not
205 bool IsEnabled() const;
208 * @brief Set the mark tolerance
210 * The tolerance is the percentage of the slider width for which snapping to
213 * @param[in] tolerance The percentage of width for which to snap
215 void SetMarkTolerance( float tolerance );
218 * Return the mark tolerance
220 * @return The tolerance set for snapping to marks
222 float GetMarkTolerance() const;
228 * @copydoc Toolkit::Slider::ValueChangedSignal()
230 Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
233 * copydoc Toolkit::Slider::SlidingFinishedSignal()
235 Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
238 * @copydoc Toolkit::Slider::MarkReachedSignal()
240 Toolkit::Slider::MarkReachedSignalType& MarkReachedSignal();
243 * Connects a callback function with the object's signals.
244 * @param[in] object The object providing the signal.
245 * @param[in] tracker Used to disconnect the signal.
246 * @param[in] signalName The signal to connect to.
247 * @param[in] functor A newly allocated FunctorDelegate.
248 * @return True if the signal was connected.
249 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
251 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
252 FunctorDelegate* functor );
257 * Called when a property of an object of this type is set.
258 * @param[in] object The object whose property is set.
259 * @param[in] index The property index.
260 * @param[in] value The new property value.
262 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
265 * Called to retrieve a property of an object of this type.
266 * @param[in] object The object whose property is to be retrieved.
267 * @param[in] index The property index.
268 * @return The current value of the property.
270 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
275 * Construct a new Slider.
280 * A reference counted object may only be deleted by calling Unreference()
285 * @copydoc CustomActorImpl::OnRelayout
287 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
293 * Domain is a from/to pair
303 Domain( Vector2 fromVal, Vector2 toVal )
304 : from( fromVal ), to( toVal )
323 * @copydoc Toolkit::Control::OnInitialize()
325 virtual void OnInitialize();
330 * @param[in] actor The actor the event is raised for
331 * @param[in] touch The touch info
332 * @return If touch is handled or not
334 bool OnTouch( Actor actor, const TouchData& touch );
339 * @param[in] actor The actor the event is raised for
340 * @param[in] gesture The pan event info
342 void OnPan( Actor actor, const PanGesture& gesture );
345 * Map a position onto a domain and return the result as a percentage
347 * @param[in] point The point to map onto the domain
348 * @return The result as a percentage [0..1]
350 float MapPercentage( const Vector2& point );
353 * Map a value in the range to a percentage
355 * @param[in] point The value in range [lowerBound..upperBound]
356 * @return The result as a percentage [0..1]
358 float MapValuePercentage( float value );
361 * Convert a point in local hit space into domain space
363 * @param[in] x The x position to convert
364 * @return The x position in domain space
366 float HitSpaceToDomain( float x );
369 * Map a percentage onto the slider's bounds
371 * @param[in] percent The current value of slider in percent
372 * @param[in] lowerBound The lower bound to map onto
373 * @param[in] upperBound The upper bound to map onto
374 * @return The value of percent mapped from lowerBound to upperBound
376 float MapBounds( float percent, float lowerBound, float upperBound );
379 * Get the range of the valid values the slider handle can move between
381 * @param[in] currentSize The current size of the slider
382 * @return The range as a domain pair
384 Domain CalcDomain( const Vector2& currentSize );
387 * Create the hit region
389 * @return The hit region actor
391 Actor CreateHitRegion();
394 * Create the track for the slider
396 * @return The track actor
398 Toolkit::ImageView CreateTrack();
401 * Create the progress track for the slider
403 * @return The track actor
405 Toolkit::ImageView CreateProgress();
408 * Create the handle for the slider
410 * @return The created image handle
412 Toolkit::ImageView CreateHandle();
415 * Create the popup arrow
417 * @return The created image handle
419 Toolkit::ImageView CreatePopupArrow();
424 * @return The created image handle
426 Toolkit::ImageView CreatePopup();
429 * Create the textview for the popup
431 * @return The textview created for the popup
433 Toolkit::TextLabel CreatePopupText();
436 * Create the value display for the slider
438 * @return The created root actor of the display
440 Actor CreateValueDisplay();
443 * Set the skin based on the current state
448 * Create all the children
450 void CreateChildren();
463 * Display the popup for a set duration with the given value
465 * @param[in] value The value to display in the popup
467 void DisplayPopup( float value );
470 * If there are marks present, filter the incoming percent based on snapping to any nearby marks
472 * @param[in] value The incoming value on the slider to filter
473 * @return The filtered percentage snapped to any nearby marks
475 float MarkFilter( float value );
478 * If there are marks present, snap the incoming percent to the nearest mark
480 * @param[in] value The incoming value on the slider to snap
481 * @return The filtered percentage snapped to the nearest mark
483 float SnapToMark( float value );
486 * Search for if a mark has been reached
488 * @param[in] value The value to search against
489 * @param[out] outIndex The index of the mark if found
490 * @return If a mark has been found to match percent
492 bool MarkReached( float value, int& outIndex );
495 * Handler for when the value view needs to be hidden
497 * @return If handled or not
499 bool HideValueView();
502 * Set value choosing whether to fire signals or not
504 * @paramp[in] value The value to set
505 * @param[in] raiseSignals Configure signals to be raised or not.
507 void DisplayValue( float value, bool raiseSignals );
510 * Create the image for the track
512 * @param[in] filename The track image
514 void SetTrackVisual( const std::string& filename );
517 * @brief Set the track visual from an Dali::Property::Map
519 * @param[in] map The Dali::Property::Map to use for to display
521 void SetTrackVisual( Dali::Property::Map map );
524 * @brief Return the track image.
526 * @return The track image.
528 std::string GetTrackVisual();
531 * Create the image for the progress bar
533 * @param[in] filename The progress bar image
535 void SetProgressVisual( const std::string& filename );
538 * @brief Set the progress visual from an Dali::Property::Map
540 * @param[in] map The Dali::Property::Map to use for to display
542 void SetProgressVisual( Dali::Property::Map map );
545 * @brief Return the progress bar image.
547 * @return The progress bar image if it exists.
549 std::string GetProgressVisual();
552 * @brief Create the image for the popup
554 * @param[in] filename The popup image
556 void CreatePopupImage( const std::string& filename );
559 * @brief Set the popup image
561 * @param[in] filename The popup image to set
563 void SetPopupVisual( const std::string& filename );
566 * @brief Set the popup from an Dali::Property::Map
568 * @param[in] map The Dali::Property::Map to use for to display
570 void SetPopupVisual( Dali::Property::Map map );
573 * @brief Return the popup image.
575 * @return The popup image if it exists.
577 std::string GetPopupVisual();
580 * @brief Set the popup arrow image
582 * @param[in] filename The popup arrow image to set
584 void SetPopupArrowVisual( const std::string& filename );
587 * @brief Set the popup arrow from an Dali::Property::Map
589 * @param[in] map The Dali::Property::Map to use for to display
591 void SetPopupArrowVisual( Dali::Property::Map map );
594 * @brief Return the popup arrow image.
596 * @return The popup arrow image if it exists.
598 std::string GetPopupArrowVisual();
601 * Create the image for the popup arrow
603 * @param[in] filename The popup arrow image to load and set
605 void CreatePopupArrowImage( const std::string& filename );
608 * Set the size of the progress bar region
610 * @param[in] region The size of the region to set
612 void ResizeProgressRegion( const Vector2& region );
615 * Create the image for the handle
617 * @param[in] filename The handle image
619 void SetHandleVisual( const std::string& filename );
622 * @brief Set the handle visual from an Dali::Property::Map
624 * @param[in] map The Dali::Property::Map to use for to display
626 void SetHandleVisual( Property::Map map );
629 * @brief Return the handle image.
631 * @return The handle image if it exists.
633 std::string GetHandleVisual();
636 * Reset the size of the handle
638 * @param[in] size The size of the handle to set
640 void ResizeHandleSize( const Vector2& size );
643 * Create and display the value on the handle
645 void CreateHandleValueDisplay();
648 * Remove and destroy the handle value display
650 void DestroyHandleValueDisplay();
653 * Set the size of the handle
655 * @param[in] size The handle size
657 void SetHandleSize( const Vector2& size );
660 * Get the size of the handle
662 * @return The handle size
664 const Vector2& GetHandleSize() const;
667 * Set the lower bound of the slider's value
669 * @param[in] bound The value to set for the lower bound
671 void SetLowerBound( float bound );
674 * Get the lower bound of the slider's value
676 * @return The lower bound value
678 float GetLowerBound() const;
681 * Set the upper bound of the slider's value
683 * @param[in] bound The value to set for the upper bound
685 void SetUpperBound( float bound );
688 * Get the upper bound of the slider's value
690 * @return The upper bound value
692 float GetUpperBound() const;
697 Slider( const Slider& );
700 Slider& operator=( const Slider& rhs );
704 Domain mDomain; ///< Current domain of the handle
706 Actor mHitArea; ///< The input handler
707 Actor mValueDisplay; ///< Display of the value
708 Toolkit::ImageView mTrack; ///< Track image
709 Toolkit::ImageView mHandle; ///< Slider handle
710 Toolkit::ImageView mProgress; ///< Progress bar
711 Toolkit::ImageView mPopup; ///< Popup backing
712 Toolkit::ImageView mPopupArrow; ///< Popup arrow backing
714 Toolkit::TextLabel mValueTextLabel; //< The text value in popup
715 Toolkit::TextLabel mHandleValueTextLabel; ///< The text value on handle
716 Vector2 mHandleLastTouchPoint; ///< The last touch point for the handle
717 Timer mValueTimer; ///< Timer used to hide value view
719 Toolkit::Slider::ValueChangedSignalType mValueChangedSignal; ///< Signal emitted when the value is changed
720 Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
721 Toolkit::Slider::MarkReachedSignalType mMarkReachedSignal; ///< Signal emitted when a mark is reached
723 SliderState mState; ///< The state of the slider
725 PanGestureDetector mPanDetector; ///< Hit region pan detector
727 MarkList mMarks; ///< List of discreet marks
729 std::string mPopupVisual; ///< Image for popup image
730 std::string mPopupArrowVisual; ///< Image for popup arrow image
731 std::string mTrackVisual; ///< Image for track image
732 std::string mHandleVisual; ///< Image for handle image
733 std::string mProgressVisual; ///< Image for progress bar image
735 Property::Map mPopupMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
736 Property::Map mTrackMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
737 Property::Map mHandleMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
738 Property::Map mProgressMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
739 Property::Map mPopupArrowMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
741 Vector4 mDisabledColor; ///< The color to tint the slider when disabled
743 Vector2 mHitRegion; ///< Size of hit region
744 Vector2 mTrackRegion; ///< Size of track region
745 Vector2 mHandleSize; ///< Size of the handle
747 float mLowerBound; ///< Lower bound on value
748 float mUpperBound; ///< Upper bound on value
749 float mValue; ///< Current value of slider
751 float mMarkTolerance; ///< Tolerance in percentage of slider width for which to snap to marks
753 int mValuePrecision; ///< The precision to use for outputting the value
755 bool mShowPopup : 1, ///< Show the popup or not
756 mShowValue : 1, ///< Whether to display the value number or not on the handle
757 mSnapToMarks : 1; ///< Turn on or off snapping to marks
760 } // namespace Internal
762 // Helpers for public-api forwarding methods
764 inline Toolkit::Internal::Slider& GetImpl( Toolkit::Slider& pub )
766 DALI_ASSERT_ALWAYS( pub );
768 Dali::RefObject& handle = pub.GetImplementation();
770 return static_cast< Toolkit::Internal::Slider& >( handle );
773 inline const Toolkit::Internal::Slider& GetImpl( const Toolkit::Slider& pub )
775 DALI_ASSERT_ALWAYS( pub );
777 const Dali::RefObject& handle = pub.GetImplementation();
779 return static_cast< const Toolkit::Internal::Slider& >( handle );
782 } // namespace Toolkit
786 #endif // __DALI_TOOLKIT_INTERNAL_SLIDER_H__