seoz pushed a commit to branch master. http://git.enlightenment.org/core/elementary.git/commit/?id=24b582462cb22be8c50fbfcb4648fb251a9d48d0
commit 24b582462cb22be8c50fbfcb4648fb251a9d48d0 Author: Daniel Juyung Seo <[email protected]> Date: Sun Mar 23 21:25:40 2014 +0900 gengrid: Fixed annoying gengrid scrolling issue when focus is back to gengrid. This patch is a gengrid version of genlist patch cc827fef6. Now, gengrid does not autoscroll to last focused/selected item when the gengrid is focused. It tries to find the nearest visible item instead of the last focused/selected item. --- src/lib/elm_gengrid.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/lib/elm_gengrid.c b/src/lib/elm_gengrid.c index 177d6b5..3895be1 100644 --- a/src/lib/elm_gengrid.c +++ b/src/lib/elm_gengrid.c @@ -2106,6 +2106,52 @@ _elm_gengrid_smart_event(Eo *obj, void *_pd, va_list *list) if (ret) *ret = EINA_TRUE; } +/* + * This function searches the nearest visible item based on the given item. + * If the given item is in the gengrid viewport, this returns the given item. + * Or this searches the realized items and checks the nearest fully visible item + * according to the given item's position. + */ +static Elm_Object_Item * +_elm_gengrid_nearest_visible_item_get(Evas_Object *obj, Elm_Object_Item *it) +{ + Evas_Coord vx = 0, vy = 0, vw = 0, vh = 0; // gengrid viewport geometry + Evas_Coord ix = 0, iy = 0, iw = 0, ih = 0; // given item geometry + Evas_Coord cx = 0, cy = 0, cw = 0, ch = 0; // candidate item geometry + Eina_List *item_list = NULL, *l = NULL; + Elm_Object_Item *item = NULL; + ELM_GENGRID_DATA_GET(obj, sd); + + if (!it) return NULL; + + evas_object_geometry_get(sd->pan_obj, &vx, &vy, &vw, &vh); + evas_object_geometry_get(VIEW(it), &ix, &iy, &iw, &ih); // FIXME: check if the item is realized or not + + if (ELM_RECTS_INCLUDE(vx, vy, vw, vh, ix, iy, iw, ih)) + return it; + + item_list = elm_gengrid_realized_items_get(obj); + if (iy < vy) + { + EINA_LIST_FOREACH(item_list, l, item) + { + evas_object_geometry_get(VIEW(item), &cx, &cy, &cw, &ch); + if (ELM_RECTS_INCLUDE(vx, vy, vw, vh, cx, cy, cw, ch)) + return item; + } + } + else + { + EINA_LIST_REVERSE_FOREACH(item_list, l, item) + { + evas_object_geometry_get(VIEW(item), &cx, &cy, &cw, &ch); + if (ELM_RECTS_INCLUDE(vx, vy, vw, vh, cx, cy, cw, ch)) + return item; + } + } + return NULL; +} + static void _elm_gengrid_smart_on_focus(Eo *obj, void *_pd EINA_UNUSED, va_list *list) { @@ -2137,10 +2183,15 @@ _elm_gengrid_smart_on_focus(Eo *obj, void *_pd EINA_UNUSED, va_list *list) if (it) { - if (is_sel) - elm_gengrid_item_selected_set(it, EINA_TRUE); - else - elm_object_item_focus_set(it, EINA_TRUE); + it = _elm_gengrid_nearest_visible_item_get(obj, it); + if (it) + { + if (is_sel) + elm_gengrid_item_selected_set(it, EINA_TRUE); + else + elm_object_item_focus_set(it, EINA_TRUE); + _elm_widget_focus_highlight_start(obj); + } } } else --
