elm_gengrid: refactor duplicated code

this brings the simple selection move into a single spot
This commit is contained in:
Marcel Hollerbach 2017-06-29 18:29:24 +02:00
parent 31c11925eb
commit f046394d0f
1 changed files with 22 additions and 62 deletions

View File

@ -3196,6 +3196,17 @@ _focus_move(Evas_Object *obj, Elm_Gengrid_Data *sd, Elm_Focus_Direction dir)
return _item_focus(sd, dir); return _item_focus(sd, dir);
} }
static Eina_Bool
_get_direction(const char *str, Elm_Focus_Direction *dir)
{
if (!strcmp(str, "left")) *dir = ELM_FOCUS_LEFT;
else if (!strcmp(str, "right")) *dir = ELM_FOCUS_RIGHT;
else if (!strcmp(str, "up")) *dir = ELM_FOCUS_UP;
else if (!strcmp(str, "down")) *dir = ELM_FOCUS_DOWN;
else return EINA_FALSE;
return EINA_TRUE;
}
static Eina_Bool static Eina_Bool
_key_action_move(Evas_Object *obj, const char *params) _key_action_move(Evas_Object *obj, const char *params)
{ {
@ -3212,6 +3223,7 @@ _key_action_move(Evas_Object *obj, const char *params)
Evas_Coord page_y = 0; Evas_Coord page_y = 0;
Elm_Object_Item *it = NULL; Elm_Object_Item *it = NULL;
Eina_Bool mirrored = efl_ui_mirrored_get(obj); Eina_Bool mirrored = efl_ui_mirrored_get(obj);
Elm_Focus_Direction direction;
elm_interface_scrollable_content_pos_get(obj, &x, &y); elm_interface_scrollable_content_pos_get(obj, &x, &y);
elm_interface_scrollable_step_size_get(obj, &step_x, &step_y); elm_interface_scrollable_step_size_get(obj, &step_x, &step_y);
@ -3221,12 +3233,17 @@ _key_action_move(Evas_Object *obj, const char *params)
if (sd->reorder_mode && sd->reorder.running) return EINA_TRUE; if (sd->reorder_mode && sd->reorder.running) return EINA_TRUE;
_elm_widget_focus_auto_show(obj); _elm_widget_focus_auto_show(obj);
if ((!strcmp(dir, "left") && !mirrored) ||
(!strcmp(dir, "right") && mirrored)) if (_get_direction(dir, &direction))
{ {
if (mirrored)
{
if (direction == ELM_FOCUS_RIGHT || direction == ELM_FOCUS_LEFT)
direction = _direction_mirror(direction);
}
if (sd->reorder_mode) if (sd->reorder_mode)
{ {
return _reorder_helper(sd, ELM_FOCUS_LEFT); return _reorder_helper(sd, direction);
} }
else else
{ {
@ -3239,7 +3256,8 @@ _key_action_move(Evas_Object *obj, const char *params)
return EINA_TRUE; return EINA_TRUE;
} }
} }
return _focus_move(obj, sd, ELM_FOCUS_LEFT); return _focus_move(obj, sd, direction);
} }
else if ((!strcmp(dir, "left_multi") && !mirrored) || else if ((!strcmp(dir, "left_multi") && !mirrored) ||
(!strcmp(dir, "right_multi") && mirrored)) (!strcmp(dir, "right_multi") && mirrored))
@ -3259,26 +3277,6 @@ _key_action_move(Evas_Object *obj, const char *params)
else return EINA_FALSE; else return EINA_FALSE;
} }
} }
else if ((!strcmp(dir, "right") && !mirrored) ||
(!strcmp(dir, "left") && mirrored))
{
if (sd->reorder_mode)
{
return _reorder_helper(sd, ELM_FOCUS_RIGHT);
}
else
{
Evas_Object *next = NULL;
next = elm_object_item_focus_next_object_get(sd->focused_item,
ELM_FOCUS_RIGHT);
if (next)
{
elm_object_focus_set(next, EINA_TRUE);
return EINA_TRUE;
}
}
return _focus_move(obj, sd, ELM_FOCUS_RIGHT);
}
else if ((!strcmp(dir, "right_multi") && !mirrored) || else if ((!strcmp(dir, "right_multi") && !mirrored) ||
(!strcmp(dir, "left_multi") && mirrored)) (!strcmp(dir, "left_multi") && mirrored))
{ {
@ -3297,25 +3295,6 @@ _key_action_move(Evas_Object *obj, const char *params)
else return EINA_FALSE; else return EINA_FALSE;
} }
} }
else if (!strcmp(dir, "up"))
{
if (sd->reorder_mode)
{
return _reorder_helper(sd, ELM_FOCUS_UP);
}
else
{
Evas_Object *next = NULL;
next = elm_object_item_focus_next_object_get(sd->focused_item,
ELM_FOCUS_UP);
if (next)
{
elm_object_focus_set(next, EINA_TRUE);
return EINA_TRUE;
}
}
return _focus_move(obj, sd, ELM_FOCUS_UP);
}
else if (!strcmp(dir, "up_multi")) else if (!strcmp(dir, "up_multi"))
{ {
if (sd->horizontal) if (sd->horizontal)
@ -3333,25 +3312,6 @@ _key_action_move(Evas_Object *obj, const char *params)
else return EINA_FALSE; else return EINA_FALSE;
} }
} }
else if (!strcmp(dir, "down"))
{
if (sd->reorder_mode)
{
return _reorder_helper(sd, ELM_FOCUS_DOWN);
}
else
{
Evas_Object *next = NULL;
next = elm_object_item_focus_next_object_get(sd->focused_item,
ELM_FOCUS_DOWN);
if (next)
{
elm_object_focus_set(next, EINA_TRUE);
return EINA_TRUE;
}
}
return _focus_move(obj, sd, ELM_FOCUS_DOWN);
}
else if (!strcmp(dir, "down_multi")) else if (!strcmp(dir, "down_multi"))
{ {
if (sd->horizontal) if (sd->horizontal)