Dear All,
This is Shinwoo Kim, learned that I could contribute to EFL! :)
I'm pleased to inform you that the patch for the "elm_diskselector".
Until now, the "elm_diskselector" only display 3 items at once,
if you accept this patch, the "elm_diskselector" can display more than 3
items.
For this feature, "elm_diskselector_display_item_num_set(Evas_Object *obj,
int num)" is added.
I would like to know more about your opinion about this feature. Thanks.
Sincerely,
Shinwoo Kim
Index: src/lib/elm_diskselector.c
===================================================================
--- src/lib/elm_diskselector.c (revision 57821)
+++ src/lib/elm_diskselector.c (working copy)
@@ -19,6 +19,10 @@
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
+#ifndef CEIL
+#define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
+#endif
+
typedef struct _Widget_Data Widget_Data;
struct _Widget_Data
@@ -35,7 +39,9 @@
Elm_Diskselector_Item *last;
Eina_List *items;
Eina_List *r_items;
- int item_count, len_threshold, len_side;
+ Eina_List *over_items;
+ Eina_List *under_items;
+ int item_count, len_threshold, len_side, display_item_num;
Ecore_Idler *idler;
Ecore_Idler *check_idler;
Eina_Bool init:1;
@@ -67,6 +73,8 @@
static void _sub_del(void *data, Evas_Object * obj, void *event_info);
static void _round_items_del(Widget_Data *wd);
static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
+static void _item_click_cb(void *data, Evas_Object *obj, void *event_info);
+static void _selected_item_indicate(Elm_Diskselector_Item *it);
static const char SIG_SELECTED[] = "selected";
static const Evas_Smart_Cb_Description _signals[] = {
@@ -91,12 +99,12 @@
evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
if (wd->round)
- evas_object_resize(wd->main_box, w / 3 * (wd->item_count + 4), h);
+ evas_object_resize(wd->main_box, w / wd->display_item_num * (wd->item_count + CEIL(wd->display_item_num) * 2), h);
else
- evas_object_resize(wd->main_box, w / 3 * (wd->item_count + 2), h);
+ evas_object_resize(wd->main_box, w / wd->display_item_num * (wd->item_count + CEIL(wd->display_item_num)), h);
elm_smart_scroller_paging_set(wd->scroller, 0, 0,
- (int)(w / 3), 0);
+ (int)(w / wd->display_item_num), 0);
if (!wd->idler)
wd->idler = ecore_idler_add(_move_scroller, data);
@@ -124,7 +132,10 @@
evas_object_show(it->base.view);
if (it->label)
+ {
edje_object_part_text_set(it->base.view, "elm.text", it->label);
+ edje_object_signal_callback_add(it->base.view, "elm,action,click", "", _item_click_cb, it);
+ }
if (it->icon)
{
evas_object_size_hint_min_set(it->icon, 24, 24);
@@ -167,6 +178,8 @@
_del_pre_hook(Evas_Object * obj)
{
Elm_Diskselector_Item *it;
+ Eina_List *l;
+
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
@@ -199,6 +212,26 @@
free(wd->first);
}
+ EINA_LIST_FOREACH(wd->under_items, l, it)
+ {
+ if (it)
+ {
+ eina_stringshare_del(it->label);
+ evas_object_del(wd->first->base.view);
+ free(it);
+ }
+ }
+
+ EINA_LIST_FOREACH(wd->over_items, l, it)
+ {
+ if (it)
+ {
+ eina_stringshare_del(it->label);
+ evas_object_del(wd->first->base.view);
+ free(it);
+ }
+ }
+
EINA_LIST_FREE(wd->items, it) _item_del(it);
eina_list_free(wd->r_items);
}
@@ -274,6 +307,7 @@
if (!it) return;
Widget_Data *wd = elm_widget_data_get(it->base.widget);
wd->selected_item = it;
+ _selected_item_indicate(wd->selected_item);
if (it->func) it->func((void *)it->base.data, it->base.widget, it);
evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
}
@@ -438,6 +472,45 @@
}
static void
+_selected_item_indicate(Elm_Diskselector_Item *it)
+{
+ Elm_Diskselector_Item *item;
+ Eina_List *l;
+ Widget_Data *wd;
+ wd = elm_widget_data_get(it->base.widget);
+
+ if (!wd) return;
+
+ EINA_LIST_FOREACH(wd->r_items, l, item)
+ {
+ if (strcmp(item->label, it->label) == 0) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
+ else
+ edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
+ }
+}
+
+static void
+_item_click_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Elm_Diskselector_Item *it = data;
+
+ if (!it) return;
+
+ Widget_Data *wd;
+ wd = elm_widget_data_get(it->base.widget);
+
+ if (!wd) return;
+
+ if (wd->selected_item != it)
+ {
+ wd->selected_item = it;
+ _selected_item_indicate(wd->selected_item);
+ }
+
+ if (it->func) it->func((void*) it->base.data, it->base.widget, it);
+}
+
+static void
_scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
Evas_Coord x, y, w, h, bw;
@@ -449,13 +522,13 @@
if (wd->round)
{
evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
- if (x > w / 3 * (wd->item_count + 1))
- elm_smart_scroller_child_region_show(wd->scroller,
- x - w / 3 * wd->item_count,
+ if (x > w / wd->display_item_num * (wd->item_count + (wd->display_item_num % 2)))
+ elm_smart_scroller_child_region_show(wd->scroller,
+ x - w / wd->display_item_num * wd->item_count,
y, w, h);
else if (x < 0)
- elm_smart_scroller_child_region_show(wd->scroller,
- x + w / 3 * wd->item_count,
+ elm_smart_scroller_child_region_show(wd->scroller,
+ x + w / wd->display_item_num * wd->item_count,
y, w, h);
}
}
@@ -522,7 +595,7 @@
}
evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
- elm_smart_scroller_child_region_show(wd->scroller, w / 3 * i, y, w, h);
+ elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
_select_item(dit);
if (wd->idler)
{
@@ -549,6 +622,9 @@
static void
_round_items_del(Widget_Data *wd)
{
+ Eina_List *l;
+ Elm_Diskselector_Item * it;
+
_round_item_del(wd, wd->last);
wd->last = NULL;
_round_item_del(wd, wd->s_last);
@@ -557,6 +633,18 @@
wd->second = NULL;
_round_item_del(wd, wd->first);
wd->first = NULL;
+
+ EINA_LIST_FOREACH(wd->under_items, l, it)
+ {
+ _round_item_del(wd, it);
+ it = NULL;
+ }
+
+ EINA_LIST_FOREACH(wd->over_items, l, it)
+ {
+ _round_item_del(wd, it);
+ it = NULL;
+ }
}
static void
@@ -564,7 +652,8 @@
{
Elm_Diskselector_Item *dit;
Elm_Diskselector_Item *it;
-
+ Elm_Diskselector_Item *temp_it;
+ int i = 0;
dit = it = eina_list_nth(wd->items, 0);
if (!dit) return;
@@ -587,6 +676,16 @@
wd->r_items = eina_list_append(wd->r_items, wd->second);
}
+ // if more than 3 itmes should be displayed
+ for(i = 2; i < CEIL(wd->display_item_num); i++)
+ {
+ it = eina_list_nth(wd->items, i);
+ if (!it) it = dit;
+ temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
+ wd->over_items = eina_list_append(wd->over_items, temp_it);
+ wd->r_items = eina_list_append(wd->r_items, temp_it);
+ }
+
it = eina_list_nth(wd->items, wd->item_count - 1);
if (!it)
it = dit;
@@ -608,6 +707,16 @@
wd->s_last->node = it->node;
wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
}
+
+ // if more than 3 itmes should be displayed
+ for(i = 3; i <= CEIL(wd->display_item_num); i++)
+ {
+ it = eina_list_nth(wd->items, wd->item_count - i);
+ if (!it) it = dit;
+ temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
+ wd->under_items = eina_list_append(wd->under_items, temp_it);
+ wd->r_items = eina_list_prepend(wd->r_items, temp_it);
+ }
}
/**
@@ -643,6 +752,7 @@
wd->round = EINA_FALSE;
wd->init = EINA_FALSE;
wd->len_side = 3;
+ wd->display_item_num = 3;
wd->scroller = elm_smart_scroller_add(evas_object_evas_get(parent));
elm_smart_scroller_widget_set(wd->scroller, obj);
@@ -735,6 +845,9 @@
EAPI void
elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
{
+ Eina_List *elist;
+ Elm_Diskselector_Item *it;
+
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
@@ -759,10 +872,19 @@
elm_box_pack_start(wd->main_box, wd->last->base.view);
if (wd->s_last)
elm_box_pack_start(wd->main_box, wd->s_last->base.view);
+
+ // if more than 3 items should be displayed
+ EINA_LIST_FOREACH(wd->under_items, elist, it)
+ elm_box_pack_start(wd->main_box, it->base.view);
+
if (wd->first)
elm_box_pack_end(wd->main_box, wd->first->base.view);
if (wd->second)
elm_box_pack_end(wd->main_box, wd->second->base.view);
+
+ // if more than 3 items should be displayed
+ EINA_LIST_FOREACH(wd->over_items, elist, it)
+ elm_box_pack_end(wd->main_box, it->base.view);
}
else
{
@@ -772,6 +894,8 @@
eina_list_free(wd->r_items);
wd->r_items = NULL;
}
+
+ _selected_item_indicate(wd->selected_item);
_sizing_eval(obj);
}
@@ -1014,6 +1138,9 @@
{
ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
Elm_Diskselector_Item *dit;
+ Elm_Diskselector_Item *item;
+ Eina_List *l;
+ int i = 0;
Widget_Data *wd = elm_widget_data_get(it->base.widget);
if (!wd) return;
@@ -1031,6 +1158,8 @@
wd->selected_item = dit;
else
wd->selected_item = eina_list_nth(wd->items, 1);
+
+ _selected_item_indicate(wd->selected_item);
}
_item_del(it);
@@ -1044,6 +1173,12 @@
evas_object_hide(wd->second->base.view);
evas_object_hide(wd->last->base.view);
evas_object_hide(wd->s_last->base.view);
+
+ EINA_LIST_FOREACH(wd->under_items, l, item)
+ evas_object_hide(item->base.view);
+
+ EINA_LIST_FOREACH(wd->over_items, l, item)
+ evas_object_hide(item->base.view);
}
else
{
@@ -1061,6 +1196,15 @@
edje_object_part_text_set(wd->second->base.view, "elm.text",
wd->second->label);
}
+ // if more than 3 itmes should be displayed
+ for(i = 2; i < CEIL(wd->display_item_num); i++)
+ {
+ dit = eina_list_nth(wd->items, i);
+ item = eina_list_nth(wd->over_items, i - 2);
+ eina_stringshare_replace(&item->label, dit->label);
+ edje_object_part_text_set(item->base.view, "elm.text", item->label);
+ }
+
dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
if (dit)
{
@@ -1075,6 +1219,14 @@
edje_object_part_text_set(wd->s_last->base.view, "elm.text",
wd->s_last->label);
}
+ // if more than 3 itmes should be displayed
+ for(i = 3; i <= CEIL(wd->display_item_num); i++)
+ {
+ dit = eina_list_nth(wd->items, wd->item_count - i);
+ item = eina_list_nth(wd->under_items, i - 3);
+ eina_stringshare_replace(&item->label, dit->label);
+ edje_object_part_text_set(item->base.view, "elm.text", item->label);
+ }
}
}
wd->check_idler = ecore_idler_add(_check_string, wd);
@@ -1156,7 +1308,10 @@
if ((wd->selected_item == it) && (!selected))
wd->selected_item = eina_list_data_get(wd->items);
else
- wd->selected_item = it;
+ {
+ wd->selected_item = it;
+ _selected_item_indicate(wd->selected_item);
+ }
if (!wd->idler)
ecore_idler_add(_move_scroller, it->base.widget);
@@ -1541,3 +1696,21 @@
ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
return elm_widget_item_cursor_engine_only_get(item);
}
+/**
+ * Set the number of items to be displayed
+ *
+ * @param obj The diskselector object
+ * @param num The number of itmes that diskselector will display
+ *
+ * @ingroup Diskselector
+ */
+EAPI void
+elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ wd->display_item_num = num;
+}
+
+
Index: src/lib/Elementary.h.in
===================================================================
--- src/lib/Elementary.h.in (revision 57821)
+++ src/lib/Elementary.h.in (working copy)
@@ -2449,6 +2449,7 @@
EAPI const char *elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item) EINA_ARG_NONNULL(1);
EAPI void elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only) EINA_ARG_NONNULL(1);
EAPI Eina_Bool elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item) EINA_ARG_NONNULL(1);
+ EAPI void elm_diskselector_display_item_num_set(Evas_Object *obj, int num) EINA_ARG_NONNULL(1);
/* smart callbacks called:
* "selected" - when item is selected (scroller stops)
*/
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel