/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/common/stage.h>
+#include <dali/devel-api/common/stage.h>
#include <dali/public-api/events/wheel-event.h>
-#include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/events/touch-event.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/devel-api/object/property-helper-devel.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
#include <dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h>
#include <dali-toolkit/public-api/controls/scrollable/item-view/default-item-layout.h>
-#include <dali-toolkit/devel-api/controls/scrollable/item-view/default-item-layout-property.h>
-#include <dali-toolkit/devel-api/controls/scrollable/item-view/item-view-devel.h>
+#include <dali-toolkit/public-api/controls/scrollable/item-view/default-item-layout-property.h>
#include <dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h>
#include <dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h>
#include <dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h>
DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "wheelScrollDistanceStep", FLOAT, WHEEL_SCROLL_DISTANCE_STEP )
DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "snapToItemEnabled", BOOLEAN, SNAP_TO_ITEM_ENABLED )
DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "refreshInterval", FLOAT, REFRESH_INTERVAL )
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, ItemView, "layout", ARRAY, LAYOUT )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "layout", ARRAY, LAYOUT )
DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "layoutPosition", FLOAT, LAYOUT_POSITION)
}
ItemView::ItemView(ItemFactory& factory)
-: Scrollable( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS | REQUIRES_WHEEL_EVENTS | REQUIRES_KEYBOARD_NAVIGATION_SUPPORT ) ),
+: Scrollable( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS | REQUIRES_KEYBOARD_NAVIGATION_SUPPORT ) ),
mItemFactory(factory),
mItemsParentOrigin(ParentOrigin::CENTER),
mItemsAnchorPoint(AnchorPoint::CENTER),
mScrollDistance(0.0f),
mScrollSpeed(0.0f),
mScrollOvershoot(0.0f),
- mGestureState(Gesture::Clear),
+ mGestureState(GestureState::CLEAR),
mAnimatingOvershootOn(false),
mAnimateOvershootOff(false),
mAnchoringEnabled(false),
Vector2 stageSize = Stage::GetCurrent().GetSize();
mWheelScrollDistanceStep = stageSize.y * DEFAULT_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION;
- self.TouchSignal().Connect( this, &ItemView::OnTouch );
- EnableGestureDetection(Gesture::Type(Gesture::Pan));
+ self.TouchedSignal().Connect( this, &ItemView::OnTouch );
+ EnableGestureDetection(GestureType::Value(GestureType::PAN));
mWheelEventFinishedTimer = Timer::New( WHEEL_EVENT_FINISHED_TIME_OUT );
mWheelEventFinishedTimer.TickSignal().Connect( this, &ItemView::OnWheelEventFinished );
SetRefreshInterval(DEFAULT_REFRESH_INTERVAL_LAYOUT_POSITIONS);
+
+ // Connect wheel event
+ self.WheelEventSignal().Connect( this, &ItemView::OnWheelEvent );
}
ItemView::~ItemView()
Actor self = Self();
// The ItemView size should match the active layout size
- self.SetSize(targetSize);
+ self.SetProperty( Actor::Property::SIZE, targetSize);
mActiveLayoutTargetSize = targetSize;
// Switch to the new layout
Vector3 size;
mActiveLayout->GetItemSize( itemId, targetSize, size );
- actor.SetSize( size.GetVectorXY() );
+ actor.SetProperty( Actor::Property::SIZE, size.GetVectorXY() );
}
// Refresh the new layout
{
ItemRange range = GetItemRange(*mActiveLayout, mActiveLayoutTargetSize, currentLayoutPosition, cacheExtra/*reserve extra*/);
RemoveActorsOutsideRange( range );
- AddActorsWithinRange( range, Self().GetCurrentSize() );
+ AddActorsWithinRange( range, Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) );
mScrollUpdatedSignal.Emit( Vector2(0.0f, currentLayoutPosition) );
}
void ItemView::InsertItem( Item newItem, float durationSeconds )
{
mAddingItems = true;
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
Actor displacedActor;
ItemIter afterDisplacedIter = mItemPool.end();
void ItemView::InsertItems( const ItemContainer& newItems, float durationSeconds )
{
mAddingItems = true;
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
// Insert from lowest id to highest
ItemContainer sortedItems(newItems);
void ItemView::ReplaceItem( Item replacementItem, float durationSeconds )
{
mAddingItems = true;
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
SetupActor( replacementItem, layoutSize );
Self().Add( replacementItem.second );
// Total number of items may change dynamically.
// Always recalculate the domain size to reflect that.
- CalculateDomainSize(Self().GetCurrentSize());
+ CalculateDomainSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
}
void ItemView::AddNewActor( unsigned int itemId, const Vector3& layoutSize )
void ItemView::SetupActor( Item item, const Vector3& layoutSize )
{
- item.second.SetParentOrigin( mItemsParentOrigin );
- item.second.SetAnchorPoint( mItemsAnchorPoint );
+ item.second.SetProperty( Actor::Property::PARENT_ORIGIN, mItemsParentOrigin );
+ item.second.SetProperty( Actor::Property::ANCHOR_POINT, mItemsAnchorPoint );
if( mActiveLayout )
{
Vector3 size;
mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size );
- item.second.SetSize( size.GetVectorXY() );
+ item.second.SetProperty( Actor::Property::SIZE, size.GetVectorXY() );
mActiveLayout->ApplyConstraints( item.second, item.first, layoutSize, Self() );
}
Scrollable::OnChildAdd( child );
}
-bool ItemView::OnWheelEvent(const WheelEvent& event)
+bool ItemView::OnWheelEvent(Actor actor, const WheelEvent& event)
{
// Respond the wheel event to scroll
if (mActiveLayout)
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
- float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.z * mWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor());
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
+ float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.GetDelta() * mWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor());
float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout);
self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition );
void ItemView::ReapplyAllConstraints()
{
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
for (ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
void ItemView::OnItemsRemoved()
{
- CalculateDomainSize(Self().GetCurrentSize());
+ CalculateDomainSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
// Adjust scroll-position after an item is removed
if( mActiveLayout )
{
- float firstItemScrollPosition = ClampFirstItemPosition(GetCurrentLayoutPosition(0), Self().GetCurrentSize(), *mActiveLayout);
+ float firstItemScrollPosition = ClampFirstItemPosition(GetCurrentLayoutPosition(0), Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ), *mActiveLayout);
Self().SetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition );
}
}
return clamppedPosition;
}
-bool ItemView::OnTouch( Actor actor, const TouchData& touch )
+bool ItemView::OnTouch( Actor actor, const TouchEvent& touch )
{
// Ignore events with multiple-touch points
if (touch.GetPointCount() != 1)
if ( touch.GetState( 0 ) == PointState::DOWN )
{
// Cancel ongoing scrolling etc.
- mGestureState = Gesture::Clear;
+ mGestureState = GestureState::CLEAR;
mScrollDistance = 0.0f;
mScrollSpeed = 0.0f;
void ItemView::OnPan( const PanGesture& gesture )
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
RemoveAnimation(mScrollAnimation);
// Short-circuit if there is no active layout
if (!mActiveLayout)
{
- mGestureState = Gesture::Clear;
+ mGestureState = GestureState::CLEAR;
return;
}
- mGestureState = gesture.state;
+ mGestureState = gesture.GetState();
switch (mGestureState)
{
- case Gesture::Finished:
+ case GestureState::FINISHED:
{
// Swipe Detection
if (fabsf(mScrollDistance) > mMinimumSwipeDistance &&
}
break;
- case Gesture::Started: // Fall through
+ case GestureState::STARTED: // Fall through
{
mTotalPanDisplacement = Vector2::ZERO;
mScrollStartedSignal.Emit(GetCurrentScrollPosition());
mRefreshEnabled = true;
}
- case Gesture::Continuing:
+ case GestureState::CONTINUING:
{
- mScrollDistance = CalculateScrollDistance(gesture.displacement, *mActiveLayout);
+ const Vector2& displacement = gesture.GetDisplacement();
+ mScrollDistance = CalculateScrollDistance(displacement, *mActiveLayout);
mScrollSpeed = Clamp((gesture.GetSpeed() * gesture.GetSpeed() * mActiveLayout->GetFlickSpeedFactor() * MILLISECONDS_PER_SECONDS), 0.0f, mActiveLayout->GetMaximumSwipeSpeed());
// Refresh order depends on the direction of the scroll; negative is towards the last item.
( firstItemScrollPosition <= mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), layoutSize) &&
currentOvershoot > -1.0f ) )
{
- mTotalPanDisplacement += gesture.displacement;
+ mTotalPanDisplacement += displacement;
}
mScrollOvershoot = CalculateScrollOvershoot();
}
break;
- case Gesture::Cancelled:
+ case GestureState::CANCELLED:
{
mScrollAnimation = DoAnchoring();
}
}
}
float layoutPosition = mActiveLayout->GetClosestAnchorPosition( GetCurrentLayoutPosition(0) );
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
if(!nextFocusActor)
{
// likely the current item is not buffered, so not in our item pool, probably best to get first viewable item
{
int nextItemID = GetItemId(commitedFocusableActor);
float layoutPosition = GetCurrentLayoutPosition(0);
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
float scrollTo = mActiveLayout->GetClosestOnScreenLayoutPosition(nextItemID, layoutPosition, layoutSize);
ScrollTo(Vector2(0.0f, scrollTo), DEFAULT_KEYBOARD_FOCUS_SCROLL_DURATION);
void ItemView::ScrollToItem(unsigned int itemId, float durationSeconds)
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
float firstItemScrollPosition = ClampFirstItemPosition(mActiveLayout->GetItemScrollToPosition(itemId), layoutSize, *mActiveLayout);
if(durationSeconds > 0.0f)
Vector2 ItemView::GetCurrentScrollPosition() const
{
- return Vector2(0.0f, GetScrollPosition(GetCurrentLayoutPosition(0), Self().GetCurrentSize()));
+ return Vector2(0.0f, GetScrollPosition(GetCurrentLayoutPosition(0), Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE )));
}
void ItemView::AddOverlay(Actor actor)
{
- actor.SetDrawMode( DrawMode::OVERLAY_2D );
+ actor.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
Self().Add(actor);
}
void ItemView::ScrollTo(const Vector2& position, float duration)
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
float firstItemScrollPosition = ClampFirstItemPosition(position.y, layoutSize, *mActiveLayout);
mOvershootEffectColor = color;
if( mOvershootOverlay )
{
- mOvershootOverlay.SetColor( color );
+ mOvershootOverlay.SetProperty( Actor::Property::COLOR, color );
}
}
{
Property::Index effectOvershootPropertyIndex = Property::INVALID_INDEX;
mOvershootOverlay = CreateBouncingEffectActor( effectOvershootPropertyIndex );
- mOvershootOverlay.SetColor(mOvershootEffectColor);
- mOvershootOverlay.SetParentOrigin(ParentOrigin::TOP_LEFT);
- mOvershootOverlay.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- mOvershootOverlay.SetDrawMode( DrawMode::OVERLAY_2D );
+ mOvershootOverlay.SetProperty( Actor::Property::COLOR,mOvershootEffectColor);
+ mOvershootOverlay.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT );
+ mOvershootOverlay.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
+ mOvershootOverlay.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
self.Add(mOvershootOverlay);
ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height );
Actor self = Self();
float scrollDistance = CalculateScrollDistance(mTotalPanDisplacement, *mActiveLayout) * mActiveLayout->GetScrollSpeedFactor();
float positionDelta = GetCurrentLayoutPosition(0) + scrollDistance;
- float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), Self().GetCurrentSize());
+ float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, Vector2(0.0f, -minLayoutPosition));
float clamppedPosition = std::min(0.0f, std::max(minLayoutPosition, positionDelta));
overshoot = positionDelta - clamppedPosition;
if (mOvershootOverlay)
{
- duration = mOvershootOverlay.GetCurrentSize().height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed;
+ duration = mOvershootOverlay.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed;
}
// Mark the animation as in progress to prevent manual property sets overwriting it.
mItemsParentOrigin = parentOrigin;
for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
- iter->second.SetParentOrigin(parentOrigin);
+ iter->second.SetProperty( Actor::Property::PARENT_ORIGIN,parentOrigin );
}
}
}
mItemsAnchorPoint = anchorPoint;
for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
- iter->second.SetAnchorPoint(anchorPoint);
+ iter->second.SetProperty( Actor::Property::ANCHOR_POINT,anchorPoint);
}
}
}
itemViewImpl.SetMinimumSwipeSpeed( value.Get<float>() );
break;
}
+
case Toolkit::ItemView::Property::MINIMUM_SWIPE_DISTANCE:
{
itemViewImpl.SetMinimumSwipeDistance( value.Get<float>() );
break;
}
+
case Toolkit::ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP:
{
itemViewImpl.SetWheelScrollDistanceStep( value.Get<float>() );
break;
}
+
case Toolkit::ItemView::Property::SNAP_TO_ITEM_ENABLED:
{
itemViewImpl.SetAnchoring( value.Get<bool>() );
break;
}
+
case Toolkit::ItemView::Property::REFRESH_INTERVAL:
{
itemViewImpl.SetRefreshInterval( value.Get<float>() );
break;
}
- case Toolkit::DevelItemView::Property::LAYOUT:
+
+ case Toolkit::ItemView::Property::LAYOUT:
{
// Get a Property::Array from the property if possible.
Property::Array layoutArray;
{
const Property::Value& element = layouts.GetElementAt( arrayIdx );
- Property::Map* layout = element.GetMap();
+ const Property::Map* layout = element.GetMap();
if( layout != NULL )
{
for( unsigned int mapIdx = 0, mapCount = (*layout).Count(); mapIdx < mapCount; ++mapIdx )
value = itemViewImpl.GetMinimumSwipeSpeed();
break;
}
+
case Toolkit::ItemView::Property::MINIMUM_SWIPE_DISTANCE:
{
value = itemViewImpl.GetMinimumSwipeDistance();
break;
}
+
case Toolkit::ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP:
{
value = itemViewImpl.GetWheelScrollDistanceStep();
break;
}
+
case Toolkit::ItemView::Property::SNAP_TO_ITEM_ENABLED:
{
value = itemViewImpl.GetAnchoring();
break;
}
+
case Toolkit::ItemView::Property::REFRESH_INTERVAL:
{
value = itemViewImpl.GetRefreshInterval();
break;
}
- case Toolkit::DevelItemView::Property::LAYOUT:
+
+ case Toolkit::ItemView::Property::LAYOUT:
{
Property::Array layouts= itemViewImpl.GetLayoutArray();
value = layouts;
break;
}
-
}
}