diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-02-22 17:25:27 +0100 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-03-02 17:24:33 +0100 |
commit | 76cc9488dd13aedf637c01b1bd8adddbe0a17d81 (patch) | |
tree | b11e2a5898390beca5b60a335c8c3302e94d4f7b | |
parent | c6dba86e4c464a25b965f1029f670de2828ddb68 (diff) | |
download | efl-76cc9488dd13aedf637c01b1bd8adddbe0a17d81.tar.gz |
efl_ui_spotlight_scroll: improve scroll behaviour
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.
-rw-r--r-- | src/lib/eina/eina_rectangle.h | 9 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_spotlight_scroll_manager.c | 21 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/lib/eina/eina_rectangle.h b/src/lib/eina/eina_rectangle.h index 54cf1ccb99..40cbe62c19 100644 --- a/src/lib/eina/eina_rectangle.h +++ b/src/lib/eina/eina_rectangle.h @@ -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 diff --git a/src/lib/elementary/efl_ui_spotlight_scroll_manager.c b/src/lib/elementary/efl_ui_spotlight_scroll_manager.c index bdb6840c06..63147c1d1b 100644 --- a/src/lib/elementary/efl_ui_spotlight_scroll_manager.c +++ b/src/lib/elementary/efl_ui_spotlight_scroll_manager.c @@ -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, |