This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 3f0a944bc60e37054e841215ff47bbcfdc189951
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:39:11 2026 -0600
elementary: average_model: drop pending heights of a row that leaves
The height a row is told is added to the average in a later turn of the
loop, while the Exact_Model takes it out as soon as the row leaves. A
row measured and removed in the same turn then left a total and a count
with no row behind them. The updates not yet added are now kept, the
ones of a row that leaves (or of sizes that were all forgotten) are
dropped, and only what was already added is taken out of the totals.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_average_model.c | 72 +++++++++++++++++++++++++------
src/lib/elementary/efl_ui_exact_model.c | 5 ---
src/lib/elementary/elm_priv.h | 4 ++
src/tests/elementary/efl_ui_model.c | 65 ++++++++++++++++++++++++++++
4 files changed, 128 insertions(+), 18 deletions(-)
diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index 43055531bb..b0410568f3 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -26,6 +26,10 @@ struct _Efl_Ui_Average_Model_Data
// The times the Exact_Model gave up its sizes that this has seen
unsigned int forgotten;
+
+ // What a row was told that has not been added to the totals yet (it is
+ // added when the loop gets to it), for the row that leaves before that.
+ Eina_List *pending;
};
typedef struct _Efl_Ui_Average_Model_Update Efl_Ui_Average_Model_Update;
@@ -33,17 +37,28 @@ struct _Efl_Ui_Average_Model_Update
{
unsigned long long *total;
unsigned long long *seen;
+ Efl_Ui_Average_Model_Data *root;
+ Eo *row;
unsigned int previous;
+ unsigned int now;
+ // The row left, or the sizes were forgotten, before it was added: there is no row to add it to
+ Eina_Bool dropped : 1;
};
// Totals of what the Exact_Model says is not kept any more are of no use
static void
_efl_ui_average_model_forgotten_check(const Eo *obj, Efl_Ui_Average_Model_Data *root)
{
+ Efl_Ui_Average_Model_Update *update;
unsigned int forgotten = _efl_ui_exact_model_forgotten_get(obj);
+ Eina_List *l;
if (root->forgotten == forgotten) return;
root->forgotten = forgotten;
+ EINA_LIST_FOREACH(root->pending, l, update)
+ {
+ update->dropped = EINA_TRUE;
+ }
memset(&root->total, 0, sizeof (root->total));
}
@@ -53,33 +68,46 @@ _efl_ui_average_model_update(Eo *obj EINA_UNUSED, void *data, const Eina_Value v
Efl_Ui_Average_Model_Update *request = data;
unsigned int now;
- if (!eina_value_uint_convert(&v, &now))
- goto on_error;
+ // (a row that left is not in the model: what it was told is not averaged)
+ if (request->dropped || !eina_value_uint_convert(&v, &now))
+ return v;
// (a row that shrinks takes from the total: the difference is signed)
*(request->total) += (long long) now - (long long) request->previous;
if (request->seen) *(request->seen) += 1;
- on_error:
return v;
}
static void
_efl_ui_average_model_clean(Eo *obj, void *data, const Eina_Future *dead_future EINA_UNUSED)
{
- free(data);
+ Efl_Ui_Average_Model_Update *update = data;
+
+ update->root->pending = eina_list_remove(update->root->pending, update);
+ free(update);
efl_unref(obj);
}
static Eina_Future *
-_efl_ui_average_model_prepare(Eo *obj,
- unsigned long long *total, unsigned long long *seen,
+_efl_ui_average_model_prepare(Eo *obj, Efl_Ui_Average_Model_Data *root,
const char *property, Eina_Value *value)
{
+ unsigned long long *total = &root->total.height;
+ unsigned long long *seen = &root->total.hseen;
Efl_Ui_Average_Model_Update *update;
Eina_Value *previous;
Eina_Future *f;
+ unsigned int now;
+
+ // What the Exact_Model refuses is not one that will be averaged
+ if (!eina_value_uint_convert(value, &now) || (now & EFL_UI_EXACT_MODEL_MEASURED) ||
+ (efl_composite_model_index_get(obj) == 0xFFFFFFFF))
+ {
+ return efl_model_property_set(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS),
+ property, value);
+ }
update = calloc(1, sizeof (Efl_Ui_Average_Model_Update));
if (!update) return efl_loop_future_rejected(obj, ENOMEM);
@@ -101,6 +129,9 @@ _efl_ui_average_model_prepare(Eo *obj,
eina_value_free(previous);
update->total = total;
+ update->now = now;
+ update->root = root;
+ update->row = obj;
// As we are operating asynchronously and we want to make sure that the object
// survive until the transaction is commited, we will ref the object here
@@ -113,6 +144,7 @@ _efl_ui_average_model_prepare(Eo *obj,
// We have to make the change after we fetch the old value, otherwise, well, no old value left
f = efl_model_property_set(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS), property, value);
+ root->pending = eina_list_append(root->pending, update);
return efl_future_then(obj, f,
.success = _efl_ui_average_model_update,
.free = _efl_ui_average_model_clean,
@@ -127,13 +159,29 @@ static void
_efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
{
Efl_Ui_Average_Model_Data *pd = data;
- unsigned int height;
+ const Efl_Model_Children_Event *ev = event->info;
+ Efl_Ui_Average_Model_Update *update;
+ Eina_List *l;
+ long long pending = 0, height;
+ unsigned int removed;
+ Eina_Bool seen = EINA_TRUE;
_efl_ui_average_model_forgotten_check(event->object, pd);
- if (!_efl_ui_exact_model_removed_height_get(event->object, &height)) return;
+ // What the row was told and the loop did not get to yet is in what the
+ // Exact_Model took out, but not yet in what is here
+ EINA_LIST_FOREACH(pd->pending, l, update)
+ {
+ if ((update->row != ev->child) || update->dropped) continue;
+ pending += (long long) update->now - (long long) update->previous;
+ if (update->seen) seen = EINA_FALSE;
+ update->dropped = EINA_TRUE;
+ }
+ if (!_efl_ui_exact_model_removed_height_get(event->object, &removed)) return;
+ height = (long long) removed - pending;
// What the Exact_Model took out was added here, so there is enough to take out.
// If there is not, the totals are wrong and are of no use any more.
- if ((pd->total.height < height) || !pd->total.hseen)
+ if ((height < 0) || (pd->total.height < (unsigned long long) height) ||
+ (seen && !pd->total.hseen))
{
ERR("The average of the heights does not hold the row that was removed: "
"starting it again.");
@@ -141,7 +189,7 @@ _efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
return;
}
pd->total.height -= height;
- pd->total.hseen--;
+ if (seen) pd->total.hseen--;
}
static Eina_Future *
@@ -162,9 +210,7 @@ _efl_ui_average_model_efl_model_property_set(Eo *obj, Efl_Ui_Average_Model_Data
if (eina_streq(property, _efl_model_property_selfh))
{
_efl_ui_average_model_forgotten_check(efl_parent_get(obj), pd->parent);
- f = _efl_ui_average_model_prepare(obj, &pd->parent->total.height,
- &pd->parent->total.hseen,
- property, value);
+ f = _efl_ui_average_model_prepare(obj, pd->parent, property, value);
}
end:
diff --git a/src/lib/elementary/efl_ui_exact_model.c b/src/lib/elementary/efl_ui_exact_model.c
index d151fa187b..7f0a02fe28 100644
--- a/src/lib/elementary/efl_ui_exact_model.c
+++ b/src/lib/elementary/efl_ui_exact_model.c
@@ -14,11 +14,6 @@
#define EFL_UI_EXACT_MODEL_CONTENT 1024
#define EFL_UI_EXACT_MODEL_CONTENT_LENGTH (EFL_UI_EXACT_MODEL_CONTENT * sizeof (unsigned int))
-// A size that was set is stored with this bit on. A slot of zeros (what the
-// storage starts as, and what a slot that was never written expands to) is
-// therefore a row nobody measured, which is not a row of size 0.
-#define EFL_UI_EXACT_MODEL_MEASURED 0x80000000u
-
// For now only vertical logic is implemented. Horizontal list and grid are not supported.
typedef struct _Efl_Ui_Exact_Model_Data Efl_Ui_Exact_Model_Data;
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index 3dbf2fbd3e..91cc874550 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -657,6 +657,10 @@ struct _Elm_Module
(the Select_Model, the Homogeneous_Model, a Boolean_Model...): the sizes
are kept under the index of the Exact_Model, which another model may
number differently. _find answers NULL for those. */
+// A size that was set is stored with this bit on. A slot of zeros (what the
+// storage starts as, and what a slot that was never written expands to) is
+// therefore a row nobody measured, which is not a row of size 0.
+#define EFL_UI_EXACT_MODEL_MEASURED 0x80000000u
Efl_Model *_efl_ui_exact_model_find(Efl_Model *model);
Eina_Bool _efl_ui_exact_model_row_size_get(Efl_Model *exact,
unsigned int index,
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index d787fcb613..100bd731bb 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -753,6 +753,70 @@ EFL_START_TEST(efl_ui_average_model_shrink)
}
EFL_END_TEST
+// A row that is measured and removed before the average heard of the
+// measure is not one that is averaged over, when it finally does.
+EFL_START_TEST(efl_ui_average_model_remove_pending)
+{
+ Efl_Model *base_model, *model;
+ Many_Rows *many = calloc(1, sizeof (Many_Rows));
+ Many_Rows *base_rows = calloc(1, sizeof (Many_Rows));
+ unsigned int i, loops;
+
+ base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+ for (i = 0; i < 4; i++)
+ {
+ efl_model_child_add(base_model);
+ }
+ model = efl_add_ref(EFL_UI_AVERAGE_MODEL_CLASS, efl_main_loop_get(),
+ efl_ui_view_model_set(efl_added, base_model));
+ ck_assert(!!model);
+ eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
+ eina_future_then(efl_model_children_slice_get(base_model, 0, 4), _many_rows_then, base_rows, NULL);
+ for (loops = 0; (loops < 50) && (many->count < 4 || base_rows->count < 4); loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(many->count, 4);
+ ck_assert_uint_eq(base_rows->count, 4);
+
+ // Measured and removed in the same turn: nothing was ever averaged
+ _uint_set(many->rows[0], "self.height", 40);
+ efl_model_child_del(base_model, base_rows->rows[0]);
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 0);
+
+ // And the ones that are there still do average
+ _uint_set(many->rows[1], "self.height", 10);
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 30);
+
+ // A row that was counted, measured again and removed in the same turn
+ _uint_set(many->rows[1], "self.height", 25);
+ efl_model_child_del(base_model, base_rows->rows[1]);
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 0);
+
+ for (i = 0; i < 4; i++)
+ {
+ efl_unref(many->rows[i]);
+ efl_unref(base_rows->rows[i]);
+ }
+ free(many);
+ free(base_rows);
+ efl_unref(model);
+ efl_unref(base_model);
+}
+EFL_END_TEST
+
// A row that was removed has no place in the model any more: what is told
// to it is not for the row that is now at the index it had.
EFL_START_TEST(efl_ui_exact_model_removed_row_write)
@@ -1121,6 +1185,7 @@ efl_ui_model(TCase *tc)
tcase_add_test(tc, efl_ui_average_model_test);
tcase_add_test(tc, efl_ui_average_model_remove);
tcase_add_test(tc, efl_ui_average_model_shrink);
+ tcase_add_test(tc, efl_ui_average_model_remove_pending);
tcase_add_test(tc, efl_ui_exact_model_test);
tcase_add_test(tc, efl_ui_exact_model_many_rows);
tcase_add_test(tc, efl_ui_exact_model_insert_remove);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.