From a80bd0fd3b835095d1a6347c7df14b551468538e Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Wed, 24 Apr 2019 19:10:12 +0200 Subject: [PATCH] efl_ui_grid: implement index behaviour of efl_pack efl_pack defines behaviour for indexes greater and smaller than 0 and the actaul size of items. With this commit the defined lange -count <-> count -1 now works as expected. Reviewed-by: SangHyeon Jade Lee Differential Revision: https://phab.enlightenment.org/D8703 --- src/lib/elementary/efl_ui_grid.c | 45 ++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/lib/elementary/efl_ui_grid.c b/src/lib/elementary/efl_ui_grid.c index ebc1a5a..8e0e0a3 100644 --- a/src/lib/elementary/efl_ui_grid.c +++ b/src/lib/elementary/efl_ui_grid.c @@ -20,6 +20,29 @@ static void _grid_clear_internal(Eo *obj, Efl_Ui_Grid_Data *pd); static void _grid_item_unpack_internal(Eo *obj, Efl_Ui_Grid_Data *pd, Efl_Ui_Grid_Item *item); +static int +clamp_index(Efl_Ui_Grid_Data *pd, int index) +{ + if (index < ((int)eina_list_count(pd->items)) * -1) + return -1; + else if (index > (int)eina_list_count(pd->items) - 1) + return 1; + return 0; +} + +static int +index_adjust(Efl_Ui_Grid_Data *pd, int index) +{ + int c = eina_list_count(pd->items); + if (index < c * -1) + return 0; + else if (index > c - 1) + return c - 1; + else if (index < 0) + return index + c; + return index; +} + static void _need_update(Efl_Ui_Grid_Data *pd) { @@ -1110,11 +1133,19 @@ _efl_ui_grid_efl_pack_linear_pack_at(Eo *obj, Efl_Gfx_Entity *subobj, int index) { + int clamp = clamp_index(pd, index); + index = index_adjust(pd, index); if (!_grid_item_process(obj, pd, subobj)) return EINA_FALSE; Efl_Ui_Grid_Item *existing = eina_list_nth(pd->items, index); EFL_UI_GRID_ITEM_DATA_GET_OR_RETURN(subobj, pid, EINA_FALSE); - pd->items = eina_list_prepend_relative(pd->items, subobj, existing); + if (clamp == 0) + pd->items = eina_list_prepend_relative(pd->items, subobj, existing); + else if (clamp == 1) + pd->items = eina_list_append(pd->items, subobj); + else + pd->items = eina_list_prepend(pd->items, subobj); + // Defered item's placing in group calculation pid->update_begin = EINA_TRUE; _need_update(pd); @@ -1124,20 +1155,16 @@ _efl_ui_grid_efl_pack_linear_pack_at(Eo *obj, EOLIAN static Efl_Gfx_Entity * _efl_ui_grid_efl_pack_linear_pack_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Grid_Data *pd, int index) { - return eina_list_nth(pd->items, index); + index = index_adjust(pd, index); + return eina_list_nth(pd->items, index); } EOLIAN static Efl_Gfx_Entity * _efl_ui_grid_efl_pack_linear_pack_unpack_at(Eo *obj EINA_UNUSED, Efl_Ui_Grid_Data *pd, int index) { + index = index_adjust(pd, index); Efl_Gfx_Entity *target = eina_list_nth(pd->items, index); - pd->items = eina_list_remove(pd->items, target); - /* - if (after) - { - } - else - */ + _grid_item_unpack_internal(obj, pd, target); _need_update(pd); return target; } -- 2.7.4