Gengrid: improve item_region_show code

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.
This commit is contained in:
Davide Andreoli 2016-01-17 15:11:29 +01:00
parent df74a34942
commit 16b16b7128
2 changed files with 8 additions and 32 deletions

View 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;

View 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)