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 a423ebba89ed9893038a5dff9e21a9179c9fff44
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:34:40 2026 -0600

    elementary: average_model: a row that leaves is taken out of the average
    
    The totals the average is made of (the sum of the heights that were told
    and how many rows were told one) only ever rose, so a row that left kept
    its height in them and still counted as seen, and the average of what is
    left was wrong for good. That was the FIXME at the top of the file.
    
    The Exact_Model, which moves the sizes before anyone else is told of a
    removal, now keeps what the removed row had been told, and the
    Average_Model takes it out when it is told of the removal (after the
    Exact_Model's own listener, before the others). It also counts the times
    the Exact_Model had to give all of its sizes up, and starts again from
    nothing when it did. A row is counted as seen when it had no height
    before it is told one, not by a flag it carries, which a row that was
    removed or forgotten would keep.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c | 55 +++++++++++++++++++++-----
 src/lib/elementary/efl_ui_exact_model.c   | 38 +++++++++++++++++-
 src/lib/elementary/elm_priv.h             |  3 ++
 src/tests/elementary/efl_ui_model.c       | 66 +++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+), 11 deletions(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index 7ee9a6fb3a..a258b09c10 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -7,8 +7,11 @@
 
 // This class rely on the parent class to do all the individual holding of value,
 // it only compute the average size of an item and answer for that property alone.
-
-// FIXME: handle child being removed
+//
+// What an average is over (the heights that were told, and how many rows were
+// told one) is kept here, and follows a row that is removed: the Exact_Model says
+// what the row had, once it has moved its own sizes. It also says when it had
+// to give all its sizes up, and then there is nothing left to average.
 typedef struct _Efl_Ui_Average_Model_Data Efl_Ui_Average_Model_Data;
 struct _Efl_Ui_Average_Model_Data
 {
@@ -21,8 +24,8 @@ struct _Efl_Ui_Average_Model_Data
       unsigned long long hseen;
    } total;
 
-   Eina_Bool wseen : 1;
-   Eina_Bool hseen : 1;
+   // The times the Exact_Model gave up its sizes that this has seen
+   unsigned int forgotten;
 };
 
 typedef struct _Efl_Ui_Average_Model_Update Efl_Ui_Average_Model_Update;
@@ -33,6 +36,17 @@ struct _Efl_Ui_Average_Model_Update
    unsigned int previous;
 };
 
+// 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)
+{
+   unsigned int forgotten = _efl_ui_exact_model_forgotten_get(obj);
+
+   if (root->forgotten == forgotten) return;
+   root->forgotten = forgotten;
+   memset(&root->total, 0, sizeof (root->total));
+}
+
 static Eina_Value
 _efl_ui_average_model_update(Eo *obj EINA_UNUSED, void *data, const Eina_Value v)
 {
@@ -78,13 +92,14 @@ _efl_ui_average_model_prepare(Eo *obj,
         if (!eina_value_error_convert(previous, &err))
           goto on_error;
         if (err != EAGAIN) goto on_error;
+        // (a row that was not measured is one more that was seen once it is)
+        update->seen = seen;
      }
    else if (!eina_value_uint_convert(previous, &update->previous))
      goto on_error;
    eina_value_free(previous);
 
    update->total = total;
-   update->seen = seen;
 
    // 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
@@ -107,6 +122,18 @@ _efl_ui_average_model_prepare(Eo *obj,
    return efl_loop_future_rejected(obj, EFL_MODEL_ERROR_INCORRECT_VALUE);
 }
 
+static void
+_efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
+{
+   Efl_Ui_Average_Model_Data *pd = data;
+   unsigned int height;
+
+   _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--;
+}
+
 static Eina_Future *
 _efl_ui_average_model_efl_model_property_set(Eo *obj, Efl_Ui_Average_Model_Data *pd, const char *property, Eina_Value *value)
 {
@@ -124,10 +151,10 @@ _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->hseen ? NULL : &pd->parent->total.hseen,
+                                          &pd->parent->total.hseen,
                                           property, value);
-        pd->hseen = EINA_TRUE;
      }
 
  end:
@@ -168,7 +195,10 @@ _efl_ui_average_model_efl_model_property_get(const Eo *obj, Efl_Ui_Average_Model
    if (t == EINA_VALUE_TYPE_UINT)
      {
         if (eina_streq(property, _efl_model_property_totalh))
-          r = _efl_ui_average_model_compute(obj, r, pd->total.height, pd->total.hseen);
+          {
+             if (!pd->parent) _efl_ui_average_model_forgotten_check(obj, pd);
+             r = _efl_ui_average_model_compute(obj, r, pd->total.height, pd->total.hseen);
+          }
         // We do not need to average the width in vertical list mode as this is done by the parent class
         /* if (eina_streq(property, _efl_model_property_totalw)) */
         /*   r = _efl_ui_average_model_compute(obj, r, pd->total.width, pd->total.wseen); */
@@ -185,7 +215,14 @@ _efl_ui_average_model_efl_object_constructor(Eo *obj, Efl_Ui_Average_Model_Data
    if (parent && efl_isa(parent, EFL_UI_AVERAGE_MODEL_CLASS))
      pd->parent = efl_data_scope_get(efl_parent_get(obj), EFL_UI_AVERAGE_MODEL_CLASS);
 
-   return efl_constructor(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS));
+   obj = efl_constructor(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS));
+   // (only the root keeps totals) After the Exact_Model's own listener, which
+   // moves the sizes and is the first, and before the ones that are told.
+   if (obj && !pd->parent)
+     efl_event_callback_priority_add(obj, EFL_MODEL_EVENT_CHILD_REMOVED,
+                                     EFL_CALLBACK_PRIORITY_BEFORE,
+                                     _efl_ui_average_model_child_removed, pd);
+   return obj;
 }
 
 #include "efl_ui_average_model.eo.c"
diff --git a/src/lib/elementary/efl_ui_exact_model.c b/src/lib/elementary/efl_ui_exact_model.c
index 9a2c72db21..d151fa187b 100644
--- a/src/lib/elementary/efl_ui_exact_model.c
+++ b/src/lib/elementary/efl_ui_exact_model.c
@@ -35,6 +35,13 @@ struct _Efl_Ui_Exact_Model_Data
       unsigned int width;
       unsigned int height;
    } total_size;
+   // What the last row that was removed had been told (for those that average), and
+   // how many times the sizes were all forgotten
+   struct {
+      unsigned int height;
+      Eina_Bool measured : 1;
+   } removed;
+   unsigned int forgotten;
 
    struct {
       unsigned int *width;
@@ -525,6 +532,7 @@ _efl_ui_exact_model_forget(Efl_Ui_Exact_Model_Data *root)
    root->compressed.height = NULL;
    root->total_size.width = 0;
    root->total_size.height = 0;
+   root->forgotten++;
 }
 
 // The sizes follow their rows when one comes or goes. The sizes are kept by
@@ -552,14 +560,16 @@ _efl_ui_exact_model_shift(Efl_Ui_Exact_Model_Data *root, unsigned int index, Ein
      {
         unsigned int w, h;
 
+        root->removed.measured = EINA_FALSE;
         if (!_efl_ui_exact_model_list_remove(root->compressed.width, index, &w) ||
             !_efl_ui_exact_model_list_remove(root->compressed.height, index, &h))
           {
              _efl_ui_exact_model_forget(root);
              return;
           }
-        if (h & EFL_UI_EXACT_MODEL_MEASURED)
-          root->total_size.height -= h & ~EFL_UI_EXACT_MODEL_MEASURED;
+        root->removed.measured = !!(h & EFL_UI_EXACT_MODEL_MEASURED);
+        root->removed.height = h & ~EFL_UI_EXACT_MODEL_MEASURED;
+        if (root->removed.measured) root->total_size.height -= root->removed.height;
         // The total width is the widest row: only when it was that one is it to be looked for again
         if ((w & EFL_UI_EXACT_MODEL_MEASURED) &&
             (w & ~EFL_UI_EXACT_MODEL_MEASURED) >= root->total_size.width)
@@ -731,6 +741,30 @@ _efl_ui_exact_model_find(Efl_Model *model)
    return model;
 }
 
+/* What the row that was last removed had been told, for a model that keeps
+   what it was told by itself: its height if it had one (true), and false if
+   it was never measured. Only meant to be asked when the removal is told, which
+   is after the sizes are moved. */
+Eina_Bool
+_efl_ui_exact_model_removed_height_get(const Efl_Model *exact, unsigned int *height)
+{
+   Efl_Ui_Exact_Model_Data *root = efl_data_scope_get(exact, EFL_UI_EXACT_MODEL_CLASS);
+
+   if (!root || root->parent || !root->removed.measured) return EINA_FALSE;
+   *height = root->removed.height;
+   return EINA_TRUE;
+}
+
+/* How many times every size was given up (when they could not be moved), for
+   a model that keeps what it was told by itself to do the same. */
+unsigned int
+_efl_ui_exact_model_forgotten_get(const Efl_Model *exact)
+{
+   Efl_Ui_Exact_Model_Data *root = efl_data_scope_get(exact, EFL_UI_EXACT_MODEL_CLASS);
+
+   return (root && !root->parent) ? root->forgotten : 0;
+}
+
 /* The size of a row as it was told to the model, without the row itself:
    the view asks for rows it has let go of and cannot wait for them. */
 Eina_Bool
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index 028b2df8f6..3dbf2fbd3e 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -661,6 +661,9 @@ 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,
                                                       Eina_Size2D *size);
+Eina_Bool            _efl_ui_exact_model_removed_height_get(const Efl_Model *exact,
+                                                            unsigned int *height);
+unsigned int         _efl_ui_exact_model_forgotten_get(const Efl_Model *exact);
 Eina_Bool            _elm_web_init(const char *engine);
 
 Eo                   *_elm_atspi_bridge_get(void);
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 9a45c86f1e..0d5c534bca 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -640,6 +640,71 @@ _gone_set_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUS
    return v;
 }
 
+// A row that leaves takes its height out of what the average is over, and
+// is no longer one that was seen.
+EFL_START_TEST(efl_ui_average_model_remove)
+{
+   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);
+
+   for (i = 0; i < 3; i++)
+     {
+        _uint_set(many->rows[i], "self.height", 10 * (i + 1));
+     }
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   // 60 over 3 seen rows, for 4 rows
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 80);
+
+   // One that was seen leaves: 30 over 2, for 3
+   efl_model_child_del(base_model, base_rows->rows[2]);
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 45);
+
+   // One that was not: 30 over 2, for 2
+   efl_model_child_del(base_model, base_rows->rows[3]);
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 30);
+
+   // A row that was seen is measured again: 60 over 2, for 2
+   _uint_set(many->rows[1], "self.height", 50);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 60);
+
+   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)
@@ -1006,6 +1071,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_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