TizenRefApp-8275 [Gallery] Add scroll to iteam feature into ImageGrid 96/122196/1
authorIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 12:44:10 +0000 (15:44 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Thu, 30 Mar 2017 12:44:10 +0000 (15:44 +0300)
- Implemented ImageGrid::scrollToItem/bringInItem methods.

Change-Id: Ie163a7c1601747fba691ba9514865e7612b79f9b

inc/presentation/ImageGrid.h
src/presentation/ImageGrid.cpp

index baea32da069829b12b1f6efbae5f09fd2e170de2..f8373a1363380c50621f6692baa45f0ad531ab75 100644 (file)
@@ -75,6 +75,9 @@ namespace gallery {
 
                ucl::Result isItemRealized(int itemIndex) const;
 
+               ucl::Result scrollToItem(int itemIndex);
+               ucl::Result bringInItem(int itemIndex);
+
                void activateRotary();
                void deactivateRotary();
 
@@ -94,6 +97,11 @@ namespace gallery {
 
                template <class FUNC>
                ucl::Result doWithItem(int itemIndex, FUNC &&func) const;
+               template <class FUNC>
+               ucl::Result doWithCell(int itemIndex, FUNC &&func) const;
+
+               template <class SHOW_FUNC>
+               ucl::Result showItem(int itemIndex, SHOW_FUNC &&showFunc);
 
                void addUnrealizeLock();
                void removeUnrealizeLock();
index 99cf0f5f995b9302116cd13ab117c999e048296a..16ad4d7d2851f4efa9afbc1a18fcaad475bfab3a 100644 (file)
@@ -617,6 +617,20 @@ namespace gallery {
 
        template <class FUNC>
        Result ImageGrid::doWithItem(const int itemIndex, FUNC &&func) const
+       {
+               return doWithCell(itemIndex,
+                       [this, &func](const int slotIndex, const int itemOffset)
+                       {
+                               const int slotOffset = (slotIndex - m_beginSlotIndex);
+                               if ((slotOffset < 0) || (slotOffset >= m_slotCount)) {
+                                       return RES_FALSE;
+                               }
+                               return func(*m_slots[slotOffset], itemOffset);
+                       });
+       }
+
+       template <class FUNC>
+       Result ImageGrid::doWithCell(const int itemIndex, FUNC &&func) const
        {
                if ((itemIndex < 0) || (itemIndex >= m_itemCount)) {
                        LOG_RETURN(RES_INVALID_ARGUMENTS,
@@ -627,12 +641,33 @@ namespace gallery {
                int itemOffset = 0;
                m_info.calcCellFromItemIndex(itemIndex, slotIndex, itemOffset);
 
-               const int slotOffset = (slotIndex - m_beginSlotIndex);
-               if ((slotOffset < 0) || (slotOffset >= m_slotCount)) {
-                       return RES_FALSE;
-               }
+               return func(slotIndex, itemOffset);
+       }
 
-               return func(*m_slots[slotOffset], itemOffset);
+       Result ImageGrid::scrollToItem(const int itemIndex)
+       {
+               return showItem(itemIndex, elm_scroller_region_show);
+       }
+
+       Result ImageGrid::bringInItem(int itemIndex)
+       {
+               return showItem(itemIndex, elm_scroller_region_bring_in);
+       }
+
+       template <class SHOW_FUNC>
+       Result ImageGrid::showItem(const int itemIndex, SHOW_FUNC &&showFunc)
+       {
+               return doWithCell(itemIndex,
+                       [this, &showFunc](const int slotIndex, const int itemOffset)
+                       {
+                               const int scrollOffset = ((slotIndex / 2) * m_slotSize);
+                               if (m_info.isHorizontal) {
+                                       showFunc(*m_scroller, scrollOffset, 0, m_scrollerSize, 1);
+                               } else {
+                                       showFunc(*m_scroller, 0, scrollOffset, 1, m_scrollerSize);
+                               }
+                               return RES_OK;
+                       });
        }
 
        void ImageGrid::activateRotary()