2011-07-20 09:28:12 -07:00
|
|
|
/**
|
|
|
|
* Simple Elementary's <b>index widget</b> example, illustrating its
|
|
|
|
* usage and API -- now with sorted insertions.
|
|
|
|
*
|
|
|
|
* See stdout/stderr for output. Compile with:
|
|
|
|
*
|
|
|
|
* @verbatim
|
|
|
|
* gcc -g `pkg-config --cflags --libs elementary` index_example.c -o index_example
|
|
|
|
* @endverbatim
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Elementary.h>
|
2012-03-28 01:42:24 -07:00
|
|
|
#define DATA_DIR "../../data"
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
static const char *items[] = \
|
|
|
|
{
|
|
|
|
"Judith",
|
|
|
|
"Paulina",
|
|
|
|
"Cathy",
|
|
|
|
"Vendella",
|
|
|
|
"Naomi",
|
|
|
|
"Ashley",
|
|
|
|
"Stacey",
|
|
|
|
"Gail"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2012-03-28 01:42:20 -07:00
|
|
|
_index_changed(void *data,
|
|
|
|
Evas_Object *obj,
|
2011-07-20 09:28:12 -07:00
|
|
|
void *event_info)
|
|
|
|
{
|
2012-03-07 04:57:17 -08:00
|
|
|
elm_gengrid_item_bring_in(event_info, ELM_GENGRID_ITEM_SCROLLTO_IN);
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-28 01:42:20 -07:00
|
|
|
_on_done(void *data,
|
|
|
|
Evas_Object *obj,
|
|
|
|
void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
|
|
|
elm_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
_grid_label_get(void *data,
|
2012-03-28 01:42:20 -07:00
|
|
|
Evas_Object *obj,
|
|
|
|
const char *part)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
|
|
|
int idx = (int)data;
|
|
|
|
return strdup(items[idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Evas_Object *
|
2012-03-28 01:42:20 -07:00
|
|
|
_grid_content_get(void *data,
|
2011-07-20 09:28:12 -07:00
|
|
|
Evas_Object *obj,
|
|
|
|
const char *part)
|
|
|
|
{
|
|
|
|
if (!strcmp(part, "elm.swallow.icon"))
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2012-03-28 01:42:24 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/images/%s", DATA_DIR,
|
2011-07-20 09:28:12 -07:00
|
|
|
"sky_01.jpg");
|
|
|
|
|
|
|
|
Evas_Object *icon = elm_bg_add(obj);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ordering alphabetically */
|
|
|
|
static int
|
|
|
|
_index_icmp(const void *data1,
|
|
|
|
const void *data2)
|
|
|
|
{
|
|
|
|
const char *label1, *label2;
|
|
|
|
|
2011-12-29 20:57:28 -08:00
|
|
|
const Elm_Object_Item *index_it1 = data1;
|
|
|
|
const Elm_Object_Item *index_it2 = data2;
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2011-12-29 20:57:28 -08:00
|
|
|
label1 = elm_index_item_letter_get(index_it1);
|
|
|
|
label2 = elm_index_item_letter_get(index_it2);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
return strcasecmp(label1, label2);
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:04:36 -07:00
|
|
|
EAPI_MAIN int
|
2012-03-28 01:42:20 -07:00
|
|
|
elm_main(int argc,
|
|
|
|
char **argv)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2012-03-27 17:52:09 -07:00
|
|
|
Evas_Object *win, *bg, *grid, *idx;
|
2012-01-30 02:29:51 -08:00
|
|
|
Elm_Object_Item *gg_it;
|
2011-07-20 09:28:12 -07:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
Elm_Gengrid_Item_Class gic;
|
|
|
|
|
|
|
|
win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
|
|
|
|
elm_win_title_set(win, "Index Example");
|
|
|
|
evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
|
|
|
|
|
|
|
|
bg = elm_bg_add(win);
|
|
|
|
elm_win_resize_object_add(win, bg);
|
|
|
|
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_show(bg);
|
|
|
|
|
|
|
|
grid = elm_gengrid_add(win);
|
|
|
|
elm_gengrid_item_size_set(grid, 150, 150);
|
|
|
|
|
|
|
|
gic.item_style = "default";
|
2011-12-01 08:53:57 -08:00
|
|
|
gic.func.text_get = _grid_label_get;
|
2011-10-25 15:28:35 -07:00
|
|
|
gic.func.content_get = _grid_content_get;
|
2011-07-20 09:28:12 -07:00
|
|
|
gic.func.state_get = NULL;
|
|
|
|
gic.func.del = NULL;
|
|
|
|
|
|
|
|
evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
elm_win_resize_object_add(win, grid);
|
|
|
|
evas_object_show(grid);
|
|
|
|
|
2012-03-27 17:52:09 -07:00
|
|
|
idx = elm_index_add(win);
|
|
|
|
evas_object_size_hint_weight_set(idx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
elm_win_resize_object_add(win, idx);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2012-03-27 17:52:09 -07:00
|
|
|
evas_object_show(idx);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
for (i = 0; i < (sizeof(items) / sizeof(items[0])); i++)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
2012-01-30 02:29:51 -08:00
|
|
|
gg_it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
/* indexing by first letters */
|
|
|
|
snprintf(buf, sizeof(buf), "%c", items[i][0]);
|
2012-03-27 17:52:09 -07:00
|
|
|
elm_index_item_sorted_insert(idx, buf, NULL, gg_it, _index_icmp, NULL);
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 17:52:09 -07:00
|
|
|
evas_object_smart_callback_add(idx, "delay,changed", _index_changed, NULL);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
evas_object_resize(win, 320, 300);
|
|
|
|
evas_object_show(win);
|
|
|
|
|
2012-03-27 17:52:09 -07:00
|
|
|
elm_index_autohide_disabled_set(idx, EINA_FALSE);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
elm_run();
|
2012-03-27 23:04:36 -07:00
|
|
|
elm_shutdown();
|
|
|
|
|
2011-07-20 09:28:12 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ELM_MAIN()
|