forked from enlightenment/efl
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 <sh10233.lee@samsung.com> Differential Revision: https://phab.enlightenment.org/D8703
This commit is contained in:
parent
404dcc290b
commit
df089ac5ff
|
@ -20,6 +20,29 @@
|
||||||
static void _grid_clear_internal(Eo *obj, Efl_Ui_Grid_Data *pd);
|
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 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
|
static void
|
||||||
_need_update(Efl_Ui_Grid_Data *pd)
|
_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,
|
Efl_Gfx_Entity *subobj,
|
||||||
int index)
|
int index)
|
||||||
{
|
{
|
||||||
|
int clamp = clamp_index(pd, index);
|
||||||
|
index = index_adjust(pd, index);
|
||||||
if (!_grid_item_process(obj, pd, subobj)) return EINA_FALSE;
|
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 *existing = eina_list_nth(pd->items, index);
|
||||||
EFL_UI_GRID_ITEM_DATA_GET_OR_RETURN(subobj, pid, EINA_FALSE);
|
EFL_UI_GRID_ITEM_DATA_GET_OR_RETURN(subobj, pid, EINA_FALSE);
|
||||||
|
|
||||||
|
if (clamp == 0)
|
||||||
pd->items = eina_list_prepend_relative(pd->items, subobj, existing);
|
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
|
// Defered item's placing in group calculation
|
||||||
pid->update_begin = EINA_TRUE;
|
pid->update_begin = EINA_TRUE;
|
||||||
_need_update(pd);
|
_need_update(pd);
|
||||||
|
@ -1124,20 +1155,16 @@ _efl_ui_grid_efl_pack_linear_pack_at(Eo *obj,
|
||||||
EOLIAN static Efl_Gfx_Entity *
|
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)
|
_efl_ui_grid_efl_pack_linear_pack_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Grid_Data *pd, int index)
|
||||||
{
|
{
|
||||||
|
index = index_adjust(pd, index);
|
||||||
return eina_list_nth(pd->items, index);
|
return eina_list_nth(pd->items, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
EOLIAN static Efl_Gfx_Entity *
|
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)
|
_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);
|
Efl_Gfx_Entity *target = eina_list_nth(pd->items, index);
|
||||||
pd->items = eina_list_remove(pd->items, target);
|
_grid_item_unpack_internal(obj, pd, target);
|
||||||
/*
|
|
||||||
if (after)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
_need_update(pd);
|
_need_update(pd);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue