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)
{
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