Fix items alignment in Gengrid.

Now alignment works no matter whether the item is smaller than the grid or not.
Also added a spinner to Gengrid 2 test so we can see the alignment in action
for different item sizes.



SVN revision: 53252
This commit is contained in:
Rafael Fonseca 2010-10-11 01:55:07 +00:00
parent c2b339a567
commit 105aeb5967
2 changed files with 48 additions and 21 deletions

View File

@ -253,6 +253,14 @@ _append_bt_clicked(void *data, Evas_Object *obj, void *event_info)
ti->item = elm_gengrid_item_append(grid, &gic, ti, grid_sel, NULL);
}
static void
_size_changed(void *data, Evas_Object *obj, void *event_info)
{
Evas_Object *grid = data;
int size = elm_spinner_value_get(obj);
elm_gengrid_item_size_set(grid, size, size);
}
void
test_gengrid2(void *data, Evas_Object *obj, void *event_info)
{
@ -312,6 +320,15 @@ test_gengrid2(void *data, Evas_Object *obj, void *event_info)
elm_box_pack_end(hbx, bt);
evas_object_show(bt);
bt = elm_spinner_add(win);
elm_spinner_min_max_set(bt, 10, 1024);
elm_spinner_value_set(bt, 150);
elm_spinner_label_format_set(bt, "Item size: %.0f");
evas_object_smart_callback_add(bt, "changed", _size_changed, grid);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_pack_end(hbx, bt);
evas_object_show(bt);
gic.item_style = "default";
gic.func.label_get = grid_label_get;
gic.func.icon_get = grid_icon_get;

View File

@ -919,46 +919,56 @@ _item_place(Elm_Gengrid_Item *item, Evas_Coord cx, Evas_Coord cy)
cvw = vw + 2 * PRELOAD * item->wd->item_width;
cvh = vh + 2 * PRELOAD * item->wd->item_height;
tch = (vh * item->wd->item_height) / item->wd->item_height;
alignh = (vh - tch) * item->wd->align_y;
alignh = 0;
alignw = 0;
tcw = (vw * item->wd->item_width) / item->wd->item_width;
alignw = (vw - tcw) * item->wd->align_x;
if ((item->wd->horizontal) && (item->wd->minw < vw))
if (item->wd->horizontal)
{
int columns, items_visible;
int columns, items_visible, items_row;
items_visible = vh / item->wd->item_height;
if (items_visible < 1)
items_visible = 1;
items_visible = 1;
columns = item->wd->count / items_visible;
if (item->wd->count % items_visible)
columns++;
columns++;
tcw = item->wd->item_width * columns;
alignw = (vw - tcw) * item->wd->align_x;
if (item->wd->minw < vw)
{
tcw = item->wd->item_width * columns;
alignw = (vw - tcw) * item->wd->align_x;
}
items_row = items_visible;
if (items_row > item->wd->count)
items_row = item->wd->count;
tch = items_row * item->wd->item_height;
alignh = (vh - tch) * item->wd->align_y;
}
else if ((item->wd->horizontal) && (item->wd->minw > vw))
alignw = 0;
if ((!item->wd->horizontal) && (item->wd->minh < vh))
else
{
int rows, items_visible;
int rows, items_visible, items_col;
items_visible = vw / item->wd->item_width;
if (items_visible < 1)
items_visible = 1;
items_visible = 1;
rows = item->wd->count / items_visible;
if (item->wd->count % items_visible)
rows++;
rows++;
tch = item->wd->item_height * rows;
alignh = (vh - tch)*item->wd->align_y;
if (item->wd->minh < vh)
{
tch = item->wd->item_height * rows;
alignh = (vh - tch) * item->wd->align_y;
}
items_col = items_visible;
if (items_col > item->wd->count)
items_col = item->wd->count;
tcw = items_col * item->wd->item_width;
alignw = (vw - tcw) * item->wd->align_x;
}
else if ((!item->wd->horizontal) && (item->wd->minh > vh))
alignh = 0;
x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;