diff options
author | Cedric BAIL <cedric.bail@free.fr> | 2020-01-24 11:01:03 -0800 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2020-01-31 10:11:39 -0800 |
commit | 2e41a13166789670602bc005a7e6a9f0815ecd77 (patch) | |
tree | d8fb7f39ce1eb441830e80a80bf704c24af00f54 | |
parent | eaeb96cc3d11b6f107aef822ef6f0fbae5ceaa03 (diff) | |
download | efl-2e41a13166789670602bc005a7e6a9f0815ecd77.tar.gz |
efl: add Efl.Model.Children_Index_Get.
This allow for fetching random children in a model. A simple fallback is
provided by Efl.Loop_Model that will allow all model to provide this
feature in a non optimized way. Later on this can be speeded up.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de>
Differential Revision: https://phab.enlightenment.org/D11185
-rw-r--r-- | src/lib/ecore/efl_loop_model.c | 36 | ||||
-rw-r--r-- | src/lib/ecore/efl_loop_model.eo | 1 | ||||
-rw-r--r-- | src/lib/efl/interfaces/efl_model.eo | 12 |
3 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/ecore/efl_loop_model.c b/src/lib/ecore/efl_loop_model.c index d3e52a63fb..88d8574285 100644 --- a/src/lib/ecore/efl_loop_model.c +++ b/src/lib/ecore/efl_loop_model.c @@ -108,6 +108,42 @@ _efl_loop_model_efl_model_property_ready_get(Eo *obj, void *pd EINA_UNUSED, cons return efl_future_then(obj, f); } +static Eina_Value +_unpack_from_array(void *data EINA_UNUSED, Eina_Value v, const Eina_Future *f EINA_UNUSED) +{ + Eo *object = NULL; + + if (eina_value_type_get(&v) == EINA_VALUE_TYPE_ERROR) return v; + if (eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY) return eina_value_error_init(EINVAL); + if (eina_value_array_count(&v) != 1) return eina_value_error_init(EINVAL); + + eina_value_array_get(&v, 0, &object); + + return eina_value_object_init(object); +} + +static Eina_Future * +_efl_loop_model_efl_model_children_index_get(Eo *obj, void *pd EINA_UNUSED, Eina_Iterator *indexes) +{ + Eina_Future *r; + Eina_Array futures; + unsigned int idx; + + eina_array_step_set(&futures, sizeof (Eina_Array), 8); + + EINA_ITERATOR_FOREACH(indexes, idx) + eina_array_push(&futures, eina_future_then(efl_model_children_slice_get(obj, idx, 1), _unpack_from_array, NULL)); + eina_iterator_free(indexes); + + r = efl_future_then(obj, eina_future_all_iterator(eina_array_iterator_new(&futures)), + .success = _efl_future_all_repack, + .success_type = EINA_VALUE_TYPE_ARRAY); + + eina_array_flush(&futures); + + return r; +} + static void _noref_death(void *data EINA_UNUSED, const Efl_Event *event) { diff --git a/src/lib/ecore/efl_loop_model.eo b/src/lib/ecore/efl_loop_model.eo index 2285b56f1b..06af337ecf 100644 --- a/src/lib/ecore/efl_loop_model.eo +++ b/src/lib/ecore/efl_loop_model.eo @@ -20,5 +20,6 @@ abstract Efl.Loop_Model extends Efl.Loop_Consumer implements Efl.Model Efl.Object.invalidate; Efl.Model.property_ready_get; Efl.Model.property { get; set; } + Efl.Model.children_index_get; } } diff --git a/src/lib/efl/interfaces/efl_model.eo b/src/lib/efl/interfaces/efl_model.eo index ee04879f68..e669d50ade 100644 --- a/src/lib/efl/interfaces/efl_model.eo +++ b/src/lib/efl/interfaces/efl_model.eo @@ -141,6 +141,18 @@ interface Efl.Model /* XXX: is this right? */ return: future<array<Efl.Object>>; [[Array of children]] } + children_index_get { + [[Get children as specified by iterator. + + Provided index have to be between 0 and @.children_count.get. + + This function might rely on @.children_slice_get as a fallback. + ]] + params { + @in indices: iterator<uint>; [[Indices of the requested children.]] + } + return: future<array<Efl.Object>>; [[Array of children]] + } @property children_count { [[Number of children. |