forked from enlightenment/efl
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
This commit is contained in:
parent
eaeb96cc3d
commit
2e41a13166
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue