>> Would be great in elm_genlist too.
>
> That's the idea, so we can have swipe to show extra actions... like
> use the state concept from genlist to show extra actions one may use
> (in your case: forward, retweet, view profile, ...;  in my case I want
> to show action to add music to playlist, or in browser we can delete
> history/bookmark items).
>

I'm sending two patches for the elm_genlist (they are very similar to
the patch for the elm_list).

Like the first mail, one patch is just to add a simple test in the
elementary_test the other one contains the functionality itself.
Best regards,

Flavio Ceolin
Developer @ ProFUSION Embedded Systems
From 70e8d2c7c87ae4b40b42fb02d870745804ff3733 Mon Sep 17 00:00:00 2001
From: ceolin <[email protected]>
Date: Tue, 12 Oct 2010 14:04:41 -0300
Subject: [PATCH 1/2] swipe event for the elm_genlist

---
 src/lib/elm_genlist.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/src/lib/elm_genlist.c b/src/lib/elm_genlist.c
index 3ce4f82..73d66de 100644
--- a/src/lib/elm_genlist.c
+++ b/src/lib/elm_genlist.c
@@ -2,10 +2,12 @@
 #include <Elementary_Cursor.h>
 #include "elm_priv.h"
 
+#define SWIPE_MOVES 12
+
 /**
  * @defgroup Genlist Genlist
  *
- * The aim was to have  more expansive list that the simple list in
+ * The Aim was to have  more expansive list that the simple list in
  * Elementary that could have more flexible items and allow many more entries
  * while still being fast and low on memory usage. At the same time it was
  * also made to be able to do tree structures. But the price to pay is more
@@ -266,6 +268,11 @@ struct _Widget_Data
    Eina_Bool height_for_width : 1;
    Eina_Bool homogeneous : 1;
    Eina_Bool clear_me : 1;
+   Eina_Bool swipe : 1;
+   struct {
+     Evas_Coord x, y;
+   } history[SWIPE_MOVES];
+   int movements;
    int walking;
    int item_width;
    int item_height;
@@ -308,6 +315,7 @@ struct _Elm_Genlist_Item
    Evas_Object *spacer;
    Eina_List *labels, *icons, *states, *icon_objs;
    Ecore_Timer *long_timer;
+   Ecore_Timer *swipe_timer;
    Evas_Coord dx, dy;
 
    Elm_Genlist_Item *rel;
@@ -753,6 +761,7 @@ _item_del(Elm_Genlist_Item *it)
    if (it->parent)
      it->parent->items = eina_list_remove(it->parent->items, it);
    if (it->long_timer) ecore_timer_del(it->long_timer);
+   if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
 
    if (it->tooltip.del_cb)
      it->tooltip.del_cb((void *)it->tooltip.data, it->base.widget, it);
@@ -832,6 +841,16 @@ _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_inf
      }
    if ((it->dragging) && (it->down))
      {
+        if (it->wd->movements == SWIPE_MOVES) it->wd->swipe = EINA_TRUE;
+        else
+          {
+             it->wd->history[it->wd->movements].x = ev->cur.output.x;
+             it->wd->history[it->wd->movements].y = ev->cur.output.y;
+             if (abs((it->wd->history[it->wd->movements].x - it->wd->history[0].x)) > 40)
+               it->wd->swipe = EINA_TRUE;
+             else
+               it->wd->movements++;
+          }
         if (it->long_timer)
           {
              ecore_timer_del(it->long_timer);
@@ -917,6 +936,37 @@ _long_press(void *data)
 }
 
 static void
+_swipe(Elm_Genlist_Item *it)
+{
+   int i, sum = 0;
+
+   if (!it) return;
+   if (!it->wd->swipe) return;
+   it->wd->swipe = EINA_FALSE;
+   for (i = 0; i < it->wd->movements; i++)
+     {
+        sum += it->wd->history[i].x;
+        if (abs(it->wd->history[0].y - it->wd->history[i].y) > 10) return;
+     }
+
+   sum /= it->wd->movements;
+   if (abs(sum - it->wd->history[0].x) <= 10) return;
+   evas_object_smart_callback_call(it->base.widget, "swipe", it);
+}
+
+static Eina_Bool
+_swipe_cancel(void *data)
+{
+   Elm_Genlist_Item *it = data;
+
+   if (!it) return ECORE_CALLBACK_CANCEL;
+   it->wd->swipe = EINA_FALSE;
+   memset(it->wd->history, 0, sizeof(it->wd->history[0]) * SWIPE_MOVES);
+   it->wd->movements = 0;
+   return ECORE_CALLBACK_RENEW;
+}
+
+static void
 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
 {
    Elm_Genlist_Item *it = data;
@@ -938,10 +988,15 @@ _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_inf
    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
      evas_object_smart_callback_call(it->base.widget, "clicked", it);
    if (it->long_timer) ecore_timer_del(it->long_timer);
+   if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
+   it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
    if (it->realized)
      it->long_timer = ecore_timer_add(it->wd->longpress_timeout, _long_press, it);
    else
      it->long_timer = NULL;
+   memset(it->wd->history, 0, sizeof(it->wd->history[0]) * SWIPE_MOVES);
+   it->wd->swipe = EINA_FALSE;
+   it->wd->movements = 0;
 }
 
 static void
@@ -966,8 +1021,14 @@ _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *
         evas_object_smart_callback_call(it->base.widget, "drag,stop", it);
         dragged = 1;
      }
+   if (it->swipe_timer)
+     {
+        ecore_timer_del(it->swipe_timer);
+        it->swipe_timer = NULL;
+     }
    if (it->wd->on_hold)
      {
+        if (it->wd->swipe) _swipe(data);
         it->wd->longpressed = EINA_FALSE;
 	it->wd->on_hold = EINA_FALSE;
 	return;
-- 
1.7.3.1

From 7b3570ad4c0d5c290d5381928dc66535d10eeb93 Mon Sep 17 00:00:00 2001
From: ceolin <[email protected]>
Date: Tue, 12 Oct 2010 15:03:53 -0300
Subject: [PATCH 2/2] Test for swipe event in the elm_genlist

---
 src/bin/test.c         |    2 +
 src/bin/test_genlist.c |  109 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/src/bin/test.c b/src/bin/test.c
index 91b5ccb..581f519 100644
--- a/src/bin/test.c
+++ b/src/bin/test.c
@@ -43,6 +43,7 @@ void test_genlist3(void *data, Evas_Object *obj, void *event_info);
 void test_genlist4(void *data, Evas_Object *obj, void *event_info);
 void test_genlist5(void *data, Evas_Object *obj, void *event_info);
 void test_genlist6(void *data, Evas_Object *obj, void *event_info);
+void test_genlist7(void *data, Evas_Object *obj, void *event_info);
 void test_table(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);
@@ -251,6 +252,7 @@ my_win_main(char *autorun)
    ADD_TEST("Genlist 3", test_genlist3);
    ADD_TEST("Genlist 4", test_genlist4);
    ADD_TEST("Genlist 5", test_genlist5);
+   ADD_TEST("Genlist 7", test_genlist7);
    ADD_TEST("Genlist Tree", test_genlist6);
    ADD_TEST("GenGrid", test_gengrid);
    ADD_TEST("GenGrid 2", test_gengrid2);
diff --git a/src/bin/test_genlist.c b/src/bin/test_genlist.c
index 44ad161..8726b36 100644
--- a/src/bin/test_genlist.c
+++ b/src/bin/test_genlist.c
@@ -1159,4 +1159,113 @@ test_genlist6(void *data, Evas_Object *obj, void *event_info)
    evas_object_resize(win, 320, 320);
    evas_object_show(win);
 }
+
+/*************/
+
+struct genlist7_data
+{
+  Evas_Object *win, *pager;
+};
+
+static void
+test_genlist7_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    struct genlist7_data *info = data;
+    if (!info) return;
+
+    elm_pager_content_pop(info->pager);
+}
+
+static void
+test_genlist7_swipe(void *data, Evas_Object *obj, void *event_info)
+{
+   struct genlist7_data *info = data;
+   Evas_Object *box, *entry, *button;
+   char item_data[] = "Just a simple test";
+
+   if (!event_info || !data) return;
+
+   box = elm_box_add(info->win);
+   elm_box_homogenous_set(box, 0);
+   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(box);
+
+   entry = elm_scrolled_entry_add(info->win);
+   elm_scrolled_entry_editable_set(entry, EINA_FALSE);
+   elm_scrolled_entry_entry_set(entry, item_data);
+   evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(entry);
+
+   button = elm_button_add(info->win);
+   elm_button_label_set(button, "back");
+   evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, 0);
+   evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0);
+   evas_object_smart_callback_add(button, "clicked", test_genlist7_back_cb,
+                                  info);
+   evas_object_show(button);
+
+   elm_box_pack_start(box, entry);
+   elm_box_pack_end(box, button);
+
+   elm_pager_content_push(info->pager, box);
+}
+
+void
+test_genlist7(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *win, *bg, *gl, *bx, *bx2, *bt, *pager;
+   static struct genlist7_data info;
+   static Testitem tit[3];
+
+   win = elm_win_add(NULL, "genlist-3", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Genlist 3");
+   elm_win_autodel_set(win, 1);
+   info.win = win;
+
+   bg = elm_bg_add(win);
+   elm_win_resize_object_add(win, bg);
+   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(bg);
+
+   pager = elm_pager_add(win);
+   elm_win_resize_object_add(win, pager);
+   evas_object_size_hint_weight_set(pager, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(pager, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_show(pager);
+   info.pager = pager;
+
+   gl = elm_genlist_add(win);
+   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_smart_callback_add(gl, "swipe", test_genlist7_swipe, &info);
+   evas_object_show(gl);
+   elm_pager_content_push(pager, gl);
+
+   itc2.item_style     = "default";
+   itc2.func.label_get = gl2_label_get;
+   itc2.func.icon_get  = gl2_icon_get;
+   itc2.func.state_get = gl2_state_get;
+   itc2.func.del       = gl2_del;
+
+   tit[0].mode = 0;
+   tit[0].item = elm_genlist_item_append(gl, &itc2,
+					 &(tit[0])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
+					 NULL/* func data */);
+   tit[1].mode = 1;
+   tit[1].item = elm_genlist_item_append(gl, &itc2,
+					 &(tit[1])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
+					 NULL/* func data */);
+   tit[2].mode = 2;
+   tit[2].item = elm_genlist_item_append(gl, &itc2,
+        				 &(tit[2])/* item data */, NULL/* parent */,
+                                         ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
+        				 NULL/* func data */);
+
+   evas_object_resize(win, 320, 320);
+   evas_object_show(win);
+}
 #endif
-- 
1.7.3.1

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to