efl_ui_spotlight_scroll: improve scroll behaviour
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Sat, 22 Feb 2020 16:25:27 +0000 (17:25 +0100)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 3 Mar 2020 21:16:58 +0000 (06:16 +0900)
when the mouse motion was used, we need to mark this event as processed.
Otherwise a click event will be emitted which is wrong.

Additionally, we should only scroll when we are definitly not clicking.
Right now, the scrolling animation would dance arround on a real TS.

Additionally², this commit introduces a little macro which calculates
the distance of a position.

src/lib/eina/eina_rectangle.h
src/lib/elementary/efl_ui_spotlight_scroll_manager.c

index 0644466cb8f42cb71d9ad6d3067e2660e762c239..c1a0788432a8bec78193b90ef0b70b58e27fda01 100644 (file)
@@ -82,6 +82,15 @@ typedef struct _Eina_Size2D
  */
 #define EINA_POSITION2D_EQ(a, b) \
   (((a).x == (b).x) && ((a).y == (b).y))
+/**
+ * @brief Convenience macro for getting the distance from one point to another
+ * @param[in] a An Eina_Position2D
+ * @param[in] b An Eina_Position2D
+ * @return The distance between the two points.
+ * @since 1.24
+ */
+#define EINA_POSITION2D_DISTANCE(a, b) \
+  sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y))
 
 /**
  * @typedef Eina_Rectangle
index b8d6df2687203ce7940ff2628b6a714eaa0e6562..fd1e022c0e5d2c1e283efced3ede1437a0235d57 100644 (file)
@@ -21,6 +21,7 @@ typedef struct {
       Eina_Bool active;
       int from;
       Eina_Position2D mouse_start;
+      double start_time;
    } mouse_move;
    Eina_Bool animation;
    Eina_Bool scroll_block;
@@ -98,6 +99,7 @@ _mouse_down_cb(void *data,
    pd->mouse_move.active = EINA_TRUE;
    pd->mouse_move.from = efl_pack_index_get(pd->container, efl_ui_spotlight_active_element_get(pd->container));
    pd->mouse_move.mouse_start = efl_input_pointer_position_get(ev);
+   pd->mouse_move.start_time = ecore_time_get();
 
    pd->transition.from = pd->mouse_move.from;
    pd->transition.to = pd->transition.from + 1;
@@ -125,12 +127,15 @@ _mouse_move_cb(void *data,
    if (!efl_input_processed_get(ev))
      efl_input_processed_set(ev, EINA_TRUE);
 
-   pd->transition.active = EINA_TRUE;
-   pd->transition.progress = (double)pos_y_diff / (double)pd->page_size.w;
-
-   _propagate_progress(data, pd->transition.from + pd->transition.progress);
-
-   _apply_box_properties(obj, pd);
+   if (pd->transition.active ||
+       EINA_POSITION2D_DISTANCE(pd->mouse_move.mouse_start, efl_input_pointer_position_get(ev)) > elm_config_finger_size_get() ||
+       ecore_time_get() - pd->mouse_move.start_time > 0.1)
+     {
+        pd->transition.active = EINA_TRUE;
+        pd->transition.progress = (double)pos_y_diff / (double)pd->page_size.w;
+        _propagate_progress(data, pd->transition.from + pd->transition.progress);
+        _apply_box_properties(obj, pd);
+     }
 }
 
 static void
@@ -150,6 +155,10 @@ _mouse_up_cb(void *data,
 
    Efl_Ui_Widget *new_content = efl_pack_content_get(pd->container, MIN(MAX(result, 0), efl_content_count(pd->container) - 1));
    efl_ui_spotlight_active_element_set(pd->container, new_content);
+
+   //Set input processed not to cause clicked event to content button.
+   if (EINA_POSITION2D_DISTANCE(pd->mouse_move.mouse_start, efl_input_pointer_position_get(ev)) > elm_config_finger_size_get())
+     efl_input_processed_set(ev, EINA_TRUE);
 }
 
 EFL_CALLBACKS_ARRAY_DEFINE(mouse_listeners,