edje: implement container api

the container api returns the number of added swallows.
the content iterator returns a iterator over all swallowed objects.

The reason this is only for swallows is that the interface explicitly
mentions UI elements at the count. Since i am believing the the result
of the count operation should mirror to the amount of elements in the
iterator, the iterator only returns swallowed objects.

ref T5719

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D7748
This commit is contained in:
Marcel Hollerbach 2019-01-24 10:18:01 +01:00
parent 0b0ff33f2f
commit 1763afb391
3 changed files with 112 additions and 0 deletions

View File

@ -3397,6 +3397,82 @@ _efl_canvas_layout_efl_container_content_remove(Eo *obj EINA_UNUSED, Edje *ed, E
return EINA_TRUE;
}
typedef struct _Content_Part_Iterator Content_Part_Iterator;
struct _Content_Part_Iterator
{
Eina_Iterator iterator;
Eo *object;
Edje *ed;
unsigned index;
};
static Eina_Bool
_content_part_iterator_next(Content_Part_Iterator *it, void **data)
{
for (; it->index < it->ed->table_parts_size; it->index++)
{
Edje_Real_Part *rp = it->ed->table_parts[it->index];
if (rp->part && rp->part->type == EDJE_PART_TYPE_SWALLOW)
{
if (data) *data = (void*) rp->typedata.swallow->swallowed_object;
it->index++;
return EINA_TRUE;
}
}
return EINA_FALSE;
}
static Eo *
_content_part_iterator_get_container(Content_Part_Iterator *it)
{
return it->object;
}
static void
_content_part_iterator_free(Content_Part_Iterator *it)
{
free(it);
}
EOLIAN Eina_Iterator*
_efl_canvas_layout_efl_container_content_iterate(Eo *obj, Edje *ed)
{
Content_Part_Iterator *it;
it = calloc(1, sizeof(*it));
if (!it) return NULL;
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
it->iterator.version = EINA_ITERATOR_VERSION;
it->iterator.next = FUNC_ITERATOR_NEXT(_content_part_iterator_next);
it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_content_part_iterator_get_container);
it->iterator.free = FUNC_ITERATOR_FREE(_content_part_iterator_free);
it->object = obj;
it->ed = ed;
it->index = 0;
return &it->iterator;
}
EOLIAN int
_efl_canvas_layout_efl_container_content_count(Eo *obj EINA_UNUSED, Edje *pd)
{
Edje_Real_Part *rp;
int result = 0;
for (int i = 0; i < pd->table_parts_size; ++i)
{
rp = pd->table_parts[i];
if (rp->part && rp->part->type == EDJE_PART_TYPE_SWALLOW)
result ++;
}
return result;
}
Efl_Gfx_Entity *
_edje_efl_content_content_get(Edje *ed, const char *part)
{

View File

@ -116,6 +116,8 @@ class Efl.Canvas.Layout extends Efl.Canvas.Group implements Efl.File, Efl.Contai
Efl.File.load_error { get; }
Efl.File.mmap { get; set; }
Efl.Container.content_remove;
Efl.Container.content_iterate;
Efl.Container.content_count;
Efl.Part.part_get; [[Returns @Efl.Canvas.Layout_Part]]
Efl.Observer.update;
Efl.Player.playable { get; }

View File

@ -123,6 +123,39 @@ EFL_START_TEST(edje_test_swallows_eoapi)
}
EFL_END_TEST
EFL_START_TEST(edje_test_swallows_container_api)
{
Evas *evas = _setup_evas();
Evas_Object *ly, *o1;
ly = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas);
fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));
fail_unless(edje_object_part_exists(ly, "swallow"));
o1 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
fail_if(!efl_content_set(efl_part(ly, "swallow"), o1));
ck_assert_int_eq(efl_content_count(ly), 1);
{
Eina_Array *arr = eina_array_new(1);
Eina_Iterator *iter = efl_content_iterate(ly);
Eo *content;
EINA_ITERATOR_FOREACH(iter, content)
{
eina_array_push(arr, content);
}
ck_assert_int_eq(eina_array_count(arr), 1);
ck_assert_ptr_eq(eina_array_data_get(arr, 0), o1);
eina_array_free(arr);
}
evas_free(evas);
}
EFL_END_TEST
void edje_test_swallow(TCase *tc)
{
@ -130,4 +163,5 @@ void edje_test_swallow(TCase *tc)
tcase_add_test(tc, edje_test_swallows_lifetime);
tcase_add_test(tc, edje_test_swallows_invalidate);
tcase_add_test(tc, edje_test_swallows_eoapi);
tcase_add_test(tc, edje_test_swallows_container_api);
}