typedef struct _Pan Pan;
#define PRELOAD 1
+#define REORDER_EFFECT_TIME 0.5
struct _Elm_Gengrid_Item
{
Evas_Object *spacer;
const Elm_Gengrid_Item_Class *gic;
Ecore_Timer *long_timer;
+ Ecore_Animator *item_moving_effect_timer;
Widget_Data *wd;
Eina_List *labels, *icons, *states, *icon_objs;
struct
const void *data;
} func;
- Evas_Coord x, y, dx, dy;
- int relcount;
- int walking;
+ Evas_Coord x, y, dx, dy, ox, oy, tx, ty, rx, ry;
+ unsigned int moving_effect_start_time;
+ int relcount;
+ int walking;
struct
{
Eina_Bool disabled : 1;
Eina_Bool selected : 1;
Eina_Bool hilighted : 1;
+ Eina_Bool moving : 1;
};
struct _Widget_Data
Elm_Gengrid_Item *last_selected_item, *reorder_item;
double align_x, align_y;
- Evas_Coord pan_x, pan_y;
+ Evas_Coord pan_x, pan_y, old_pan_x, old_pan_y;
Evas_Coord item_width, item_height; /* Each item size */
Evas_Coord minw, minh; /* Total obj size */
Evas_Coord reorder_item_x, reorder_item_y;
Eina_Bool v_bounce : 1;
Eina_Bool reorder_mode : 1;
Eina_Bool reorder_item_changed : 1;
+ Eina_Bool move_effect_enabled : 1;
};
#define ELM_GENGRID_ITEM_FROM_INLIST(item) \
{NULL, NULL}
};
-
+static Eina_Compare_Cb _elm_gengrid_item_compare_cb;
+static Eina_Compare_Cb _elm_gengrid_item_compare_data_cb;
static Eina_Bool
_event_hook(Evas_Object *obj,
{
item = elm_gengrid_selected_item_get(obj);
evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
- evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
}
else return EINA_FALSE;
item->want_unrealize = EINA_FALSE;
}
+static Eina_Bool
+_reorder_item_moving_effect_timer_cb(void *data)
+{
+ Elm_Gengrid_Item *item = data;
+ double time, t;
+ Evas_Coord dx, dy;
+
+ time = REORDER_EFFECT_TIME;
+ t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
+ dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
+ dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
+
+ if (t <= time)
+ {
+ item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
+ item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
+ }
+ else
+ {
+ item->rx += dx;
+ item->ry += dy;
+ }
+
+ if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
+ (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
+ {
+ evas_object_move(item->base.view, item->tx, item->ty);
+ evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+ item->moving = EINA_FALSE;
+ item->item_moving_effect_timer = NULL;
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ evas_object_move(item->base.view, item->rx, item->ry);
+ evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+
+ return ECORE_CALLBACK_RENEW;
+}
+
static void
_item_place(Elm_Gengrid_Item *item,
Evas_Coord cx,
evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
if ((item->wd->reorder_mode) && (item->wd->reorder_item))
{
+ if (item->moving) return;
+
+ if (!item->wd->move_effect_enabled)
+ {
+ item->ox = x;
+ item->oy = y;
+ }
if (item->wd->reorder_item == item)
{
evas_object_move(item->base.view,
}
else
{
+ if (item->wd->move_effect_enabled)
+ {
+ if ((item->ox != x) || (item->oy != y))
+ {
+ if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
+ ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
+ ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
+ {
+ item->tx = x;
+ item->ty = y;
+ item->rx = item->ox;
+ item->ry = item->oy;
+ item->moving = EINA_TRUE;
+ item->moving_effect_start_time = ecore_loop_time_get();
+ item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
+ return;
+ }
+ }
+ }
+
if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
item->wd->item_width, item->wd->item_height,
x+(item->wd->item_width/2), y+(item->wd->item_height/2),
EINA_INLIST_GET(item));
item->wd->reorder_item_changed = EINA_TRUE;
-
+ item->wd->move_effect_enabled = EINA_TRUE;
if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
item->walking--;
item->wd->walking--;
+ item->wd->last_selected_item = item;
if ((item->wd->clear_me) && (!item->wd->walking))
elm_gengrid_clear(item->base.widget);
else
if ((!item->walking) && (item->delete_me))
if (!item->relcount) _item_del(item);
}
- item->wd->last_selected_item = item;
}
static void
if (!cx) cy++;
}
}
+
+ if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
+ {
+ if (!sd->wd->reorder_item_changed)
+ {
+ sd->wd->old_pan_x = sd->wd->pan_x;
+ sd->wd->old_pan_y = sd->wd->pan_y;
+ }
+ sd->wd->move_effect_enabled = EINA_FALSE;
+ }
evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
}
evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
}
+static int
+_elm_gengrid_item_compare_data(const void *data, const void *data1)
+{
+ const Elm_Gengrid_Item *item = data;
+ const Elm_Gengrid_Item *item1 = data1;
+
+ return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
+}
+
+static int
+_elm_gengrid_item_compare(const void *data, const void *data1)
+{
+ Elm_Gengrid_Item *item, *item1;
+ item = ELM_GENGRID_ITEM_FROM_INLIST(data);
+ item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
+ return _elm_gengrid_item_compare_cb(item, item1);
+}
+
/**
* Add a new Gengrid object.
*
return item;
}
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_direct_sorted_insert(Evas_Object *obj,
+ const Elm_Gengrid_Item_Class *gic,
+ const void *data,
+ Eina_Compare_Cb comp,
+ Evas_Smart_Cb func,
+ const void *func_data)
+{
+ Elm_Gengrid_Item *item;
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return NULL;
+
+ item = _item_create(wd, gic, data, func, func_data);
+ if (!item) return NULL;
+
+ _elm_gengrid_item_compare_cb = comp;
+ wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(item),
+ _elm_gengrid_item_compare);
+ if (wd->calc_job) ecore_job_del(wd->calc_job);
+ wd->calc_job = ecore_job_add(_calc_job, wd);
+
+ return item;
+}
+
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_sorted_insert(Evas_Object *obj,
+ const Elm_Gengrid_Item_Class *gic,
+ const void *data,
+ Eina_Compare_Cb comp,
+ Evas_Smart_Cb func,
+ const void *func_data)
+{
+ _elm_gengrid_item_compare_data_cb = comp;
+
+ return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
+}
+
/**
* Remove an item from the Gengrid.
*
elm_gengrid_item_update(item);
}
+EAPI const Elm_Gengrid_Item_Class *
+elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
+{
+ ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
+ if (item->delete_me) return NULL;
+ return item->gic;
+}
+
+EAPI void
+elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
+ const Elm_Gengrid_Item_Class *gic)
+{
+ ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
+ EINA_SAFETY_ON_NULL_RETURN(gic);
+ if (item->delete_me) return;
+ item->gic = gic;
+ elm_gengrid_item_update(item);
+}
+
/**
* Get the item's coordinates.
*
if (!label)
return NULL;
elm_object_style_set(label, "tooltip");
- elm_label_label_set(label, data);
+ elm_object_text_set(label, data);
return label;
}