2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/object/property-array.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <cstring> // for strcmp
33 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
34 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
35 #include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
36 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
42 const char* DEFAULT_INDICATOR_IMAGE_FILE_NAME = "popup_scroll.9.png";
43 const float DEFAULT_SLIDER_DEPTH(1.0f);
44 const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f);
45 const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f);
46 const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame
47 const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
48 const float DEFAULT_INDICATOR_MINIMUM_HEIGHT(0.0f);
49 const float DEFAULT_INDICATOR_START_PADDING(0.0f);
50 const float DEFAULT_INDICATOR_END_PADDING(0.0f);
51 const float DEFAULT_INDICATOR_TRANSIENT_DURATION(1.0f);
54 * Indicator size constraint
55 * Indicator size depends on both indicator's parent size and the scroll content size
57 struct IndicatorSizeConstraint
60 * @param[in] minimumHeight The minimum height for the indicator
61 * @param[in] padding The sum of the padding at the start & end of the indicator
63 IndicatorSizeConstraint(float minimumHeight, float padding)
64 : mMinimumHeight(minimumHeight),
71 * @param[in] current The current indicator size
72 * @param[in] parentSizeProperty The parent size of scroll indicator.
73 * @return The new scroll indicator size.
75 void operator()(Vector3& current, const PropertyInputContainer& inputs)
77 const Vector3& parentSize = inputs[0]->GetVector3();
78 const float contentSize = inputs[1]->GetFloat();
80 // Take into account padding that may exist at the beginning and end of the indicator.
81 const float parentHeightMinusPadding = parentSize.height - mPadding;
83 float height = contentSize > parentHeightMinusPadding ? parentHeightMinusPadding * (parentHeightMinusPadding / contentSize) : parentHeightMinusPadding * ((parentHeightMinusPadding - contentSize * 0.5f) / parentHeightMinusPadding);
85 current.y = std::max(mMinimumHeight, height);
93 * Indicator position constraint
94 * Positions the indicator to reflect the current scroll position within the scroll domain.
96 struct IndicatorPositionConstraint
99 * @param[in] startPadding The padding at the start of the indicator
100 * @param[in] endPadding The padding at the end of the indicator
102 IndicatorPositionConstraint(float startPadding, float endPadding)
103 : mStartPadding(startPadding),
104 mEndPadding(endPadding)
109 * Constraint operator
110 * @param[in,out] current The current indicator position
111 * @param[in] inputs Contains the size of indicator, the size of indicator's parent, and the scroll position of the scrollable container (from 0.0 -> 1.0 in each axis)
112 * @return The new indicator position is returned.
114 void operator()(Vector3& current, const PropertyInputContainer& inputs)
116 const Vector3& indicatorSize = inputs[0]->GetVector3();
117 const Vector3& parentSize = inputs[1]->GetVector3();
118 const float scrollPosition = -inputs[2]->GetFloat();
119 const float minimumScrollPosition = inputs[3]->GetFloat();
120 const float maximumScrollPosition = inputs[4]->GetFloat();
122 // Take into account padding that may exist at the beginning and end of the indicator.
123 const float parentHeightMinusPadding = parentSize.height - (mStartPadding + mEndPadding);
125 float relativePosition = std::max(0.0f, std::min(1.0f, (scrollPosition - minimumScrollPosition) / (maximumScrollPosition - minimumScrollPosition)));
126 current.y = mStartPadding + (parentHeightMinusPadding - indicatorSize.height) * relativePosition;
127 current.z = DEFAULT_SLIDER_DEPTH;
134 } // unnamed namespace
144 using namespace Dali;
148 return Toolkit::ScrollBar::New();
152 // Setup properties, signals and actions using the type-registry.
153 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create );
155 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION )
156 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY )
157 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT )
158 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION )
159 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION )
160 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS )
161 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT )
162 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING )
163 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING )
164 DALI_PROPERTY_REGISTRATION(Toolkit, ScrollBar, "indicatorTransientDuration", FLOAT, INDICATOR_TRANSIENT_DURATION)
166 DALI_SIGNAL_REGISTRATION(Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL )
167 DALI_SIGNAL_REGISTRATION(Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL)
169 DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "ShowIndicator", ACTION_SHOW_INDICATOR )
170 DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "HideIndicator", ACTION_HIDE_INDICATOR )
171 DALI_ACTION_REGISTRATION(Toolkit, ScrollBar, "ShowTransientIndicator", ACTION_SHOW_TRANSIENT_INDICATOR)
173 DALI_TYPE_REGISTRATION_END()
176 const char* SCROLL_DIRECTION_NAME[] = {"VERTICAL", "HORIZONTAL"};
177 const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"VARIABLE", "FIXED"};
181 ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
182 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
183 mIndicatorShowAlpha(1.0f),
184 mDirection(direction),
185 mScrollableObject(WeakHandle<Handle>()),
186 mPropertyScrollPosition(Property::INVALID_INDEX),
187 mPropertyMinScrollPosition(Property::INVALID_INDEX),
188 mPropertyMaxScrollPosition(Property::INVALID_INDEX),
189 mPropertyScrollContentSize(Property::INVALID_INDEX),
190 mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
191 mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
192 mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION),
194 mGestureDisplacement(Vector2::ZERO),
195 mCurrentScrollPosition(0.0f),
196 mIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE),
197 mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT),
198 mIndicatorMinimumHeight(DEFAULT_INDICATOR_MINIMUM_HEIGHT),
199 mIndicatorStartPadding(DEFAULT_INDICATOR_START_PADDING),
200 mIndicatorEndPadding(DEFAULT_INDICATOR_END_PADDING),
202 mIndicatorFirstShow(true)
206 ScrollBar::~ScrollBar()
210 void ScrollBar::OnInitialize()
214 CreateDefaultIndicatorActor();
215 self.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
217 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::SCROLL_BAR);
220 DevelControl::ControlAccessible* ScrollBar::CreateAccessibleObject()
222 return new ScrollBarAccessible(Self());
225 void ScrollBar::SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize)
227 if(handle && propertyScrollPosition != Property::INVALID_INDEX && propertyMinScrollPosition != Property::INVALID_INDEX && propertyMaxScrollPosition != Property::INVALID_INDEX && propertyScrollContentSize != Property::INVALID_INDEX)
229 mScrollableObject = WeakHandle<Handle>(handle);
230 mPropertyScrollPosition = propertyScrollPosition;
231 mPropertyMinScrollPosition = propertyMinScrollPosition;
232 mPropertyMaxScrollPosition = propertyMaxScrollPosition;
233 mPropertyScrollContentSize = propertyScrollContentSize;
239 DALI_LOG_ERROR("Can not set empty handle of source object or invalid source property index\n");
243 void ScrollBar::CreateDefaultIndicatorActor()
245 const std::string imageDirPath = AssetManager::GetDaliImagePath();
246 Toolkit::ImageView indicator = Toolkit::ImageView::New(imageDirPath + DEFAULT_INDICATOR_IMAGE_FILE_NAME);
247 indicator.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
248 indicator.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
249 indicator.SetStyleName("ScrollBarIndicator");
250 indicator.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR);
251 SetScrollIndicator(indicator);
254 void ScrollBar::SetScrollIndicator(Actor indicator)
256 // Don't allow empty handle
259 // Remove current Indicator
262 Self().Remove(mIndicator);
264 mIndicator = indicator;
266 mIndicatorFirstShow = true;
267 Self().Add(mIndicator);
269 EnableGestureDetection(GestureType::Value(GestureType::PAN));
271 PanGestureDetector detector(GetPanGestureDetector());
272 detector.DetachAll();
273 detector.Attach(mIndicator);
275 unsigned int childCount = mIndicator.GetChildCount();
276 for(unsigned int index = 0; index < childCount; index++)
278 Actor child = mIndicator.GetChildAt(index);
281 detector.Attach(child);
287 DALI_LOG_ERROR("Empty handle of scroll indicator\n");
291 Actor ScrollBar::GetScrollIndicator()
296 void ScrollBar::ApplyConstraints()
298 Handle scrollableHandle = mScrollableObject.GetHandle();
302 if(mIndicatorSizeConstraint)
304 mIndicatorSizeConstraint.Remove();
307 // Set indicator height according to the indicator's height policy
308 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
310 mIndicator.SetProperty(Actor::Property::SIZE, Vector2(Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, mIndicatorFixedHeight));
314 mIndicatorSizeConstraint = Constraint::New<Vector3>(mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint(mIndicatorMinimumHeight, mIndicatorStartPadding + mIndicatorEndPadding));
315 mIndicatorSizeConstraint.AddSource(ParentSource(Actor::Property::SIZE));
316 mIndicatorSizeConstraint.AddSource(Source(scrollableHandle, mPropertyScrollContentSize));
317 mIndicatorSizeConstraint.Apply();
320 if(mIndicatorPositionConstraint)
322 mIndicatorPositionConstraint.Remove();
325 mIndicatorPositionConstraint = Constraint::New<Vector3>(mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint(mIndicatorStartPadding, mIndicatorEndPadding));
326 mIndicatorPositionConstraint.AddSource(LocalSource(Actor::Property::SIZE));
327 mIndicatorPositionConstraint.AddSource(ParentSource(Actor::Property::SIZE));
328 mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyScrollPosition));
329 mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyMinScrollPosition));
330 mIndicatorPositionConstraint.AddSource(Source(scrollableHandle, mPropertyMaxScrollPosition));
331 mIndicatorPositionConstraint.Apply();
335 void ScrollBar::SetScrollPositionIntervals(const Dali::Vector<float>& positions)
337 mScrollPositionIntervals = positions;
339 Handle scrollableHandle = mScrollableObject.GetHandle();
343 if(mPositionNotification)
345 scrollableHandle.RemovePropertyNotification(mPositionNotification);
348 mPositionNotification = scrollableHandle.AddPropertyNotification(mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals));
349 mPositionNotification.NotifySignal().Connect(this, &ScrollBar::OnScrollPositionIntervalReached);
353 Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
355 return mScrollPositionIntervals;
358 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
360 // Emit the signal to notify the scroll position crossing
361 Handle scrollableHandle = mScrollableObject.GetHandle();
364 mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetCurrentProperty<float>(mPropertyScrollPosition));
365 if(Self() == Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
367 GetAccessibleObject()->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::VALUE);
372 void ScrollBar::ShowIndicator()
374 // Cancel any animation
381 if(mIndicatorFirstShow)
383 // Preserve the alpha value from the stylesheet
384 mIndicatorShowAlpha = Self().GetCurrentProperty<Vector4>(Actor::Property::COLOR).a;
385 mIndicatorFirstShow = false;
388 if(mIndicatorShowDuration > 0.0f)
390 mAnimation = Animation::New(mIndicatorShowDuration);
391 mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), mIndicatorShowAlpha, AlphaFunction::EASE_IN);
396 mIndicator.SetProperty(Actor::Property::OPACITY, mIndicatorShowAlpha);
400 void ScrollBar::HideIndicator()
402 // Cancel any animation
409 if(mIndicatorHideDuration > 0.0f)
411 mAnimation = Animation::New(mIndicatorHideDuration);
412 mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN);
417 mIndicator.SetProperty(Actor::Property::OPACITY, 0.0f);
421 void ScrollBar::ShowTransientIndicator()
423 // Cancel any animation
430 mAnimation = Animation::New(mIndicatorShowDuration + mTransientIndicatorDuration + mIndicatorHideDuration);
431 if(mIndicatorShowDuration > 0.0f)
433 mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA),
435 AlphaFunction::EASE_IN,
436 TimePeriod(0, mIndicatorShowDuration));
440 mIndicator.SetProperty(Actor::Property::OPACITY, mIndicatorShowAlpha);
442 mAnimation.AnimateTo(Property(mIndicator, Actor::Property::COLOR_ALPHA),
444 AlphaFunction::EASE_IN,
445 TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration));
449 bool ScrollBar::OnPanGestureProcessTick()
451 // Update the scroll position property.
452 Handle scrollableHandle = mScrollableObject.GetHandle();
455 scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
461 void ScrollBar::OnPan(const PanGesture& gesture)
463 Handle scrollableHandle = mScrollableObject.GetHandle();
467 Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
469 switch(gesture.GetState())
471 case Dali::GestureState::STARTED:
473 if(!mPanProcessTimer)
475 // Make sure the pan gesture is only being processed once per frame.
476 mPanProcessTimer = Timer::New(DEFAULT_PAN_GESTURE_PROCESS_TIME);
477 mPanProcessTimer.TickSignal().Connect(this, &ScrollBar::OnPanGestureProcessTick);
478 mPanProcessTimer.Start();
482 mScrollStart = scrollableHandle.GetCurrentProperty<float>(mPropertyScrollPosition);
483 mGestureDisplacement = Vector2::ZERO;
488 case Dali::GestureState::CONTINUING:
490 mGestureDisplacement += gesture.GetDisplacement();
492 float minScrollPosition = scrollableHandle.GetCurrentProperty<float>(mPropertyMinScrollPosition);
493 float maxScrollPosition = scrollableHandle.GetCurrentProperty<float>(mPropertyMaxScrollPosition);
495 // The domain size is the internal range
496 float domainSize = maxScrollPosition - minScrollPosition;
497 float logicalSize = Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE).y - (mIndicator.GetCurrentProperty<Vector3>(Actor::Property::SIZE).y + mIndicatorStartPadding + mIndicatorEndPadding);
499 mCurrentScrollPosition = mScrollStart - ((mGestureDisplacement.y * domainSize) / logicalSize);
500 mCurrentScrollPosition = -std::min(maxScrollPosition, std::max(-mCurrentScrollPosition, minScrollPosition));
510 // Destroy the timer when pan gesture is finished.
511 mPanProcessTimer.Stop();
512 mPanProcessTimer.TickSignal().Disconnect(this, &ScrollBar::OnPanGestureProcessTick);
513 mPanProcessTimer.Reset();
518 // Refresh the ItemView cache with extra items
519 GetImpl(itemView).DoRefresh(mCurrentScrollPosition, true);
522 mPanFinishedSignal.Emit();
530 // Disable automatic refresh in ItemView during fast scrolling
531 GetImpl(itemView).SetRefreshEnabled(!mIsPanning);
536 void ScrollBar::OnSizeSet(const Vector3& size)
538 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
540 mIndicator.SetProperty(Actor::Property::SIZE, Vector2(size.width, mIndicatorFixedHeight));
543 Control::OnSizeSet(size);
546 void ScrollBar::SetScrollDirection(Toolkit::ScrollBar::Direction direction)
548 mDirection = direction;
551 Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const
556 void ScrollBar::SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy)
558 if(policy != mIndicatorHeightPolicy)
560 mIndicatorHeightPolicy = policy;
565 Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() const
567 return mIndicatorHeightPolicy;
570 void ScrollBar::SetIndicatorFixedHeight(float height)
572 mIndicatorFixedHeight = height;
574 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
576 mIndicator.SetProperty(Actor::Property::SIZE, Vector2(Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE).width, mIndicatorFixedHeight));
580 float ScrollBar::GetIndicatorFixedHeight() const
582 return mIndicatorFixedHeight;
585 void ScrollBar::SetIndicatorShowDuration(float durationSeconds)
587 mIndicatorShowDuration = durationSeconds;
590 float ScrollBar::GetIndicatorShowDuration() const
592 return mIndicatorShowDuration;
595 void ScrollBar::SetIndicatorHideDuration(float durationSeconds)
597 mIndicatorHideDuration = durationSeconds;
600 float ScrollBar::GetIndicatorHideDuration() const
602 return mIndicatorHideDuration;
605 void ScrollBar::OnScrollDirectionPropertySet(Property::Value propertyValue)
607 std::string directionName(propertyValue.Get<std::string>());
608 if(directionName == "VERTICAL")
610 SetScrollDirection(Toolkit::ScrollBar::VERTICAL);
612 else if(directionName == "HORIZONTAL")
614 SetScrollDirection(Toolkit::ScrollBar::HORIZONTAL);
618 DALI_ASSERT_ALWAYS(!"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value.");
622 void ScrollBar::OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue)
624 std::string policyName(propertyValue.Get<std::string>());
625 if(policyName == "VARIABLE")
627 SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
629 else if(policyName == "FIXED")
631 SetIndicatorHeightPolicy(Toolkit::ScrollBar::FIXED);
635 DALI_ASSERT_ALWAYS(!"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value.");
639 bool ScrollBar::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
641 Dali::BaseHandle handle(object);
643 bool connected(true);
644 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(handle);
646 if(0 == strcmp(signalName.c_str(), PAN_FINISHED_SIGNAL))
648 scrollBar.PanFinishedSignal().Connect(tracker, functor);
650 else if(0 == strcmp(signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL))
652 scrollBar.ScrollPositionIntervalReachedSignal().Connect(tracker, functor);
656 // signalName does not match any signal
663 void ScrollBar::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
665 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(Dali::BaseHandle(object));
669 ScrollBar& scrollBarImpl(GetImpl(scrollBar));
672 case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
674 scrollBarImpl.OnScrollDirectionPropertySet(value);
677 case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
679 scrollBarImpl.OnIndicatorHeightPolicyPropertySet(value);
682 case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
684 scrollBarImpl.SetIndicatorFixedHeight(value.Get<float>());
687 case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
689 scrollBarImpl.SetIndicatorShowDuration(value.Get<float>());
692 case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
694 scrollBarImpl.SetIndicatorHideDuration(value.Get<float>());
697 case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
699 const Property::Array* array = value.GetArray();
702 Dali::Vector<float> positions;
703 size_t positionCount = array->Count();
704 positions.Resize(positionCount);
705 for(size_t i = 0; i != positionCount; ++i)
707 array->GetElementAt(i).Get(positions[i]);
710 scrollBarImpl.SetScrollPositionIntervals(positions);
714 case Toolkit::ScrollBar::Property::INDICATOR_MINIMUM_HEIGHT:
716 scrollBarImpl.mIndicatorMinimumHeight = value.Get<float>();
717 scrollBarImpl.ApplyConstraints();
720 case Toolkit::ScrollBar::Property::INDICATOR_START_PADDING:
722 scrollBarImpl.mIndicatorStartPadding = value.Get<float>();
723 scrollBarImpl.ApplyConstraints();
726 case Toolkit::ScrollBar::Property::INDICATOR_END_PADDING:
728 scrollBarImpl.mIndicatorEndPadding = value.Get<float>();
729 scrollBarImpl.ApplyConstraints();
732 case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
734 scrollBarImpl.mTransientIndicatorDuration = value.Get<float>();
741 Property::Value ScrollBar::GetProperty(BaseObject* object, Property::Index index)
743 Property::Value value;
745 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(Dali::BaseHandle(object));
749 ScrollBar& scrollBarImpl(GetImpl(scrollBar));
752 case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
754 value = SCROLL_DIRECTION_NAME[scrollBarImpl.GetScrollDirection()];
757 case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
759 value = INDICATOR_HEIGHT_POLICY_NAME[scrollBarImpl.GetIndicatorHeightPolicy()];
762 case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
764 value = scrollBarImpl.GetIndicatorFixedHeight();
767 case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
769 value = scrollBarImpl.GetIndicatorShowDuration();
772 case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
774 value = scrollBarImpl.GetIndicatorHideDuration();
777 case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
779 Property::Value tempValue(Property::ARRAY);
780 Property::Array* array = tempValue.GetArray();
784 Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
785 size_t positionCount(positions.Count());
787 for(size_t i(0); i != positionCount; ++i)
789 array->PushBack(positions[i]);
796 case Toolkit::ScrollBar::Property::INDICATOR_MINIMUM_HEIGHT:
798 value = scrollBarImpl.mIndicatorMinimumHeight;
801 case Toolkit::ScrollBar::Property::INDICATOR_START_PADDING:
803 value = scrollBarImpl.mIndicatorStartPadding;
806 case Toolkit::ScrollBar::Property::INDICATOR_END_PADDING:
808 value = scrollBarImpl.mIndicatorEndPadding;
811 case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
813 value = scrollBarImpl.mTransientIndicatorDuration;
821 bool ScrollBar::DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes)
825 Dali::BaseHandle handle(object);
827 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast(handle);
829 DALI_ASSERT_DEBUG(scrollBar);
833 if(0 == strcmp(actionName.c_str(), ACTION_SHOW_INDICATOR))
835 GetImpl(scrollBar).ShowIndicator();
838 else if(0 == strcmp(actionName.c_str(), ACTION_HIDE_INDICATOR))
840 GetImpl(scrollBar).HideIndicator();
843 else if(0 == strcmp(actionName.c_str(), ACTION_SHOW_TRANSIENT_INDICATOR))
845 GetImpl(scrollBar).ShowTransientIndicator();
853 Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction)
855 // Create the implementation, temporarily owned by this handle on stack
856 IntrusivePtr<ScrollBar> impl = new ScrollBar(direction);
858 // Pass ownership to CustomActor handle
859 Toolkit::ScrollBar handle(*impl);
861 // Second-phase init of the implementation
862 // This can only be done after the CustomActor connection has been made...
868 double ScrollBar::ScrollBarAccessible::GetMinimum() const
870 auto self = Toolkit::ScrollBar::DownCast(Self());
871 Handle scrollableHandle = GetImpl(self).mScrollableObject.GetHandle();
872 return scrollableHandle ? scrollableHandle.GetCurrentProperty<float>(GetImpl(self).mPropertyMinScrollPosition) : 0.0f;
875 double ScrollBar::ScrollBarAccessible::GetCurrent() const
877 auto self = Toolkit::ScrollBar::DownCast(Self());
878 Handle scrollableHandle = GetImpl(self).mScrollableObject.GetHandle();
879 return scrollableHandle ? scrollableHandle.GetCurrentProperty<float>(GetImpl(self).mPropertyScrollPosition) : 0.0f;
882 double ScrollBar::ScrollBarAccessible::GetMaximum() const
884 auto self = Toolkit::ScrollBar::DownCast(Self());
885 Handle scrollableHandle = GetImpl(self).mScrollableObject.GetHandle();
886 return scrollableHandle ? scrollableHandle.GetCurrentProperty<float>(GetImpl(self).mPropertyMaxScrollPosition) : 1.0f;
889 bool ScrollBar::ScrollBarAccessible::SetCurrent(double current)
891 if(current < GetMinimum() || current > GetMaximum())
896 auto valueBefore = GetCurrent();
898 auto self = Toolkit::ScrollBar::DownCast(Self());
899 Handle scrollableHandle = GetImpl(self).mScrollableObject.GetHandle();
900 if(!scrollableHandle)
905 scrollableHandle.SetProperty(GetImpl(self).mPropertyScrollPosition, static_cast<float>(current));
907 auto valueAfter = GetCurrent();
909 if((current != valueBefore) && (valueBefore == valueAfter))
917 double ScrollBar::ScrollBarAccessible::GetMinimumIncrement() const
922 } // namespace Internal
924 } // namespace Toolkit