2 //gcc -g `pkg-config --cflags --libs elementary` hoversel_example_01.c -o hoversel_example_01
4 #include <Elementary.h>
6 # include "elementary_config.h"
9 static void _print_items(void *data, Evas_Object *obj, void *event_info);
10 static void _rm_items(void *data, Evas_Object *obj, void *event_info);
11 static void _sel(void *data, Evas_Object *obj, void *event_info);
12 static void _free(void *data, Evas_Object *obj, void *event_info);
13 static void _add_item(void *data, Evas_Object *obj, void *event_info);
16 elm_main(int argc, char **argv)
18 Evas_Object *win, *bg, *rect, *hoversel;
19 Elm_Hoversel_Item *it;
21 win = elm_win_add(NULL, "hoversel", ELM_WIN_BASIC);
22 elm_win_title_set(win, "Hoversel");
23 elm_win_autodel_set(win, EINA_TRUE);
24 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
27 elm_win_resize_object_add(win, bg);
30 rect = evas_object_rectangle_add(evas_object_evas_get(win));
31 evas_object_color_set(rect, 255, 0, 0, 255);
32 evas_object_show(rect);
34 hoversel = elm_hoversel_add(win);
35 elm_hoversel_hover_parent_set(hoversel, win);
36 elm_hoversel_horizontal_set(hoversel, EINA_FALSE);
37 elm_object_text_set(hoversel, "Hoversel");
38 elm_hoversel_icon_set(hoversel, rect);
39 elm_hoversel_item_add(hoversel, "Print items", NULL, ELM_ICON_NONE,
41 elm_hoversel_item_add(hoversel, "Option 2", "home", ELM_ICON_STANDARD, NULL,
43 it = elm_hoversel_item_add(hoversel, "Clear all items", "close",
44 ELM_ICON_STANDARD, _rm_items, NULL);
45 evas_object_smart_callback_add(hoversel, "selected", _sel, it);
46 evas_object_smart_callback_add(hoversel, "clicked", _add_item, NULL);
48 evas_object_resize(hoversel, 180, 30);
49 evas_object_move(hoversel, 10, 10);
50 evas_object_show(hoversel);
52 evas_object_resize(win, 200, 300);
53 evas_object_show(win);
62 _print_items(void *data, Evas_Object *obj, void *event_info)
64 const Eina_List *items = elm_hoversel_items_get(obj);
66 Elm_Hoversel_Item *it;
68 EINA_LIST_FOREACH(items, l, it)
69 printf("%s\n", elm_hoversel_item_label_get(it));
73 _rm_items(void *data, Evas_Object *obj, void *event_info)
75 if(!elm_hoversel_expanded_get(obj))
76 elm_hoversel_clear(obj);
80 _sel(void *data, Evas_Object *obj, void *event_info)
82 if(!elm_hoversel_expanded_get(obj) && event_info != data)
83 elm_hoversel_item_del(event_info);
87 _add_item(void *data, Evas_Object *obj, void *event_info)
90 char *str = malloc(sizeof(char) * 10);
91 Elm_Hoversel_Item *it;
93 snprintf(str, 10, "item %d", ++num);
95 it = elm_hoversel_item_add(obj, str, NULL, ELM_ICON_NONE, NULL, str);
96 elm_hoversel_item_del_cb_set(it, _free);
100 _free(void *data, Evas_Object *obj, void *event_info)