Gengrid: improve item_region_show code
authorDave Andreoli <dave@gurumeditation.it>
Sun, 17 Jan 2016 14:11:29 +0000 (15:11 +0100)
committerDave Andreoli <dave@gurumeditation.it>
Sun, 17 Jan 2016 14:11:29 +0000 (15:11 +0100)
There is no need to recalc row and col position of the item, they are already stored in the item struct.

The old implementation was calculating wrong values and also was storing this wrong values in it->x and it->y, resulting in wrong results for the elm_gengrid_item_pos_get() function.

so, at the end,  this is a @fix for the pos_get() function.

Also changed a bit the test to let the gengrid fill the window and thus testing behaviour on col/row changes.

I didn't find any regression in all the gengrid tests after this, let me know if it broke something for you.

legacy/elementary/src/bin/test_gengrid.c
legacy/elementary/src/lib/elm_gengrid.c

index 6ba3622..bd74e5b 100644 (file)
@@ -1306,6 +1306,7 @@ test_gengrid4(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_
    elm_gengrid_item_class_free(gic);
    elm_gengrid_item_show(ti[2579].item, sd->scrollto);
    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_size_hint_min_set(grid, 600, 400);
    evas_object_show(grid);
    sd->grid = grid;
index 7661995..02b1294 100644 (file)
@@ -328,14 +328,13 @@ static void
 _item_show_region(void *data)
 {
    Elm_Gengrid_Data *sd = data;
-   Evas_Coord cvw, cvh, it_xpos = 0, it_ypos = 0, col = 0, row = 0, minx = 0, miny = 0;
+   Evas_Coord cvw, cvh, it_xpos = 0, it_ypos = 0, minx = 0, miny = 0;
    Evas_Coord vw = 0, vh = 0;
    Elm_Object_Item *eo_it = NULL;
    evas_object_geometry_get(sd->pan_obj, NULL, NULL, &cvw, &cvh);
 
    if ((cvw != 0) && (cvh != 0))
        {
-          int x = 0, y = 0;
           if (sd->show_region)
             eo_it = sd->show_it;
           else if (sd->bring_in)
@@ -347,45 +346,21 @@ _item_show_region(void *data)
           eo_do(sd->pan_obj, elm_obj_pan_pos_min_get(&minx, &miny));
           if (sd->horizontal && (sd->item_height > 0))
             {
-               row = cvh / sd->item_height;
-               if (row <= 0) row = 1;
-               x = (it->position - 1) / row;
-               if (elm_widget_mirrored_get(sd->obj))
-                 {
-                    col = sd->item_count / row;
-                    if (sd->item_count % row == 0)
-                      col--;
-                    x = col - x;
-                 }
-
-               y = (it->position - 1) % row;
-               if (x >= 1)
-                 it_xpos = ((x - GG_IT(it)->prev_group) * sd->item_width)
+               if (it->x >= 1)
+                 it_xpos = ((it->x - GG_IT(it)->prev_group) * sd->item_width)
                     + (GG_IT(it)->prev_group * sd->group_item_width)
                     + minx;
                else it_xpos = minx;
-               miny = miny + ((cvh - (sd->item_height * row))
-                    * sd->align_y);
-               it_ypos = y * sd->item_height + miny;
-               it->x = x;
-               it->y = y;
+               it_ypos = it->y * sd->item_height + miny;
             }
           else if (sd->item_width > 0)
             {
-               col = cvw / sd->item_width;
-               if (col <= 0) col = 1;
-               y = (it->position - 1) / col;
-               x = (it->position - 1) % col;
-               it_xpos = x * sd->item_width + minx;
-               if (y >= 1)
-                 it_ypos = ((y - GG_IT(it)->prev_group) * sd->item_height)
+               it_xpos = it->x * sd->item_width + minx;
+               if (it->y >= 1)
+                 it_ypos = ((it->y - GG_IT(it)->prev_group) * sd->item_height)
                     + (GG_IT(it)->prev_group * sd->group_item_height)
                     + miny;
                else it_ypos = miny;
-               minx = minx + ((cvw - (sd->item_width * col))
-                    * sd->align_x);
-               it->x = x;
-               it->y = y;
             }
 
           switch (sd->scroll_to_type)