bu5hm4n pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=7965e2e10f750d9c16be9c29f27dceb07dfd2ac6

commit 7965e2e10f750d9c16be9c29f27dceb07dfd2ac6
Author: Marcel Hollerbach <[email protected]>
Date:   Fri Apr 26 18:30:31 2019 +0200

    efl_ui_pager: refactor object addition
    
    this reduces LOC and keeps functionality.
    
    Reviewed-by: Cedric BAIL <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D8746
---
 src/lib/elementary/efl_ui_pager.c | 84 +++++++++++----------------------------
 1 file changed, 23 insertions(+), 61 deletions(-)

diff --git a/src/lib/elementary/efl_ui_pager.c 
b/src/lib/elementary/efl_ui_pager.c
index 95ebd1233c..30d9464c63 100644
--- a/src/lib/elementary/efl_ui_pager.c
+++ b/src/lib/elementary/efl_ui_pager.c
@@ -415,28 +415,32 @@ _register_child(Eo *obj EINA_UNUSED, Efl_Ui_Pager_Data 
*pd, Efl_Gfx_Entity *subo
    return EINA_TRUE;
 }
 
-EOLIAN static Eina_Bool
-_efl_ui_pager_efl_pack_linear_pack_begin(Eo *obj EINA_UNUSED,
-                                         Efl_Ui_Pager_Data *pd,
-                                         Efl_Gfx_Entity *subobj)
+static void
+_update_internals(Eo *obj EINA_UNUSED, Efl_Ui_Pager_Data *pd, Efl_Gfx_Entity 
*subobj EINA_UNUSED, int index)
 {
-   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
-   pd->content_list = eina_list_prepend(pd->content_list, subobj);
-
    pd->cnt++;
-   pd->curr.page++;
+
+   if (pd->curr.page >= index)
+     pd->curr.page++;
 
    if (pd->transition)
-     efl_page_transition_pack(pd->transition, 0);
-   else
-     {
-        if (pd->cnt == 1)
-          efl_pack(pd->page_box, subobj);
-     }
+     efl_page_transition_pack(pd->transition, index);
 
    if (pd->indicator)
-     efl_page_indicator_pack(pd->indicator, 0);
+     efl_page_transition_pack(pd->indicator, index);
 
+   if (pd->cnt == 1)
+     efl_ui_pager_current_page_set(obj, 0);
+}
+
+EOLIAN static Eina_Bool
+_efl_ui_pager_efl_pack_linear_pack_begin(Eo *obj EINA_UNUSED,
+                                         Efl_Ui_Pager_Data *pd,
+                                         Efl_Gfx_Entity *subobj)
+{
+   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
+   pd->content_list = eina_list_prepend(pd->content_list, subobj);
+   _update_internals(obj, pd, subobj, 0);
    return EINA_TRUE;
 }
 
@@ -447,21 +451,7 @@ _efl_ui_pager_efl_pack_linear_pack_end(Eo *obj EINA_UNUSED,
 {
    if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
    pd->content_list = eina_list_append(pd->content_list, subobj);
-
-   pd->cnt++;
-   if (pd->curr.page == -1) pd->curr.page = 0;
-
-   if (pd->transition)
-     efl_page_transition_pack(pd->transition, (pd->cnt - 1));
-   else
-     {
-        if (pd->cnt == 1)
-          efl_pack(pd->page_box, subobj);
-     }
-
-   if (pd->indicator)
-     efl_page_indicator_pack(pd->indicator, (pd->cnt - 1));
-
+   _update_internals(obj, pd, subobj, eina_list_count(pd->content_list) - 1);
    return EINA_TRUE;
 }
 
@@ -474,18 +464,8 @@ _efl_ui_pager_efl_pack_linear_pack_before(Eo *obj 
EINA_UNUSED,
    if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
    int index = eina_list_data_idx(pd->content_list, (void *)existing);
    if (index == -1) return EINA_FALSE;
-
    pd->content_list = eina_list_prepend_relative(pd->content_list, subobj, 
existing);
-
-   pd->cnt++;
-   if (pd->curr.page >= index) pd->curr.page++;
-
-   if (pd->transition)
-     efl_page_transition_pack(pd->transition, index);
-
-   if (pd->indicator)
-     efl_page_indicator_pack(pd->indicator, index);
-
+   _update_internals(obj, pd, subobj, index);
    return EINA_TRUE;
 }
 
@@ -498,18 +478,8 @@ _efl_ui_pager_efl_pack_linear_pack_after(Eo *obj 
EINA_UNUSED,
    if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
    int index = eina_list_data_idx(pd->content_list, (void *)existing);
    if (index == -1) return EINA_FALSE;
-
    pd->content_list = eina_list_append_relative(pd->content_list, subobj, 
existing);
-
-   pd->cnt++;
-   if (pd->curr.page > index) pd->curr.page++;
-
-   if (pd->transition)
-     efl_page_transition_pack(pd->transition, (index + 1));
-
-   if (pd->indicator)
-     efl_page_indicator_pack(pd->indicator, (index + 1));
-
+   _update_internals(obj, pd, subobj, index + 1);
    return EINA_TRUE;
 }
 
@@ -535,15 +505,7 @@ _efl_ui_pager_efl_pack_linear_pack_at(Eo *obj,
         existing = eina_list_nth(pd->content_list, index);
         pd->content_list = eina_list_prepend_relative(
            pd->content_list, subobj, existing);
-
-        pd->cnt++;
-        if (pd->curr.page >= index) pd->curr.page++;
-
-        if (pd->transition)
-          efl_page_transition_pack(pd->transition, index);
-
-        if (pd->indicator)
-         efl_page_indicator_pack(pd->indicator, index);
+        _update_internals(obj, pd, subobj, index);
      }
 
    return EINA_TRUE;

-- 


Reply via email to