scroller: fix page calculation logic when looping is enabled.
authorHosang Kim <hosang12.kim@samsung.com>
Fri, 28 Aug 2015 12:12:30 +0000 (21:12 +0900)
committerChunEon Park <hermet@hermet.pe.kr>
Fri, 28 Aug 2015 12:12:30 +0000 (21:12 +0900)
Test Plan:
1. elementary_test -> scroller
           2. Lopping in x axis
           3. click prev page or next page

Reviewers: SanghyeonLee, singh.amitesh, Hermet, seoz, cedric, raster, jaehwan

Differential Revision: https://phab.enlightenment.org/D2982

src/bin/test_scroller.c
src/lib/elm_interface_scrollable.c

index 75ddfb7..3a53d1b 100644 (file)
@@ -28,6 +28,24 @@ _my_bt_go_900_900(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EIN
 }
 
 static void
+_my_bt_prev_page(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+       Evas_Object *sc = (Evas_Object *)data;
+       int page_x = 0, page_y = 0;
+       elm_scroller_current_page_get(sc, &page_x, &page_y);
+       elm_scroller_page_bring_in(sc, --page_x, page_y);
+}
+
+static void
+_my_bt_next_page(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+       Evas_Object *sc = (Evas_Object *)data;
+       int page_x = 0, page_y = 0;
+       elm_scroller_current_page_get(sc, &page_x, &page_y);
+       elm_scroller_page_bring_in(sc, ++page_x, page_y);
+}
+
+static void
 _my_bt_freeze_toggle(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
 {
    if (elm_check_state_get(obj))
@@ -350,6 +368,22 @@ test_scroller(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_
    elm_table_pack(tb2, bt, 2, 2, 1, 1);
    evas_object_show(bt);
 
+   bt = elm_button_add(win);
+   elm_object_text_set(bt, "prev page");
+   evas_object_smart_callback_add(bt, "clicked", _my_bt_prev_page, sc);
+   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(bt, 0.1, 0.5);
+   elm_table_pack(tb2, bt, 0, 1, 1, 1);
+   evas_object_show(bt);
+
+   bt = elm_button_add(win);
+   elm_object_text_set(bt, "next page");
+   evas_object_smart_callback_add(bt, "clicked", _my_bt_next_page, sc);
+   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(bt, 0.9, 0.5);
+   elm_table_pack(tb2, bt, 2, 1, 1, 1);
+   evas_object_show(bt);
+
    evas_object_event_callback_add(sc, EVAS_CALLBACK_MOVE, _sc_move_cb, tb2);
    evas_object_event_callback_add(sc, EVAS_CALLBACK_RESIZE, _sc_resize_cb, tb2);
    evas_object_geometry_get(sc, &x, &y, &w, &h);
index 914fc9a..77763ab 100644 (file)
@@ -2177,7 +2177,10 @@ _elm_scroll_page_x_get(Elm_Scrollable_Smart_Interface_Data *sid,
 
    if (sid->pagesize_h > 0)
      {
-        x = x + (sid->pagesize_h * 0.5);
+        if (x >= 0)
+          x = x + (sid->pagesize_h * 0.5);
+        else if (x < 0 && sid->loop_h)
+          x = x - (sid->pagesize_h * 0.5);
         x = x / (sid->pagesize_h);
         x = x * (sid->pagesize_h);
      }
@@ -2221,7 +2224,10 @@ _elm_scroll_page_y_get(Elm_Scrollable_Smart_Interface_Data *sid,
 
    if (sid->pagesize_v > 0)
      {
-        y = y + (sid->pagesize_v * 0.5);
+        if (y >= 0)
+          y = y + (sid->pagesize_v * 0.5);
+        else if (y < 0 && sid->loop_v)
+          y = y - (sid->pagesize_v * 0.5);
         y = y / (sid->pagesize_v);
         y = y * (sid->pagesize_v);
      }
@@ -4360,8 +4366,8 @@ _elm_interface_scrollable_page_show(Eo *obj, Elm_Scrollable_Smart_Interface_Data
 
    eo_do(sid->obj, elm_interface_scrollable_content_viewport_geometry_get
          (NULL, NULL, &w, &h));
-   if (pagenumber_h >= 0) x = sid->pagesize_h * pagenumber_h;
-   if (pagenumber_v >= 0) y = sid->pagesize_v * pagenumber_v;
+   x = sid->pagesize_h * pagenumber_h;
+   y = sid->pagesize_v * pagenumber_v;
 
    sid->wx = (sid->is_mirrored ? _elm_scroll_x_mirrored_get(sid->obj, x) : x);
    sid->wy = y;
@@ -4390,8 +4396,8 @@ _elm_interface_scrollable_page_bring_in(Eo *obj, Elm_Scrollable_Smart_Interface_
 
    eo_do(sid->obj, elm_interface_scrollable_content_viewport_geometry_get
          (NULL, NULL, &w, &h));
-   if (pagenumber_h >= 0) x = sid->pagesize_h * pagenumber_h;
-   if (pagenumber_v >= 0) y = sid->pagesize_v * pagenumber_v;
+   x = sid->pagesize_h * pagenumber_h;
+   y = sid->pagesize_v * pagenumber_v;
    if (_elm_scroll_content_region_show_internal(obj, &x, &y, w, h))
      {
         _elm_scroll_scroll_to_x(sid, _elm_config->bring_in_scroll_friction, x);