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 0fae0d9eac7c06f9d15143086cda053e52a8448d
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:46:56 2026 -0600

    elementary: exact_model: a removed row's height travels with its event
    
    The height of the row that left was kept in the model for the listeners
    of the event, and let go of by the last. An earlier listener that
    stopped the event left it there, and a removal made from a listener
    nested another and overwrote it, so that the Average_Model, which
    listens after the first, took nothing out for the row it was told of. It
    is now kept with the event that told of it (and the one that was being
    told when another began), and only given to that event.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c |  2 +-
 src/lib/elementary/efl_ui_exact_model.c   | 42 ++++++++++++----
 src/lib/elementary/elm_priv.h             |  2 +
 src/tests/elementary/efl_ui_model.c       | 80 +++++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+), 10 deletions(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index be578a4111..9486fad2f4 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -223,7 +223,7 @@ _efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
         if (update->seen) seen = EINA_FALSE;
         update->dropped = EINA_TRUE;
      }
-   if (!_efl_ui_exact_model_removed_height_get(event->object, &removed)) return;
+   if (!_efl_ui_exact_model_removed_height_get(event->object, ev, &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.
diff --git a/src/lib/elementary/efl_ui_exact_model.c b/src/lib/elementary/efl_ui_exact_model.c
index 88cf7df35d..ae8bcccc7c 100644
--- a/src/lib/elementary/efl_ui_exact_model.c
+++ b/src/lib/elementary/efl_ui_exact_model.c
@@ -32,10 +32,15 @@ struct _Efl_Ui_Exact_Model_Data
    } 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
+   // The event that told of it is what says whose it is, so that one that was
+   // stopped before the last listener, and a removal told from a listener of
+   // another, do not give what is another row's. The one that was being told
+   // when another began is kept (the removals are not nested more than that).
    struct {
+      const void *event;
       unsigned int height;
       Eina_Bool measured : 1;
-   } removed;
+   } removed, outer;
    unsigned int forgotten;
 
    struct {
@@ -581,10 +586,19 @@ _efl_ui_exact_model_forget(Efl_Ui_Exact_Model_Data *root)
 // The sizes follow their rows when one comes or goes. The sizes are kept by
 // index, and the rows after the one that came or went have another one now.
 static void
-_efl_ui_exact_model_shift(Efl_Ui_Exact_Model_Data *root, unsigned int index, Eina_Bool added)
+_efl_ui_exact_model_shift(Efl_Ui_Exact_Model_Data *root, unsigned int index, Eina_Bool added,
+                          const void *event)
 {
    unsigned char i;
 
+   if (!added)
+     {
+        // (whatever the last one told is of no use to this one, and what it was told of is kept)
+        root->outer = root->removed;
+        root->removed.measured = EINA_FALSE;
+        root->removed.event = event;
+     }
+
    // What is kept expanded in the slots has to be in the list to be moved
    for (i = 0; i < EINA_C_ARRAY_LENGTH(root->slot); i++)
      {
@@ -631,7 +645,7 @@ _efl_ui_exact_model_child_added(void *data, const Efl_Event *event)
 {
    const Efl_Model_Children_Event *ev = event->info;
 
-   _efl_ui_exact_model_shift(data, ev->index, EINA_TRUE);
+   _efl_ui_exact_model_shift(data, ev->index, EINA_TRUE, NULL);
 }
 
 static void
@@ -639,15 +653,18 @@ _efl_ui_exact_model_child_removed(void *data, const Efl_Event *event)
 {
    const Efl_Model_Children_Event *ev = event->info;
 
-   _efl_ui_exact_model_shift(data, ev->index, EINA_FALSE);
+   _efl_ui_exact_model_shift(data, ev->index, EINA_FALSE, ev);
 }
 
 static void
-_efl_ui_exact_model_child_removed_done(void *data, const Efl_Event *event EINA_UNUSED)
+_efl_ui_exact_model_child_removed_done(void *data, const Efl_Event *event)
 {
    Efl_Ui_Exact_Model_Data *root = data;
 
-   root->removed.measured = EINA_FALSE;
+   // Told of by every listener: the one that was being told when this began has the rest
+   if (root->removed.event != event->info) return;
+   root->removed = root->outer;
+   memset(&root->outer, 0, sizeof (root->outer));
 }
 
 static Eina_Future *
@@ -803,12 +820,19 @@ _efl_ui_exact_model_find(Efl_Model *model)
    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_removed_height_get(const Efl_Model *exact, const void *event,
+                                       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;
+   if (!root || root->parent) return EINA_FALSE;
+   // (what is told of is that of the event, the one that is being told or the one it was in)
+   if (root->removed.event == event && root->removed.measured)
+     *height = root->removed.height;
+   else if (root->outer.event == event && root->outer.measured)
+     *height = root->outer.height;
+   else
+     return EINA_FALSE;
    return EINA_TRUE;
 }
 
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index da3f7efaf9..d7d8b6a80a 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -661,11 +661,13 @@ struct _Elm_Module
 // 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,
                                                       Eina_Size2D *size);
 Eina_Bool            _efl_ui_exact_model_removed_height_get(const Efl_Model *exact,
+                                                            const void *event,
                                                             unsigned int *height);
 unsigned int         _efl_ui_exact_model_forgotten_get(const Efl_Model *exact);
 Eina_Bool            _efl_ui_average_model_estimate_get(const Efl_Model *exact,
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index d78cbe6a9e..9aff84ad98 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -1512,6 +1512,85 @@ EFL_START_TEST(efl_ui_average_model_forgotten_in_set)
 }
 EFL_END_TEST
 
+typedef struct _Nested_Removal Nested_Removal;
+struct _Nested_Removal
+{
+   Efl_Model *base;
+   Eo *then;
+   Eina_Bool done;
+};
+
+// (listens before the average does)
+static void
+_nested_removal(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   Nested_Removal *nr = data;
+
+   if (nr->done) return;
+   nr->done = EINA_TRUE;
+   efl_model_child_del(nr->base, nr->then);
+}
+
+// A listener that comes before the Average_Model removes another row while the
+// first is told of: what the first one had been told is still taken out.
+EFL_START_TEST(efl_ui_average_model_remove_nested)
+{
+   Efl_Model *base_model, *model;
+   Many_Rows *many = calloc(1, sizeof (Many_Rows));
+   Many_Rows *base_rows = calloc(1, sizeof (Many_Rows));
+   Nested_Removal nr = { 0 };
+   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);
+
+   _uint_set(many->rows[0], "self.height", 10);
+   _uint_set(many->rows[1], "self.height", 20);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 60);
+
+   nr.base = base_model;
+   nr.then = base_rows->rows[3];
+   efl_event_callback_priority_add(model, EFL_MODEL_EVENT_CHILD_REMOVED, -150, _nested_removal, &nr);
+   efl_model_child_del(base_model, base_rows->rows[0]);
+   ck_assert(nr.done);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   // The one told 20 is the only one left that was, for the two that are
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 40);
+   efl_event_callback_del(model, EFL_MODEL_EVENT_CHILD_REMOVED, _nested_removal, &nr);
+
+   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
+
 void
 efl_ui_model(TCase *tc)
 {
@@ -1540,4 +1619,5 @@ efl_ui_model(TCase *tc)
    tcase_add_test(tc, efl_ui_exact_model_remove_widest_alike);
    tcase_add_test(tc, efl_ui_exact_model_destroyed);
    tcase_add_test(tc, efl_ui_average_model_forgotten_in_set);
+   tcase_add_test(tc, efl_ui_average_model_remove_nested);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to