Page MenuHomePhabricator

File Metadata

Author
SanghyeonLee
Created
Sep 9 2018, 11:10 PM

gengrid_example_1.c

/**
* Simple Elementary's <b>gengrid widget</b> example, illustrating its
* usage and API.
*
* See stdout/stderr for output. Compile with:
*
* @verbatim
* gcc -g gengrid_example_1.c -o gengrid_example_1 `pkg-config --cflags --libs elementary`
* @endverbatim
*/
#include <Elementary.h>
typedef struct _Example_Item
{
const char *path;
} Example_Item;
static const char *imgs[9] =
{
"panel_01.jpg",
"plant_01.jpg",
"rock_01.jpg",
"rock_02.jpg",
"sky_01.jpg",
"sky_02.jpg",
"sky_03.jpg",
"sky_04.jpg",
"wood_01.jpg",
};
static Elm_Gengrid_Item_Class *gic = NULL;
static Evas_Object *before_bt, *after_bt;
Example_Item* _item_new(void)
{
Example_Item *it;
it = malloc(sizeof(*it));
it->path = eina_stringshare_add(imgs[rand() % (sizeof(imgs) /
sizeof(imgs[0]))]);
return it;
}
/* label fetching callback */
static char *
_grid_label_get(void *data,
Evas_Object *obj EINA_UNUSED,
const char *part EINA_UNUSED)
{
const Example_Item *it = data;
char buf[256];
snprintf(buf, sizeof(buf), "Photo %s", it->path);
return strdup(buf);
}
/* icon fetching callback */
static Evas_Object *
_grid_content_get(void *data,
Evas_Object *obj,
const char *part)
{
const Example_Item *it = data;
if (!strcmp(part, "elm.swallow.icon"))
{
Evas_Object *icon = elm_bg_add(obj);
char buf[PATH_MAX];
snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(),
it->path);
elm_bg_file_set(icon, buf, NULL);
evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1,
1);
evas_object_show(icon);
return icon;
}
else if (!strcmp(part, "elm.swallow.end"))
{
Evas_Object *ck;
ck = elm_check_add(obj);
evas_object_propagate_events_set(ck, EINA_FALSE);
evas_object_show(ck);
return ck;
}
return NULL;
}
/* state fetching callback */
static Eina_Bool
_grid_state_get(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
const char *part EINA_UNUSED)
{
return EINA_FALSE;
}
/* deletion callback */
static void
_grid_del(void *data,
Evas_Object *obj EINA_UNUSED)
{
Example_Item *it = data;
eina_stringshare_del(it->path);
free(it);
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED,
char **argv EINA_UNUSED)
{
Evas_Object *win, *grid, *bx, *hbx_1, *hbx_2, *hbx_3, *bt, *ck, *sl, *sp;
Eina_Bool bounce;
double h, v;
int i;
srand(time(NULL));
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_app_info_set(elm_main, "elementary", "images");
win = elm_win_util_standard_add("gengrid", "Generic Grid Example");
elm_win_autodel_set(win, EINA_TRUE);
bx = elm_box_add(win);
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, bx);
evas_object_show(bx);
grid = elm_gengrid_add(win);
elm_gengrid_item_size_set(grid, 150, 150);
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);
elm_box_pack_end(bx, grid);
elm_gengrid_horizontal_set(grid, EINA_TRUE);
evas_object_show(grid);
if (!gic)
{
gic = elm_gengrid_item_class_new();
gic->item_style = "default";
gic->func.text_get = _grid_label_get;
gic->func.content_get = _grid_content_get;
gic->func.state_get = _grid_state_get;
gic->func.del = _grid_del;
} // we only create the first time its needed. we dont unref/free
for(i=0; i<1000; i++)
{
Example_Item *it = _item_new();
elm_gengrid_item_append(grid, gic, it, NULL, NULL);
}
elm_gengrid_item_show(elm_gengrid_nth_item_get(grid, 500), ELM_GENGRID_ITEM_SCROLLTO_IN);
evas_object_resize(win, 600, 600);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()