summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2014-07-09 15:09:43 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-07-09 15:09:43 +0900
commit4bdf40f03900710d16aacee44a0a666766857afc (patch)
treece5205beb88e6689b6338e231e38b856573ca38c
parent6805e484a2c95ec2ec3cbd18fd859d278e0705e4 (diff)
gengrid: Added normal reorder type
Summary: - Added Elm_Gengrid_Reorder_Type enum - Added API elm_gengrid_reorder_type_set() - Implemented the normal reorder type animation - The old reorder type is changed to ELM_GENGRID_REORDER_TYPE_SWAP. - ELM_GENGRID_REORDER_TYPE_NORMAL is the default reorder type. Test Plan: 1. elementary_test->"Gengrid Focus" 2. Enable "Reorder Mode Enable" 3. Move the items by keys @feature Reviewers: raster, seoz CC: seoz, chinmaya061, aryarockstar Differential Revision: https://phab.enlightenment.org/D813
-rw-r--r--src/lib/elm_gengrid.c200
-rw-r--r--src/lib/elm_gengrid_legacy.h19
-rw-r--r--src/lib/elm_widget_gengrid.h2
3 files changed, 207 insertions, 14 deletions
diff --git a/src/lib/elm_gengrid.c b/src/lib/elm_gengrid.c
index b44f316a2..26ea778d7 100644
--- a/src/lib/elm_gengrid.c
+++ b/src/lib/elm_gengrid.c
@@ -2056,6 +2056,26 @@ get_down_item(Elm_Gengrid_Data *sd, Elm_Object_Item *it)
2056 return next; 2056 return next;
2057} 2057}
2058 2058
2059typedef struct _Item_Info
2060{
2061 Elm_Gen_Item *it;
2062 Evas_Coord x, y;
2063} Item_Info;
2064
2065typedef struct _Reorder_Normal_Data
2066{
2067 Item_Info *items;
2068 Elm_Gen_Item *corner_item;
2069 int no;
2070} Reorder_Normal_Data;
2071
2072static void
2073_free_reorder_normal_data(Reorder_Normal_Data *rnd)
2074{
2075 free(rnd->items);
2076 free(rnd);
2077}
2078
2059static void 2079static void
2060_anim_end(Elm_Gengrid_Data *sd) 2080_anim_end(Elm_Gengrid_Data *sd)
2061{ 2081{
@@ -2064,8 +2084,34 @@ _anim_end(Elm_Gengrid_Data *sd)
2064 it1_prev = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(sd->reorder.it1)->prev); 2084 it1_prev = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(sd->reorder.it1)->prev);
2065 it2_prev = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(sd->reorder.it2)->prev); 2085 it2_prev = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(sd->reorder.it2)->prev);
2066 2086
2067 if ((!sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_UP) || (sd->reorder.dir == ELM_FOCUS_DOWN))) || 2087 if ((sd->reorder.type == ELM_GENGRID_REORDER_TYPE_NORMAL) &&
2068 (sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_LEFT) || (sd->reorder.dir == ELM_FOCUS_RIGHT)))) 2088 ((!sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_UP) || (sd->reorder.dir == ELM_FOCUS_DOWN))) ||
2089 (sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_LEFT) || (sd->reorder.dir == ELM_FOCUS_RIGHT)))))
2090 {
2091 sd->items = eina_inlist_remove(sd->items, EINA_INLIST_GET(sd->reorder.it1));
2092 if ((sd->reorder.dir == ELM_FOCUS_UP) ||
2093 (sd->reorder.dir == ELM_FOCUS_LEFT))
2094 {
2095 if (it2_prev)
2096 {
2097 tmp = eina_inlist_find(sd->items, EINA_INLIST_GET(it2_prev));
2098 sd->items = eina_inlist_append_relative(sd->items, EINA_INLIST_GET(sd->reorder.it1),
2099 tmp);
2100 }
2101 else
2102 sd->items = eina_inlist_prepend(sd->items, EINA_INLIST_GET(sd->reorder.it1));
2103 }
2104 else if ((sd->reorder.dir == ELM_FOCUS_DOWN) ||
2105 (sd->reorder.dir == ELM_FOCUS_RIGHT))
2106 {
2107 tmp = eina_inlist_find(sd->items, EINA_INLIST_GET(sd->reorder.it2));
2108 sd->items = eina_inlist_append_relative(sd->items, EINA_INLIST_GET(sd->reorder.it1),
2109 tmp);
2110 }
2111 }
2112 else if ((sd->reorder.type == ELM_GENGRID_REORDER_TYPE_SWAP) &&
2113 ((!sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_UP) || (sd->reorder.dir == ELM_FOCUS_DOWN))) ||
2114 (sd->horizontal && ((sd->reorder.dir == ELM_FOCUS_LEFT) || (sd->reorder.dir == ELM_FOCUS_RIGHT)))))
2069 { 2115 {
2070 sd->items = eina_inlist_remove(sd->items, EINA_INLIST_GET(sd->reorder.it1)); 2116 sd->items = eina_inlist_remove(sd->items, EINA_INLIST_GET(sd->reorder.it1));
2071 sd->items = eina_inlist_remove(sd->items, EINA_INLIST_GET(sd->reorder.it2)); 2117 sd->items = eina_inlist_remove(sd->items, EINA_INLIST_GET(sd->reorder.it2));
@@ -2189,18 +2235,37 @@ _item_move_cb(void *data, double pos)
2189 2235
2190 dx = sd->reorder.x2 - sd->reorder.x1; 2236 dx = sd->reorder.x2 - sd->reorder.x1;
2191 dy = sd->reorder.y2 - sd->reorder.y1; 2237 dy = sd->reorder.y2 - sd->reorder.y1;
2192 xx1 = sd->reorder.x1 + dx * frame; 2238 xx1 = sd->reorder.x1 + (dx * frame);
2193 yy1 = sd->reorder.y1 + dy * frame; 2239 yy1 = sd->reorder.y1 + (dy * frame);
2194 2240
2195 xx2 = sd->reorder.x2 - dx * frame; 2241 if (sd->reorder.type == ELM_GENGRID_REORDER_TYPE_NORMAL)
2196 yy2 = sd->reorder.y2 - dy * frame; 2242 {
2243 int i = 0;
2244 Reorder_Normal_Data *rnd = sd->reorder.data;
2245
2246 for (;i < rnd->no; i++)
2247 {
2248 dx = rnd->items[i + 1].x - rnd->items[i].x;
2249 dy = rnd->items[i + 1].y - rnd->items[i].y;
2250 xx2 = rnd->items[i].x + (frame * dx);
2251 yy2 = rnd->items[i].y + (frame * dy);
2252 evas_object_move(VIEW(rnd->items[i].it), xx2, yy2);
2253 }
2254 }
2255 else if (sd->reorder.type == ELM_GENGRID_REORDER_TYPE_SWAP)
2256 {
2257 xx2 = sd->reorder.x2 - (dx * frame);
2258 yy2 = sd->reorder.y2 - (dy * frame);
2259 evas_object_move(VIEW(sd->reorder.it2), xx2, yy2);
2260 }
2197 2261
2198 evas_object_move(VIEW(sd->reorder.it1), xx1, yy1); 2262 evas_object_move(VIEW(sd->reorder.it1), xx1, yy1);
2199 evas_object_move(VIEW(sd->reorder.it2), xx2, yy2);
2200 2263
2201 if (pos == 1.0) 2264 if (pos == 1.0)
2202 { 2265 {
2203 _anim_end(sd); 2266 _anim_end(sd);
2267 if (sd->reorder.type == ELM_GENGRID_REORDER_TYPE_NORMAL)
2268 _free_reorder_normal_data(sd->reorder.data);
2204 elm_gengrid_item_show((Elm_Object_Item *)sd->reorder.it1, 2269 elm_gengrid_item_show((Elm_Object_Item *)sd->reorder.it1,
2205 ELM_GENGRID_ITEM_SCROLLTO_IN); 2270 ELM_GENGRID_ITEM_SCROLLTO_IN);
2206 evas_object_smart_callback_call(sd->obj, SIG_ITEM_REORDER_START, 2271 evas_object_smart_callback_call(sd->obj, SIG_ITEM_REORDER_START,
@@ -2213,11 +2278,105 @@ _item_move_cb(void *data, double pos)
2213} 2278}
2214 2279
2215static void 2280static void
2281_store_nearby_items(Elm_Gengrid_Data *sd)
2282{
2283 Reorder_Normal_Data *rnd = sd->reorder.data;
2284 Eina_Inlist *itr;
2285 Evas_Coord x, y, cvw, cvh, col = 0, row = 0;
2286 int i = 0;
2287 int corner_item_pos = 0;
2288 Eina_Inlist *it1_list, *it2_list;
2289
2290 evas_object_geometry_get(sd->pan_obj, NULL, NULL, &cvw, &cvh);
2291
2292 rnd->no = abs(sd->reorder.it2->position - sd->reorder.it1->position);
2293 rnd->items = malloc(sizeof(Item_Info) * (rnd->no + 1));
2294
2295 if (sd->horizontal && sd->item_height > 0)
2296 {
2297 row = cvh / sd->item_height;
2298 if (row <= 0) row = 1;
2299 if (sd->reorder.dir == ELM_FOCUS_RIGHT)
2300 {
2301 corner_item_pos = (sd->reorder.it2->position + 1) / row;
2302 corner_item_pos = corner_item_pos * row;
2303 corner_item_pos = sd->reorder.it2->position - corner_item_pos;
2304 }
2305 else if (sd->reorder.dir == ELM_FOCUS_LEFT)
2306 {
2307 corner_item_pos = (sd->reorder.it2->position + 1) / row;
2308 corner_item_pos = (corner_item_pos + 1) * row;
2309 corner_item_pos = corner_item_pos - sd->reorder.it2->position;
2310 }
2311 }
2312 else if (sd->item_width > 0)
2313 {
2314 col = cvw / sd->item_width;
2315 if (col <= 0) col = 1;
2316 if (sd->reorder.dir == ELM_FOCUS_DOWN)
2317 {
2318 corner_item_pos = (sd->reorder.it2->position + 1) / col;
2319 corner_item_pos = corner_item_pos * col;
2320 corner_item_pos = sd->reorder.it2->position - corner_item_pos;
2321 }
2322 else if (sd->reorder.dir == ELM_FOCUS_UP)
2323 {
2324 corner_item_pos = (sd->reorder.it2->position + 1) / col;
2325 corner_item_pos = (corner_item_pos + 1) * col;
2326 corner_item_pos = corner_item_pos - sd->reorder.it2->position;
2327 }
2328 }
2329
2330 it1_list = eina_inlist_find(sd->items, EINA_INLIST_GET(sd->reorder.it1));
2331 it2_list = eina_inlist_find(sd->items, EINA_INLIST_GET(sd->reorder.it2));
2332
2333 if ((sd->reorder.it1->position) < (sd->reorder.it2)->position)
2334 {
2335 for (itr = it2_list; itr != it1_list; itr = itr->prev)
2336 {
2337 Elm_Gen_Item *cur = EINA_INLIST_CONTAINER_GET(itr, Elm_Gen_Item);
2338 evas_object_geometry_get(VIEW(cur), &x, &y, NULL, NULL);
2339 rnd->items[i].it = cur;
2340 rnd->items[i].x = x;
2341 rnd->items[i].y = y;
2342 if (i == (corner_item_pos - 1))
2343 rnd->corner_item = cur;
2344 i++;
2345 }
2346 rnd->items[i].it = sd->reorder.it1;
2347 rnd->items[i].x = sd->reorder.x1;
2348 rnd->items[i].y = sd->reorder.y1;
2349 }
2350 else if (sd->reorder.it1->position > sd->reorder.it2->position)
2351 {
2352 for (itr = it2_list; itr != it1_list; itr = itr->next)
2353 {
2354 Elm_Gen_Item *cur = EINA_INLIST_CONTAINER_GET(itr, Elm_Gen_Item);
2355 evas_object_geometry_get(VIEW(cur), &x, &y, NULL, NULL);
2356 rnd->items[i].it = cur;
2357 rnd->items[i].x = x;
2358 rnd->items[i].y = y;
2359 if (i == (corner_item_pos - 1))
2360 rnd->corner_item = cur;
2361 i++;
2362 }
2363 rnd->items[i].it = sd->reorder.it1;
2364 rnd->items[i].x = sd->reorder.x1;
2365 rnd->items[i].y = sd->reorder.y1;
2366 }
2367}
2368
2369static void
2216_swap_items(Elm_Gen_Item *it1, Elm_Gen_Item *it2, Elm_Focus_Direction dir) 2370_swap_items(Elm_Gen_Item *it1, Elm_Gen_Item *it2, Elm_Focus_Direction dir)
2217{ 2371{
2218 ELM_GENGRID_DATA_GET(WIDGET(it1), sd); 2372 ELM_GENGRID_DATA_GET(WIDGET(it1), sd);
2219 Evas_Coord xx1, yy1, xx2, yy2; 2373 Evas_Coord xx1, yy1, xx2, yy2;
2220 2374
2375 sd->reorder.running = EINA_TRUE;
2376 sd->reorder.dir = dir;
2377 sd->reorder.it1 = it1;
2378 sd->reorder.it2 = it2;
2379
2221 evas_object_geometry_get(VIEW(it1), &xx1, &yy1, NULL, NULL); 2380 evas_object_geometry_get(VIEW(it1), &xx1, &yy1, NULL, NULL);
2222 evas_object_geometry_get(VIEW(it2), &xx2, &yy2, NULL, NULL); 2381 evas_object_geometry_get(VIEW(it2), &xx2, &yy2, NULL, NULL);
2223 sd->reorder.x1 = xx1; 2382 sd->reorder.x1 = xx1;
@@ -2225,13 +2384,16 @@ _swap_items(Elm_Gen_Item *it1, Elm_Gen_Item *it2, Elm_Focus_Direction dir)
2225 sd->reorder.x2 = xx2; 2384 sd->reorder.x2 = xx2;
2226 sd->reorder.y2 = yy2; 2385 sd->reorder.y2 = yy2;
2227 2386
2228 sd->reorder.running = EINA_TRUE; 2387 if (sd->reorder.type == ELM_GENGRID_REORDER_TYPE_NORMAL)
2229 sd->reorder.dir = dir; 2388 {
2230 sd->reorder.it1 = it1; 2389 Reorder_Normal_Data *rnd = malloc(sizeof(Reorder_Normal_Data));
2231 sd->reorder.it2 = it2; 2390 memset(rnd, 0, sizeof(Reorder_Normal_Data));
2232 2391 sd->reorder.data = rnd;
2233 evas_object_raise(VIEW(it2)); 2392 _store_nearby_items(sd);
2234 evas_object_stack_above(VIEW(it1), VIEW(it2)); 2393 if (rnd->corner_item)
2394 evas_object_raise(VIEW(rnd->corner_item));
2395 }
2396 evas_object_raise(VIEW(it1));
2235 evas_object_smart_callback_call(sd->obj, SIG_ITEM_REORDER_STOP, 2397 evas_object_smart_callback_call(sd->obj, SIG_ITEM_REORDER_STOP,
2236 sd->reorder.it1); 2398 sd->reorder.it1);
2237 //TODO: Add elm config for time 2399 //TODO: Add elm config for time
@@ -4008,6 +4170,7 @@ elm_gengrid_reorder_mode_start(Evas_Object *obj, Ecore_Pos_Map tween_mode)
4008 4170
4009 sd->reorder_mode = EINA_TRUE; 4171 sd->reorder_mode = EINA_TRUE;
4010 sd->reorder.tween_mode = tween_mode; 4172 sd->reorder.tween_mode = tween_mode;
4173 sd->reorder.type = ELM_GENGRID_REORDER_TYPE_NORMAL;
4011} 4174}
4012 4175
4013EAPI void 4176EAPI void
@@ -4020,6 +4183,15 @@ elm_gengrid_reorder_mode_stop(Evas_Object *obj)
4020 sd->reorder.tween_mode = -1; 4183 sd->reorder.tween_mode = -1;
4021} 4184}
4022 4185
4186EAPI void
4187elm_gengrid_reorder_type_set(Evas_Object *obj, Elm_Gengrid_Reorder_Type type)
4188{
4189 ELM_GENGRID_CHECK(obj);
4190 ELM_GENGRID_DATA_GET(obj, sd);
4191
4192 sd->reorder.type = type;
4193}
4194
4023EOLIAN static void 4195EOLIAN static void
4024_elm_gengrid_reorder_mode_set(Eo *obj EINA_UNUSED, Elm_Gengrid_Data *sd, Eina_Bool reorder_mode) 4196_elm_gengrid_reorder_mode_set(Eo *obj EINA_UNUSED, Elm_Gengrid_Data *sd, Eina_Bool reorder_mode)
4025{ 4197{
diff --git a/src/lib/elm_gengrid_legacy.h b/src/lib/elm_gengrid_legacy.h
index 3b4ce69ab..6c2602d08 100644
--- a/src/lib/elm_gengrid_legacy.h
+++ b/src/lib/elm_gengrid_legacy.h
@@ -211,6 +211,12 @@ EINA_DEPRECATED EAPI void elm_gengrid_last_page_get(const Evas_Object *
211 */ 211 */
212EINA_DEPRECATED EAPI void elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber); 212EINA_DEPRECATED EAPI void elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber);
213 213
214typedef enum _Elm_Gengrid_Reorder_Type
215{
216 ELM_GENGRID_REORDER_TYPE_NORMAL,
217 ELM_GENGRID_REORDER_TYPE_SWAP
218} Elm_Gengrid_Reorder_Type;
219
214/** 220/**
215 * Enable the gengrid widget mode reordered with keys 221 * Enable the gengrid widget mode reordered with keys
216 * 222 *
@@ -237,4 +243,17 @@ EAPI void elm_gengrid_reorder_mode_start(Evas_Object *obj
237 */ 243 */
238EAPI void elm_gengrid_reorder_mode_stop(Evas_Object *obj); 244EAPI void elm_gengrid_reorder_mode_stop(Evas_Object *obj);
239 245
246/**
247 * Set the reorder type
248 *
249 * @param obj The gengrid object
250 * @param type Elm_Gengrid_Reorder_Type value
251 *
252 * @see Elm_Gengrid_Reorder_Type
253 * @since 1.10
254 *
255 * @ingroup Gengrid
256 */
257EAPI void elm_gengrid_reorder_type_set(Evas_Object *obj, Elm_Gengrid_Reorder_Type type);
258
240#include "elm_gengrid.eo.legacy.h" 259#include "elm_gengrid.eo.legacy.h"
diff --git a/src/lib/elm_widget_gengrid.h b/src/lib/elm_widget_gengrid.h
index a44d0fc98..a2b94c238 100644
--- a/src/lib/elm_widget_gengrid.h
+++ b/src/lib/elm_widget_gengrid.h
@@ -77,9 +77,11 @@ struct _Elm_Gengrid_Data
77 struct 77 struct
78 { 78 {
79 Elm_Gen_Item *it1, *it2; /**< The items which are getting swapped */ 79 Elm_Gen_Item *it1, *it2; /**< The items which are getting swapped */
80 void *data; /**< This is the data used to store information related to animation */
80 Elm_Focus_Direction dir; /**< focus key direction */ 81 Elm_Focus_Direction dir; /**< focus key direction */
81 Ecore_Pos_Map tween_mode; /**< Position mappings for animation */ 82 Ecore_Pos_Map tween_mode; /**< Position mappings for animation */
82 Evas_Coord x1, y1, x2, y2; /**< Coordinates of it1 and it2 */ 83 Evas_Coord x1, y1, x2, y2; /**< Coordinates of it1 and it2 */
84 Elm_Gengrid_Reorder_Type type; /**< Reorder type */
83 Eina_Bool running : 1; /**< animation is happening */ 85 Eina_Bool running : 1; /**< animation is happening */
84 } reorder; 86 } reorder;
85 87