jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=86a59a3a2469374c8d5b5c7545dccbe7d2f4d34f

commit 86a59a3a2469374c8d5b5c7545dccbe7d2f4d34f
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Thu Apr 14 14:12:16 2016 +0900

    Elm_test/Grid: Add linear API test for Efl.Ui.Grid
    
    At this point, it proves that the grid API does not work.
    Some things still need to be implemented or fixed.
---
 src/bin/elementary/test.c               |   2 +
 src/bin/elementary/test_ui_grid.c       | 146 ++++++++++++++++++++++++++++++++
 src/lib/efl/interfaces/efl_pack_grid.eo |   8 ++
 src/lib/efl/interfaces/efl_pack_item.eo |  10 +--
 src/lib/elementary/efl_ui_grid.c        |  51 +++++++----
 src/lib/elementary/efl_ui_grid.eo       |   9 +-
 6 files changed, 193 insertions(+), 33 deletions(-)

diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index e70e26b..9fbca60 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -141,6 +141,7 @@ void test_table6(void *data, Evas_Object *obj, void 
*event_info);
 void test_table7(void *data, Evas_Object *obj, void *event_info);
 void test_table8(void *data, Evas_Object *obj, void *event_info);
 void test_ui_grid(void *data, Evas_Object *obj, void *event_info);
+void test_ui_grid_linear(void *data, Evas_Object *obj, void *event_info);
 void test_gengrid(void *data, Evas_Object *obj, void *event_info);
 void test_gengrid2(void *data, Evas_Object *obj, void *event_info);
 void test_gengrid3(void *data, Evas_Object *obj, void *event_info);
@@ -594,6 +595,7 @@ add_tests:
    //------------------------------//
    ADD_TEST(NULL, "New Containers", "Ui.Box", test_ui_box);
    ADD_TEST(NULL, "New Containers", "Ui.Grid", test_ui_grid);
+   ADD_TEST(NULL, "New Containers", "Ui.Grid Linear", test_ui_grid_linear);
 
    //------------------------------//
    ADD_TEST(NULL, "Entries", "Entry", test_entry);
diff --git a/src/bin/elementary/test_ui_grid.c 
b/src/bin/elementary/test_ui_grid.c
index 1ebd728..fec81ed 100644
--- a/src/bin/elementary/test_ui_grid.c
+++ b/src/bin/elementary/test_ui_grid.c
@@ -353,3 +353,149 @@ test_ui_grid(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_i
 
    evas_object_show(win);
 }
+
+static const char *
+btn_text(const char *str)
+{
+   static char buf[64];
+   static int id = 0;
+   sprintf(buf, "%s %d", str ?: "item", ++id);
+   return buf;
+}
+
+static void
+remove_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info 
EINA_UNUSED)
+{
+   eo_unref(obj);
+}
+
+static void
+append_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info 
EINA_UNUSED)
+{
+   Eo *grid = data;
+   Eo *o = elm_button_add(grid);
+   elm_object_text_set(o, btn_text("appended"));
+   evas_object_smart_callback_add(o, "clicked", remove_cb, grid);
+   elm_object_tooltip_text_set(o, "Click to unpack");
+   efl_pack_end(grid, o);
+   efl_gfx_visible_set(o, 1);
+}
+
+static void
+rmrand_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info 
EINA_UNUSED)
+{
+   Eo *grid = data, *o;
+   int cols, rows;
+
+   efl_pack_grid_size_get(o, &cols, &rows);
+   if (!cols || !rows) return;
+
+   o = efl_pack_grid_child_at(grid, rand() % cols, rand() % rows);
+   eo_unref(o);
+}
+
+static void
+clear_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info 
EINA_UNUSED)
+{
+   Eo *grid = data;
+   efl_pack_clear(grid);
+}
+
+void
+test_ui_grid_linear(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
+                    void *event_info EINA_UNUSED)
+{
+   Evas_Object *win, *o, *vbox, *f, *hbox, *grid, *ico;
+
+   win = elm_win_util_standard_add("ui-grid-linear", "Efl.Ui.Grid Linear 
APIs");
+   elm_win_autodel_set(win, EINA_TRUE);
+   efl_gfx_size_set(win, 600, 400);
+
+   vbox = eo_add(EFL_UI_BOX_CLASS, win);
+   efl_pack_padding_set(vbox, 10, 10, EINA_TRUE);
+   efl_pack_direction_set(vbox, EFL_ORIENT_DOWN);
+   evas_object_size_hint_weight_set(vbox, 1, 1);
+   evas_object_size_hint_padding_set(vbox, 5, 5, 5, 5);
+   elm_win_resize_object_add(win, vbox);
+   efl_gfx_visible_set(vbox, 1);
+
+
+   // create here to pass in cb
+   grid = eo_add(EFL_UI_GRID_CLASS, win);
+
+
+   /* controls */
+   f = elm_frame_add(win);
+   elm_object_text_set(f, "Controls");
+   evas_object_size_hint_align_set(f, -1, -1);
+   evas_object_size_hint_weight_set(f, 1, 0);
+   efl_pack(vbox, f);
+   efl_gfx_visible_set(f, 1);
+
+   hbox = eo_add(EFL_UI_BOX_CLASS, win);
+   elm_object_content_set(f, hbox);
+   efl_pack_padding_set(hbox, 5, 0, EINA_TRUE);
+   efl_gfx_visible_set(hbox, 1);
+
+   ico = elm_icon_add(win);
+   elm_icon_standard_set(ico, "list-add");
+   o = elm_button_add(win);
+   elm_object_content_set(o, ico);
+   elm_object_text_set(o, "Append");
+   evas_object_smart_callback_add(o, "clicked", append_cb, grid);
+   efl_pack(hbox, o);
+   efl_gfx_visible_set(o, 1);
+
+   ico = elm_icon_add(win);
+   elm_icon_standard_set(ico, "edit-delete");
+   o = elm_button_add(win);
+   elm_object_content_set(o, ico);
+   elm_object_text_set(o, "Remove random");
+   evas_object_smart_callback_add(o, "clicked", rmrand_cb, grid);
+   efl_pack(hbox, o);
+   efl_gfx_visible_set(o, 1);
+
+   ico = elm_icon_add(win);
+   elm_icon_standard_set(ico, "edit-clear-all");
+   o = elm_button_add(win);
+   elm_object_content_set(o, ico);
+   elm_object_text_set(o, "Clear");
+   evas_object_smart_callback_add(o, "clicked", clear_cb, grid);
+   efl_pack(hbox, o);
+   efl_gfx_visible_set(o, 1);
+
+
+   /* contents */
+   f = elm_frame_add(win);
+   elm_object_text_set(f, "Contents");
+   evas_object_size_hint_align_set(f, -1, -1);
+   evas_object_size_hint_weight_set(f, 1, 1);
+   efl_pack(vbox, f);
+   efl_gfx_visible_set(f, 1);
+
+   efl_pack_max_span_set(grid, 4);
+   efl_pack_directions_set(grid, EFL_ORIENT_RIGHT, EFL_ORIENT_DOWN);
+   evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_object_content_set(f, grid);
+   evas_object_show(grid);
+
+   o = elm_button_add(win);
+   elm_object_text_set(o, btn_text(NULL));
+   evas_object_smart_callback_add(o, "clicked", remove_cb, grid);
+   efl_pack(grid, o);
+   efl_gfx_visible_set(o, 1);
+
+   o = elm_button_add(win);
+   elm_object_text_set(o, btn_text(NULL));
+   evas_object_smart_callback_add(o, "clicked", remove_cb, grid);
+   efl_pack(grid, o);
+   efl_gfx_visible_set(o, 1);
+
+   o = elm_button_add(win);
+   elm_object_text_set(o, btn_text(NULL));
+   evas_object_smart_callback_add(o, "clicked", remove_cb, grid);
+   efl_pack(grid, o);
+   efl_gfx_visible_set(o, 1);
+
+   evas_object_show(win);
+}
diff --git a/src/lib/efl/interfaces/efl_pack_grid.eo 
b/src/lib/efl/interfaces/efl_pack_grid.eo
index eda8ebb..67782d0 100644
--- a/src/lib/efl/interfaces/efl_pack_grid.eo
+++ b/src/lib/efl/interfaces/efl_pack_grid.eo
@@ -25,6 +25,14 @@ interface Efl.Pack_Grid (Efl.Pack_Linear)
             @in row: int;
          }
       }
+      grid_child_at {
+         [[returns the top child at position. see also grid_children_at]]
+         return: Efl.Pack_Item*;
+         params {
+            @in col: int;
+            @in row: int;
+         }
+      }
       @property grid_child_position {
          [[position and span of the $subobj in this container, may be modified 
to move the $subobj]]
          set { [[same as grid_pack]] }
diff --git a/src/lib/efl/interfaces/efl_pack_item.eo 
b/src/lib/efl/interfaces/efl_pack_item.eo
index a7969ef..83c1105 100644
--- a/src/lib/efl/interfaces/efl_pack_item.eo
+++ b/src/lib/efl/interfaces/efl_pack_item.eo
@@ -1,14 +1,6 @@
+/* FIXME: this is not necessary - just use efl.gfx.base */
 interface Efl.Pack_Item
 {
    [[Describes an item that can be packed in a container.]]
    legacy_prefix: null;
-   methods {
-      /* FIXME: is this same as eo_parent? shouldn't it be? */
-      @property container {
-         get {}
-         values {
-            obj: const(Eo.Base)*; /* FIXME: this is an Efl.Pack* */
-         }
-      }
-   }
 }
diff --git a/src/lib/elementary/efl_ui_grid.c b/src/lib/elementary/efl_ui_grid.c
index 5181d30..4f90522 100644
--- a/src/lib/elementary/efl_ui_grid.c
+++ b/src/lib/elementary/efl_ui_grid.c
@@ -22,7 +22,7 @@ struct _Grid_Item
 
    Efl_Pack_Item *object;
    int colspan, rowspan;
-   int col, row; // if linear, this may change
+   int col, row;
 
    Eina_Bool linear : 1;
 };
@@ -53,7 +53,7 @@ struct _Grid_Item_Iterator
 static inline Eina_Bool
 _horiz(Efl_Orient dir)
 {
-   return dir % 180 == 0;
+   return dir % 180 == EFL_ORIENT_RIGHT;
 }
 
 EOLIAN static Eina_Bool
@@ -250,6 +250,8 @@ _efl_ui_grid_eo_base_constructor(Eo *obj, Efl_Ui_Grid_Data 
*pd)
 
    pd->dir1 = EFL_ORIENT_RIGHT;
    pd->dir2 = EFL_ORIENT_DOWN;
+   pd->lastcol = -1;
+   pd->lastrow = -1;
 
    return obj;
 }
@@ -309,10 +311,12 @@ _efl_ui_grid_efl_pack_grid_pack_grid(Eo *obj, 
Efl_Ui_Grid_Data *pd, Efl_Pack_Ite
    if ((row + rowspan) >= 0x7ffff)
      WRN("row + rowspan getting rather large (>32767)");
 
-   if ((col + colspan - 1) > pd->lastcol)
-     pd->lastcol = col + colspan;
-   if ((row + rowspan - 1) > pd->lastrow)
-     pd->lastrow = row + rowspan;
+   if ((pd->lastcol < (col + colspan - 1)) ||
+       (pd->lastrow < (row + rowspan - 1)))
+     {
+        pd->lastcol = col + colspan - 1;
+        pd->lastrow = row + rowspan - 1;
+     }
 
    elm_widget_sub_object_add(obj, subobj);
    evas_object_table_pack(wd->resize_obj, subobj, col, row, colspan, rowspan);
@@ -338,15 +342,24 @@ _efl_ui_grid_efl_pack_grid_grid_child_position_get(Eo 
*obj, Efl_Ui_Grid_Data *pd
    if (rowspan) *rowspan = irowspan;
 }
 
+EOLIAN static Efl_Pack_Item *
+_efl_ui_grid_efl_pack_grid_grid_child_at(Eo *obj, Efl_Ui_Grid_Data *pd 
EINA_UNUSED, int col, int row)
+{
+   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);
+
+   return evas_object_table_child_get(wd->resize_obj, col, row);
+}
+
 EOLIAN static Eina_Bool
 _efl_ui_grid_efl_pack_unpack(Eo *obj, Efl_Ui_Grid_Data *pd EINA_UNUSED, 
Efl_Pack_Item *subobj)
 {
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
 
-   if (elm_widget_sub_object_del(obj, subobj))
+   if (evas_object_table_unpack(wd->resize_obj, subobj))
      {
-        evas_object_table_unpack(wd->resize_obj, subobj);
-        return EINA_TRUE;
+        if (elm_widget_sub_object_del(obj, subobj))
+          return EINA_TRUE;
+        return EINA_FALSE;
      }
 
    return EINA_FALSE;
@@ -440,19 +453,17 @@ _efl_ui_grid_efl_pack_contents_iterate(Eo *obj, 
Efl_Ui_Grid_Data *pd EINA_UNUSED
 EOLIAN static int
 _efl_ui_grid_efl_pack_contents_count(Eo *obj, Efl_Ui_Grid_Data *pd EINA_UNUSED)
 {
-   /* FIXME */
-   Eina_Iterator *it;
-   Efl_Pack_Item *pack;
-   int k = 0;
+   Eina_List *li;
+   int count;
 
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, 0);
 
-   it = evas_object_table_iterator_new(obj);
-   EINA_ITERATOR_FOREACH(it, pack)
-     k++;
-   eina_iterator_free(it);
+   /* FIXME */
+   li = evas_object_table_children_get(wd->resize_obj);
+   count = eina_list_count(li);
+   eina_list_free(li);
 
-   return k;
+   return count;
 }
 
 EOLIAN static Eina_List *
@@ -616,6 +627,7 @@ _efl_ui_grid_efl_pack_linear_pack_end(Eo *obj, 
Efl_Ui_Grid_Data *pd, Efl_Pack_It
              col = 0;
              row++;
           }
+        if (row < 0) row = 0;
      }
    else
      {
@@ -625,9 +637,12 @@ _efl_ui_grid_efl_pack_linear_pack_end(Eo *obj, 
Efl_Ui_Grid_Data *pd, Efl_Pack_It
              row = 0;
              col++;
           }
+        if (col < 0) col = 0;
      }
 
    DBG("packing new obj at %d,%d", col, row);
+   pd->lastcol = col;
+   pd->lastrow = row;
    efl_pack_grid(obj, subobj, col, row, 1, 1);
 }
 
diff --git a/src/lib/elementary/efl_ui_grid.eo 
b/src/lib/elementary/efl_ui_grid.eo
index accbddc..dd33117 100644
--- a/src/lib/elementary/efl_ui_grid.eo
+++ b/src/lib/elementary/efl_ui_grid.eo
@@ -27,6 +27,7 @@ class Efl.Ui.Grid (Elm.Widget, Efl.Pack_Grid)
       Efl.Pack.layout_request;
       Efl.Pack_Grid.pack_grid;
       Efl.Pack_Grid.grid_children_at;
+      Efl.Pack_Grid.grid_child_at;
       Efl.Pack_Grid.grid_child_position.set;
       Efl.Pack_Grid.grid_child_position.get;
       Efl.Pack_Grid.grid_size.set;
@@ -37,14 +38,10 @@ class Efl.Ui.Grid (Elm.Widget, Efl.Pack_Grid)
       Efl.Pack_Grid.columns.get;
       Efl.Pack_Grid.rows.set;
       Efl.Pack_Grid.rows.get;
+      Efl.Pack_Grid.directions.set;
+      Efl.Pack_Grid.directions.get;
       Efl.Pack_Linear.pack_end;
-      //Efl.Pack_Linear.child_at.get;
-      //Efl.Pack_Linear.child_at.set;
-      //Efl.Pack_Linear.child_index.get;
-      //Efl.Pack_Linear.child_index.set;
       Efl.Pack_Linear.direction.set;
       Efl.Pack_Linear.direction.get;
-      Efl.Pack_Grid.directions.set;
-      Efl.Pack_Grid.directions.get;
    }
 }

-- 


Reply via email to