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 15541a9189395a1d4135139986953dd8c3a404d1
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 10 21:47:20 2026 -0600

    elementary: average_model: the first measured row changes the estimate
    
    A view gives the rows nobody measured the size it has for them until a
    row was measured, and the average after. When the first one measured is
    0 high the average stays 0, the revision stayed too, and a list that
    kept the stand-in in its cache never asked again. Whether anything was
    measured is now part of what the revision counts, and the properties
    changed event with it.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c | 15 +++++--
 src/tests/elementary/efl_ui_model.c       | 68 +++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index 4d4df65c52..be578a4111 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -32,10 +32,14 @@ struct _Efl_Ui_Average_Model_Data
    // the number of times it changed (what a view that estimates with it keeps)
    unsigned long long average;
    unsigned int revision;
-
    // 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;
+
+   // Whether any row was told when it was: a view gives the rows nobody measured
+   // the size it has for them (not the average) until one was, so it changes
+   // what they are even when the average is the 0 it was
+   Eina_Bool known : 1;
 };
 
 typedef struct _Efl_Ui_Average_Model_Update Efl_Ui_Average_Model_Update;
@@ -53,14 +57,19 @@ struct _Efl_Ui_Average_Model_Update
 };
 
 // What an item is estimated to be, from what was told: not a number of its own,
-// a change of it is what makes the estimates of the others change.
+// a change of it is what makes the estimates of the others change. That is a
+// change of the average, and the first row that is told (or the last one that
+// leaves), as the rows nobody measured are then what the average is and not
+// what the view had for them.
 static Eina_Bool
 _efl_ui_average_model_revise(Efl_Ui_Average_Model_Data *root)
 {
    unsigned long long average = root->total.hseen ? root->total.height / root->total.hseen : 0;
+   Eina_Bool known = !!root->total.hseen;
 
-   if (average == root->average) return EINA_FALSE;
+   if ((average == root->average) && (known == root->known)) return EINA_FALSE;
    root->average = average;
+   root->known = known;
    root->revision++;
    return EINA_TRUE;
 }
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 6bb4c48f5d..d78cbe6a9e 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -865,6 +865,73 @@ EFL_START_TEST(efl_ui_average_model_root_deleted)
 }
 EFL_END_TEST
 
+static void
+_total_height_changed(void *data, const Efl_Event *ev)
+{
+   Efl_Model_Property_Event *pev = ev->info;
+   unsigned int *count = data;
+   Eina_Array_Iterator it;
+   const char *property;
+   unsigned int i;
+
+   if (!pev || !pev->changed_properties) return;
+   EINA_ARRAY_ITER_NEXT(pev->changed_properties, i, property, it)
+     if (eina_streq(property, "total.height")) (*count)++;
+}
+
+// The first row that is measured changes what the rows nobody measured are
+// estimated to be (from a stand-in to its height), even when that height is 0
+// and the average, a number, stays what it was: it is told of like any change.
+EFL_START_TEST(efl_ui_average_model_first_measure)
+{
+   Efl_Model *base_model, *model;
+   Many_Rows *many = calloc(1, sizeof (Many_Rows));
+   unsigned int i, loops, changes = 0, known_changes;
+
+   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);
+   efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _total_height_changed, &changes);
+   eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
+   for (loops = 0; (loops < 50) && many->count < 4; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(many->count, 4);
+   changes = 0;
+
+   _uint_set(many->rows[0], "self.height", 0);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   known_changes = changes;
+   ck_assert_uint_eq(known_changes, 1);
+
+   // (and from then on, the average of 0 staying 0 is no change)
+   _uint_set(many->rows[1], "self.height", 0);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(changes, known_changes);
+
+   for (i = 0; i < 4; i++)
+     {
+        efl_unref(many->rows[i]);
+     }
+   free(many);
+   efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _total_height_changed, &changes);
+   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)
@@ -1459,6 +1526,7 @@ efl_ui_model(TCase *tc)
    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_average_model_root_deleted);
+   tcase_add_test(tc, efl_ui_average_model_first_measure);
    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.

Reply via email to