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 3649054ebc4620f8ee347388149e205f9c0b96b6
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 7 00:46:53 2026 -0600

    elementary: box part indices follow Efl.Pack.Linear
    
    The box part took indices as they came: a negative or out of range
    index to content_get and unpack_at gave NULL, and pack_at(-1) reached
    evas_object_box_insert_at as a huge unsigned position. Efl.Pack.Linear
    says -1 is the last item, content_get and unpack_at clamp, and pack_at
    goes to the beginning below -count and to the end from count on, which
    is what Efl.Ui.Box does. Normalise the index the same way.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_layout_pack.c   | 21 ++++++-
 src/tests/elementary/efl_ui_test_layout.c | 97 +++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/src/lib/elementary/efl_ui_layout_pack.c b/src/lib/elementary/efl_ui_layout_pack.c
index 1e9e8446c4..5aba9be14f 100644
--- a/src/lib/elementary/efl_ui_layout_pack.c
+++ b/src/lib/elementary/efl_ui_layout_pack.c
@@ -84,9 +84,17 @@ _box_nth(Eo *pack, int index)
 {
    Evas_Object_Box_Option *opt;
    Evas_Object_Box_Data *priv;
+   int count;
 
-   if (!pack || (index < 0)) return NULL;
+   if (!pack) return NULL;
    priv = efl_data_scope_get(pack, EVAS_BOX_CLASS);
+   count = eina_list_count(priv->children);
+   if (!count) return NULL;
+   // As Efl.Pack.Linear says and Efl.Ui.Box does: -1 is the last, and an
+   // index out of range gives the first or the last.
+   if (index <= -count) index = 0;
+   else if (index >= count) index = count - 1;
+   else if (index < 0) index += count;
    opt = eina_list_nth(priv->children, index);
    if (!opt) return NULL;
    return opt->obj;
@@ -190,7 +198,8 @@ _efl_ui_layout_part_box_efl_pack_linear_pack_after(Eo *obj EINA_UNUSED, Efl_Ui_L
    index = _box_index(pack, existing);
    if (index < 0) return EINA_FALSE;
 
-   other = _box_nth(pack, index + 1);
+   // _box_nth clamps, so the last one has to be told apart first.
+   other = ((index + 1) < evas_obj_box_count(pack)) ? _box_nth(pack, index + 1) : NULL;
    if (other)
      return _efl_ui_layout_box_insert_before(pd->obj, pd->sd, pd->part, subobj, other);
 
@@ -198,8 +207,14 @@ _efl_ui_layout_part_box_efl_pack_linear_pack_after(Eo *obj EINA_UNUSED, Efl_Ui_L
 }
 
 EOLIAN static Eina_Bool
-_efl_ui_layout_part_box_efl_pack_linear_pack_at(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx_Entity *subobj, int index)
+_efl_ui_layout_part_box_efl_pack_linear_pack_at(Eo *obj, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx_Entity *subobj, int index)
 {
+   int count = evas_obj_box_count(_pack_real(pd));
+
+   // Before -count it is a pack_begin, from count on a pack_end.
+   if (index < -count) return efl_pack_begin(obj, subobj);
+   if (index >= count) return efl_pack_end(obj, subobj);
+   if (index < 0) index += count;
    return _efl_ui_layout_box_insert_at(pd->obj, pd->sd, pd->part, subobj, index);
 }
 
diff --git a/src/tests/elementary/efl_ui_test_layout.c b/src/tests/elementary/efl_ui_test_layout.c
index 2719cc7c09..ae399f6a8a 100644
--- a/src/tests/elementary/efl_ui_test_layout.c
+++ b/src/tests/elementary/efl_ui_test_layout.c
@@ -647,12 +647,109 @@ EFL_START_TEST(efl_ui_layout_test_box_part)
 
    ck_assert_ptr_eq(efl_pack_unpack_at(efl_part(ly, "box"), 1), c);
    ck_assert_int_eq(efl_content_count(efl_part(ly, "box")), 2);
+
+   // After the last one is the end.
+   c = efl_add(EFL_UI_BUTTON_CLASS, win);
+   ck_assert(efl_pack_after(efl_part(ly, "box"), c, b));
+   ck_assert_int_eq(efl_pack_index_get(efl_part(ly, "box"), c), 2);
+}
+EFL_END_TEST
+
+// Indices of the box part follow Efl.Ui.Box: negative ones count from the end
+// and out of range ones are clamped (content_get, unpack_at) or go to an end
+// (pack_at). Both containers get the same calls and must agree.
+static Eo *
+_box_part_fill(Eo *win, Eo *ly, Eo *box, Eo **items, int n)
+{
+   int i;
+
+   for (i = 0; i < n; i++)
+     {
+        items[i] = efl_add(EFL_UI_BUTTON_CLASS, win);
+        if (ly) ck_assert(efl_pack_end(efl_part(ly, "box"), items[i]));
+        else ck_assert(efl_pack_end(box, items[i]));
+     }
+   return box;
+}
+
+EFL_START_TEST(efl_ui_layout_test_box_part_indices)
+{
+   static const int idx[] = { 0, 2, 3, -1, -2, -3, -4, 5, 7, -9 };
+   char buf[PATH_MAX];
+   Eo *win, *ly, *box, *a[3], *b[3];
+   unsigned int i;
+   int k;
+
+   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
+   ly = efl_add(EFL_UI_LAYOUT_CLASS, win);
+   snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
+   ck_assert(efl_file_simple_load(ly, buf, "box_layout"));
+   box = efl_add(EFL_UI_BOX_CLASS, win);
+   _box_part_fill(win, ly, NULL, a, 3);
+   _box_part_fill(win, NULL, box, b, 3);
+
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(idx); i++)
+     {
+        Eo *ra = efl_pack_content_get(efl_part(ly, "box"), idx[i]);
+        Eo *rb = efl_pack_content_get(box, idx[i]);
+
+        ck_assert_ptr_ne(rb, NULL);
+        for (k = 0; (k < 3) && (b[k] != rb); k++)
+          {
+             continue;
+          }
+        ck_assert_msg(ra == a[k], "content_get(%d) differs from Efl.Ui.Box (%d)",
+                      idx[i], k);
+     }
+
+   // pack_at: where does a new child land?
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(idx); i++)
+     {
+        Eo *na = efl_add(EFL_UI_BUTTON_CLASS, win);
+        Eo *nb = efl_add(EFL_UI_BUTTON_CLASS, win);
+
+        ck_assert(efl_pack_at(efl_part(ly, "box"), na, idx[i]));
+        ck_assert(efl_pack_at(box, nb, idx[i]));
+        ck_assert_msg(efl_pack_index_get(efl_part(ly, "box"), na) ==
+                      efl_pack_index_get(box, nb),
+                      "pack_at(%d) differs from Efl.Ui.Box", idx[i]);
+        ck_assert_int_eq(efl_content_count(efl_part(ly, "box")),
+                         efl_content_count(box));
+        // Take it out again, from where it is.
+        ck_assert(efl_pack_unpack(efl_part(ly, "box"), na));
+        ck_assert(efl_pack_unpack(box, nb));
+        efl_del(na);
+        efl_del(nb);
+     }
+
+   // unpack_at: which one comes out?
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(idx); i++)
+     {
+        Eo *ra = efl_pack_unpack_at(efl_part(ly, "box"), idx[i]);
+        Eo *rb = efl_pack_unpack_at(box, idx[i]);
+        int ia = -1, ib = -1;
+
+        ck_assert_ptr_ne(rb, NULL);
+        ck_assert_ptr_ne(ra, NULL);
+        for (k = 0; k < 3; k++)
+          {
+             if (a[k] == ra) ia = k;
+             if (b[k] == rb) ib = k;
+          }
+        ck_assert_int_eq(ia, ib);
+        // Put it back at the same place.
+        ck_assert(efl_pack_at(efl_part(ly, "box"), ra, ia));
+        ck_assert(efl_pack_at(box, rb, ib));
+        ck_assert_int_eq(efl_pack_index_get(efl_part(ly, "box"), ra),
+                         efl_pack_index_get(box, rb));
+     }
 }
 EFL_END_TEST
 
 void efl_ui_test_layout(TCase *tc)
 {
    tcase_add_test(tc, efl_ui_layout_calc_subobjs_without_calc);
+   tcase_add_test(tc, efl_ui_layout_test_box_part_indices);
    tcase_add_test(tc, efl_ui_layout_content_replaced_while_held);
    tcase_add_test(tc, efl_ui_layout_part_without_widget);
    tcase_add_test(tc, efl_ui_layout_text_set_while_building);

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

Reply via email to