Hello,
I have done a patch to add a new event for the elm_list similar to the
iphone swipe's effect.
The event is quite simple, it's triggered when a horizontal drag plus
mouse release occur.
There are two patches, the first is the feature itself and the second
is just two examples for elementary_test.
Best regards,
Flavio Ceolin
Developer @ ProFUSION Embedded Systems
From 8da67eb19c4ff76eca22931a8c65d496a6592e41 Mon Sep 17 00:00:00 2001
From: ceolin <[email protected]>
Date: Wed, 6 Oct 2010 10:24:21 -0300
Subject: [PATCH 1/2] swipe event
---
src/lib/elm_list.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/src/lib/elm_list.c b/src/lib/elm_list.c
index 4ee7728..53ff3d5 100644
--- a/src/lib/elm_list.c
+++ b/src/lib/elm_list.c
@@ -1,6 +1,8 @@
#include <Elementary.h>
#include "elm_priv.h"
+#define SWIPE_MOVES 12
+
/**
* @defgroup List List
*
@@ -20,6 +22,11 @@ struct _Widget_Data
Eina_Bool scr_minw : 1;
Eina_Bool scr_minh : 1;
int walking;
+ int movements;
+ struct {
+ Evas_Coord x, y;
+ } history[SWIPE_MOVES];
+ Eina_Bool swipe : 1;
Eina_Bool fix_pending : 1;
Eina_Bool on_hold : 1;
Eina_Bool multi : 1;
@@ -37,6 +44,7 @@ struct _Elm_List_Item
Evas_Object *icon, *end;
Evas_Smart_Cb func;
Ecore_Timer *long_timer;
+ Ecore_Timer *swipe_timer;
Eina_Bool deleted : 1;
Eina_Bool even : 1;
Eina_Bool is_even : 1;
@@ -102,6 +110,7 @@ _elm_list_item_free(Elm_List_Item *it)
eina_stringshare_del(it->label);
+ if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
if (it->long_timer) ecore_timer_del(it->long_timer);
if (it->icon) evas_object_del(it->icon);
if (it->end) evas_object_del(it->end);
@@ -593,6 +602,20 @@ _item_unselect(Elm_List_Item *it)
_elm_list_unwalk(wd);
}
+static Eina_Bool
+_swipe_cancel(void *data)
+{
+ Elm_List_Item *it = data;
+ Widget_Data *wd = elm_widget_data_get(it->base.widget);
+
+ if (!wd) return;
+ ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, 0);
+ wd->swipe = EINA_FALSE;
+ memset(wd->history, 0, sizeof(wd->history[0]) * SWIPE_MOVES);
+ wd->movements = 0;
+ return ECORE_CALLBACK_RENEW;
+}
+
static void
_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{
@@ -615,6 +638,16 @@ _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void
if (!wd->wasselected)
_item_unselect(it);
}
+ if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
+ else
+ {
+ wd->history[wd->movements].x = ev->cur.output.x;
+ wd->history[wd->movements].y = ev->cur.output.y;
+ if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
+ wd->swipe = EINA_TRUE;
+ else
+ wd->movements++;
+ }
}
}
@@ -632,6 +665,38 @@ _long_press(void *data)
return ECORE_CALLBACK_CANCEL;
}
+static Eina_Bool
+_swipe(void *data)
+{
+ int i;
+ Evas_Coord y0;
+ Eina_Bool to_right = EINA_TRUE;
+ Elm_List_Item *it = data;
+ Widget_Data *wd = elm_widget_data_get(it->base.widget);
+
+ if (!wd) return ECORE_CALLBACK_CANCEL;
+ ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, 0);
+ if (!wd->swipe) return ECORE_CALLBACK_CANCEL;
+ wd->swipe = EINA_FALSE;
+ y0 = wd->history[0].y;
+ if ((wd->history[1].x - wd->history[0].x) < -1) to_right = EINA_FALSE;
+ for (i = 1; i < wd->movements; i++)
+ {
+ if (to_right)
+ {
+ if ((wd->history[i].x - wd->history[i - 1].x) < 1) return EINA_FALSE;
+ }
+ else
+ {
+ if ((wd->history[i].x - wd->history[i - 1].x) > -1) return EINA_FALSE;
+ }
+
+ if (abs(y0 - wd->history[i].y) > 10) return EINA_FALSE;
+ }
+ evas_object_smart_callback_call(it->base.widget, "swipe", it);
+ return ECORE_CALLBACK_CANCEL;
+}
+
static void
_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{
@@ -649,9 +714,14 @@ _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void
wd->longpressed = EINA_FALSE;
if (it->long_timer) ecore_timer_del(it->long_timer);
it->long_timer = ecore_timer_add(1.0, _long_press, it);
+ if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
+ it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
/* Always call the callbacks last - the user may delete our context! */
if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
evas_object_smart_callback_call(it->base.widget, "clicked", it);
+ memset(wd->history, 0, sizeof(wd->history[0]) * SWIPE_MOVES);
+ wd->swipe = EINA_FALSE;
+ wd->movements = 0;
}
static void
@@ -672,8 +742,14 @@ _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *
ecore_timer_del(it->long_timer);
it->long_timer = NULL;
}
+ if (it->swipe_timer)
+ {
+ ecore_timer_del(it->swipe_timer);
+ it->swipe_timer = NULL;
+ }
if (wd->on_hold)
{
+ if (wd->swipe) _swipe(data);
wd->on_hold = EINA_FALSE;
return;
}
--
1.7.3.1
From 536b062a0e4209d8b51e3cb3be616b7156be32fa Mon Sep 17 00:00:00 2001
From: ceolin <[email protected]>
Date: Wed, 6 Oct 2010 10:27:33 -0300
Subject: [PATCH 2/2] tests for swipe
---
src/bin/test.c | 4 +
src/bin/test_list.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 232 insertions(+), 0 deletions(-)
diff --git a/src/bin/test.c b/src/bin/test.c
index 1a68280..7570b8c 100644
--- a/src/bin/test.c
+++ b/src/bin/test.c
@@ -31,6 +31,8 @@ void test_hoversel(void *data, Evas_Object *obj, void *event_info);
void test_list(void *data, Evas_Object *obj, void *event_info);
void test_list2(void *data, Evas_Object *obj, void *event_info);
void test_list3(void *data, Evas_Object *obj, void *event_info);
+void test_list4(void *data, Evas_Object *obj, void *event_info);
+void test_list5(void *data, Evas_Object *obj, void *event_info);
void test_carousel(void *data, Evas_Object *obj, void *event_info);
void test_inwin(void *data, Evas_Object *obj, void *event_info);
void test_inwin2(void *data, Evas_Object *obj, void *event_info);
@@ -237,6 +239,8 @@ my_win_main(char *autorun)
ADD_TEST("List", test_list);
ADD_TEST("List 2", test_list2);
ADD_TEST("List 3", test_list3);
+ ADD_TEST("List 4", test_list4);
+ ADD_TEST("List 5", test_list5);
ADD_TEST("Carousel", test_carousel);
ADD_TEST("Inwin", test_inwin);
ADD_TEST("Inwin 2", test_inwin2);
diff --git a/src/bin/test_list.c b/src/bin/test_list.c
index af5282b..b77067a 100755
--- a/src/bin/test_list.c
+++ b/src/bin/test_list.c
@@ -365,4 +365,232 @@ test_list3(void *data, Evas_Object *obj, void *event_info)
evas_object_resize(win, 320, 300);
evas_object_show(win);
}
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+struct Pginfo {
+ Evas_Object *pager, *win;
+};
+
+static void
+test_list4_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ struct Pginfo *info = data;
+ if (!info) return;
+
+ elm_pager_content_pop(info->pager);
+}
+
+static void
+test_list4_swipe(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *box, *entry, *button;
+ const char *item_label = NULL;
+ struct Pginfo *info = data;
+ char *item_data;
+ if (!event_info || !data) return;
+
+ item_data = elm_list_item_data_get(event_info);
+
+ box = elm_box_add(info->win);
+ elm_box_horizontal_set(box, 0);
+ 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_list4_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_list4(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *win, *bg, *li, *ic, *ic2, *pager;
+ static struct Pginfo info = {NULL, NULL};
+ char buf[PATH_MAX];
+
+ win = elm_win_add(NULL, "list-4", ELM_WIN_BASIC);
+ elm_win_title_set(win, "List 4");
+ 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;
+
+ li = elm_list_add(win);
+ evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_list_horizontal_mode_set(li, ELM_LIST_COMPRESS);
+ evas_object_smart_callback_add(li, "swipe", test_list4_swipe, &info);
+ elm_pager_content_push(pager, li);
+
+ static char pf_data[] = "Pink Floyd were formed in 1965, and originally consisted of university" \
+ "students Roger Waters, Nick Mason, Richard Wright, and Syd Barrett. The group were a popular"\
+ "fixture on London's underground music scene, and under Barrett's leadership released two "\
+ "charting singles, \"Arnold Layne\" and \"See Emily Play\", and a successful debut album, "\
+ "ThePiper at the Gates of Dawn. In 1968, guitarist and singer David Gilmour joined the "\
+ "line-up. Barrett was soon removed, due to his increasingly erratic behaviour. Following "\
+ "Barrett's departure, bass player and singer Roger Waters became the band's lyricist and "\
+ "conceptual leader, with Gilmour assuming lead guitar and much of the vocals. With this "\
+ "line-up, Floyd went on to achieve worldwide critical and commercial success with the "\
+ "conceptalbums The Dark Side of the Moon, Wish You Were Here, Animals, and The Wall.";
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/mystrale.jpg", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 0, 0);
+ elm_icon_file_set(ic, buf, NULL);
+ elm_list_item_append(li, "Pink Floyd", ic, NULL, NULL, &pf_data);
+
+ static char ds_data[] = "Dire Straits were a British rock band, formed by Mark Knopfler "\
+ "(lead vocals and lead guitar), his younger brother David Knopfler (rhythm guitar and "\
+ "backing vocals), John Illsley (bass guitar and backing vocals), and Pick Withers (drums "\
+ "and percussion), and managed by Ed Bicknell, active between 1977 and 1995. Although the "\
+ "band was formed in an era when punk rock was at the forefront, Dire Straits played a more "
+ "bluesy style, albeit with a stripped-down sound that appealed to audiences weary of the "\
+ "overproduced stadium rock of the 1970s.[citation needed] In their early days, Mark and "\
+ "David requested that pub owners turn down their sound so that patrons could converse "\
+ "while the band played, an indication of their unassuming demeanor. Despite this oddly "\
+ "self-effacing approach to rock and roll, Dire Straits soon became hugely successful, with "\
+ "their first album going multi-platinum globally.";
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/mystrale_2.jpg", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 0, 0);
+ elm_icon_file_set(ic, buf, NULL);
+ elm_list_item_append(li, "Dire Straits", ic, NULL, NULL, &ds_data);
+
+ static char uh_data[] = "Uriah Heep are an English hard rock band. The band released several "\
+ "commercially successful albums in the 1970s such as Uriah Heep Live (1973), but their "\
+ "audience declined by the 1980s, to the point where they became essentially a cult band in "\
+ "the United States and United Kingdom. Uriah Heep maintain a significant following in "\
+ "Germany, the Netherlands, Scandinavia, the Balkans, Japan and Russia, where they still "\
+ "perform at stadium-sized venues.";
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_17.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 1, 1);
+ elm_icon_file_set(ic, buf, NULL);
+ elm_list_item_append(li, "Uriah Heep", ic, NULL, NULL, &uh_data);
+
+ static char r_data[] = "Rush is a Canadian rock band formed in August 1968, in the Willowdale "\
+ "neighbourhood of Toronto, Ontario. The band is composed of bassist, keyboardist, and lead "\
+ "vocalist Geddy Lee, guitarist Alex Lifeson, and drummer and lyricist Neil Peart. The band "\
+ "and its membership went through a number of re-configurations between 1968 and 1974, "\
+ "achieving their current form when Peart replaced original drummer John Rutsey in July 1974, "\
+ "two weeks before the group's first United States tour.";
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_21.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 0, 0);
+ elm_icon_file_set(ic, buf, NULL);
+ ic2 = elm_icon_add(win);
+ elm_icon_standard_set(ic2, "clock");
+ elm_icon_scale_set(ic2, 0, 0);
+ elm_list_item_append(li, "Rush", ic, ic2, NULL, &r_data);
+
+ elm_list_go(li);
+
+ evas_object_show(li);
+ evas_object_resize(win, 320, 300);
+ evas_object_show(win);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+struct swipe_icons {
+ Evas_Object *ic, *ic2;
+ unsigned state : 1;
+};
+
+static void
+test_list5_swipe(void *data, Evas_Object *obj, void *event_info)
+{
+ struct swipe_icons *icons;
+ if (!event_info) return;
+
+ icons = elm_list_item_data_get(event_info);
+ if (!icons->state)
+ {
+ elm_list_item_icon_set(event_info, icons->ic2);
+ icons->state = 1;
+ }
+ else
+ {
+ elm_list_item_icon_set(event_info, icons->ic);
+ icons->state = 0;
+ }
+}
+
+void
+test_list5(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *win, *bg, *li, *ic, *ic2;
+ static struct swipe_icons icons, icons2, icons3;
+ char buf[PATH_MAX];
+
+ win = elm_win_add(NULL, "list-5", ELM_WIN_BASIC);
+ elm_win_title_set(win, "List 5");
+ elm_win_autodel_set(win, 1);
+
+ 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);
+
+ li = elm_list_add(win);
+ evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_list_horizontal_mode_set(li, ELM_LIST_COMPRESS);
+ evas_object_smart_callback_add(li, "swipe", test_list5_swipe, NULL);
+ elm_win_resize_object_add(win, li);
+ evas_object_show(li);
+
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_13.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 0, 0);
+ elm_icon_file_set(ic, buf, NULL);
+ icons.ic = ic;
+ ic2 = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_14.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic2, 0, 0);
+ elm_icon_file_set(ic2, buf, NULL);
+ icons.ic2 = ic2;
+ elm_list_item_append(li, "Network", ic, NULL, NULL, &icons);
+
+ ic = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_15.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic, 0, 0);
+ elm_icon_file_set(ic, buf, NULL);
+ icons2.ic = ic;
+ ic2 = elm_icon_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/icon_16.png", PACKAGE_DATA_DIR);
+ elm_icon_scale_set(ic2, 0, 0);
+ elm_icon_file_set(ic2, buf, NULL);
+ icons2.ic2 = ic2;
+ elm_list_item_append(li, "Audio", ic, NULL, NULL, &icons2);
+
+ elm_list_go(li);
+ evas_object_resize(win, 320, 300);
+ 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