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 3da5a8ba1f6bdb3d3754e5c2ad71e9b4b9fb8d82
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 20:24:38 2026 -0600
elementary: average_model: a shrinking row lowers the total
The difference between what a row is now and what it was is unsigned, so
a row that went from 50 to 30 added 4294967276 to the total. The check
on removal then hid it by only taking the row out when the total was big
enough. The difference is now signed, and a total that cannot hold the
row that leaves is logged and started again instead of being kept.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_average_model.c | 16 ++++++++--
src/tests/elementary/efl_ui_model.c | 49 +++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index a258b09c10..43055531bb 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -56,7 +56,8 @@ _efl_ui_average_model_update(Eo *obj EINA_UNUSED, void *data, const Eina_Value v
if (!eina_value_uint_convert(&v, &now))
goto on_error;
- *(request->total) += now - request->previous;
+ // (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:
@@ -130,8 +131,17 @@ _efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
_efl_ui_average_model_forgotten_check(event->object, pd);
if (!_efl_ui_exact_model_removed_height_get(event->object, &height)) return;
- if (pd->total.height >= height) pd->total.height -= height;
- if (pd->total.hseen) pd->total.hseen--;
+ // 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)
+ {
+ ERR("The average of the heights does not hold the row that was removed: "
+ "starting it again.");
+ memset(&pd->total, 0, sizeof (pd->total));
+ return;
+ }
+ pd->total.height -= height;
+ pd->total.hseen--;
}
static Eina_Future *
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 0d5c534bca..d787fcb613 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -705,6 +705,54 @@ EFL_START_TEST(efl_ui_average_model_remove)
}
EFL_END_TEST
+// A row that is measured again with a smaller size makes the average go
+// down, and is not a row that wrapped the total around.
+EFL_START_TEST(efl_ui_average_model_shrink)
+{
+ Efl_Model *base_model, *model;
+ Many_Rows *many = calloc(1, sizeof (Many_Rows));
+ unsigned int loops;
+
+ base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+ efl_model_child_add(base_model);
+ efl_model_child_add(base_model);
+ 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, 3), _many_rows_then, many, NULL);
+ for (loops = 0; (loops < 50) && many->count < 3; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(many->count, 3);
+
+ // (the average is over the rows that were told, and is for all of them)
+ _uint_set(many->rows[0], "self.height", 50);
+ _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"), 90);
+
+ _uint_set(many->rows[0], "self.height", 30);
+ for (loops = 0; loops < 8; loops++)
+ {
+ ecore_main_loop_iterate();
+ }
+ ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 60);
+
+ for (loops = 0; loops < 3; loops++)
+ {
+ efl_unref(many->rows[loops]);
+ }
+ free(many);
+ 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)
@@ -1072,6 +1120,7 @@ efl_ui_model(TCase *tc)
tcase_add_test(tc, efl_ui_homogeneous_model_test);
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_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.