Index example
#include <Elementary.h>
#include <assert.h>
static const char *dict[] = \
{
#include "dict.txt"
};
static void
_index_item_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
printf("Deleting index node (%s). Comparing index "
"item data reported via callback with the one returned by "
"index's API on items: %s.\n",
elm_index_item_letter_get(event_info),
data == elm_object_item_data_get(event_info) ? "OK" :
"FAIL, something went wrong");
}
/* delete an index item */
static void
_item_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Elm_Object_Item *it = elm_index_selected_item_get(data, 0);
if (!it) return;
printf("Deleting last selected index item, which had letter"
" %s (pointing to %p)\n", elm_index_item_letter_get(it),
elm_object_item_data_get(it));
elm_object_item_del(it);
elm_index_level_go(data, 0);
}
static void
_item_del_all(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
elm_index_item_clear(data);
elm_index_level_go(data, 0);
}
static void
_active_set(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Eina_Bool disabled = elm_index_autohide_disabled_get(data);
elm_index_autohide_disabled_set(data, !disabled);
printf("Toggling index programmatically to %s.\n",
!disabled ? "On" : "Off");
}
/* "delay,changed" hook */
static void
_index_changed(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
elm_list_item_bring_in(elm_object_item_data_get(event_info));
}
static void
_index_selected(void *data EINA_UNUSED, Evas_Object *obj, void *event_info)
{
Elm_Object_Item *lit = event_info;
printf("New index item selected. Comparing item reported"
" via callback with the selection returned by the API: "
"%s.\n", lit == elm_index_selected_item_get(obj, 0) ? "OK" :
"FAIL, something went wrong");
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *hbox, *vbox, *bt, *sep, *list, *id;
Elm_Object_Item *lit;
unsigned int i;
char curr = 0;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("index", "Index Example");
elm_win_autodel_set(win, EINA_TRUE);
vbox = elm_box_add(win);
evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, vbox);
evas_object_show(vbox);
list = elm_list_add(win);
evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(list);
elm_box_pack_end(vbox, list);
id = elm_index_add(win);
evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, id);
evas_object_show(id);
for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++)
{
lit = elm_list_item_append(list, dict[i], NULL, NULL, NULL, NULL);
if (curr != dict[i][0])
{
Elm_Object_Item *index_it;
char buf[32];
curr = dict[i][0];
/* indexing by first letters */
snprintf(buf, sizeof(buf), "%c", curr);
index_it = elm_index_item_append(id, buf, NULL, lit);
/* this is here just to demostrate the API call */
(void)elm_index_item_find(id, lit);
assert(elm_index_item_find(id, lit) == index_it);
elm_object_item_del_cb_set(index_it, _index_item_del);
}
}
evas_object_smart_callback_add(id, "delay,changed", _index_changed,
NULL);
evas_object_smart_callback_add(id, "selected", _index_selected, NULL);
elm_index_level_go(id, 0);
/* attribute setting knobs */
sep = elm_separator_add(win);
elm_separator_horizontal_set(sep, EINA_TRUE);
elm_box_pack_end(vbox, sep);
evas_object_show(sep);
hbox = elm_box_add(win);
elm_box_horizontal_set(hbox, EINA_TRUE);
evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(vbox, hbox);
evas_object_show(hbox);
bt = elm_button_add(win);
elm_object_text_set(bt, "bring in index");
evas_object_smart_callback_add(bt, "clicked", _active_set, id);
elm_box_pack_end(hbox, bt);
evas_object_show(bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "delete last selected item");
evas_object_smart_callback_add(bt, "clicked", _item_del, id);
elm_box_pack_end(hbox, bt);
evas_object_show(bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "delete all items");
evas_object_smart_callback_add(bt, "clicked", _item_del_all, id);
elm_box_pack_end(hbox, bt);
evas_object_show(bt);
evas_object_resize(win, 320, 600);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
evas_object_size_hint_fill_set
#define evas_object_size_hint_fill_set
Convenience macro to make it easier to understand that align is also used for fill properties (as fil...
Definition Evas_Common.h:299
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition Evas_Common.h:297
EVAS_HINT_FILL
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition Evas_Common.h:298
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:527
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339
elm_box_horizontal_set
void elm_box_horizontal_set(Elm_Box *obj, Eina_Bool horizontal)
Set the horizontal orientation.
Definition elm_box_eo.legacy.c:27
elm_box_add
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition elm_box.c:363
elm_box_pack_end
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition elm_box_eo.legacy.c:57
elm_button_add
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition efl_ui_button.c:459
elm_object_item_del_cb_set
void elm_object_item_del_cb_set(Elm_Widget_Item *obj, Evas_Smart_Cb del_cb)
Set the function to be called when an item from the widget is freed.
Definition elm_widget_item_eo.legacy.c:231
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition elm_general.h:556
elm_object_item_data_get
void * elm_object_item_data_get(const Elm_Object_Item *it)
Get the data associated with an object item.
Definition efl_ui_widget.c:3796
elm_policy_set
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition elm_main.c:1380
Elm_Object_Item
Eo Elm_Object_Item
An Elementary Object item handle.
Definition elm_object_item.h:6
elm_object_item_del
void elm_object_item_del(Eo *obj)
Delete the given item.
Definition elm_main.c:2017
elm_run
void elm_run(void)
Run Elementary's main loop.
Definition elm_main.c:1357
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition elm_general.h:248
ELM_POLICY_QUIT
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition elm_general.h:227
elm_index_item_find
Elm_Widget_Item * elm_index_item_find(Elm_Index *obj, const void *data)
Find a given index widget's item, using item data.
Definition elm_index_eo.legacy.c:99
elm_index_level_go
void elm_index_level_go(Elm_Index *obj, int level)
Flush the changes made to the index items so they work correctly.
Definition elm_index_eo.legacy.c:75
elm_index_autohide_disabled_get
Eina_Bool elm_index_autohide_disabled_get(const Elm_Index *obj)
Enable or disable auto hiding feature for a given index widget.
Definition elm_index_eo.legacy.c:9
elm_index_item_append
Elm_Widget_Item * elm_index_item_append(Elm_Index *obj, const char *letter, Evas_Smart_Cb func, const void *data)
Append a new item on a given index widget.
Definition elm_index_eo.legacy.c:111
elm_index_autohide_disabled_set
void elm_index_autohide_disabled_set(Elm_Index *obj, Eina_Bool disabled)
Enable or disable auto hiding feature for a given index widget.
Definition elm_index_eo.legacy.c:3
elm_index_selected_item_get
Elm_Widget_Item * elm_index_selected_item_get(const Elm_Index *obj, int level)
Returns the last selected item, for a given index widget.
Definition elm_index_eo.legacy.c:117
elm_index_item_clear
void elm_index_item_clear(Elm_Index *obj)
Removes all items from a given index widget.
Definition elm_index_eo.legacy.c:87
elm_index_add
Evas_Object * elm_index_add(Evas_Object *parent)
Add a new index widget to the given parent Elementary (container) object.
Definition elm_index.c:1186
elm_index_item_letter_get
const char * elm_index_item_letter_get(const Elm_Index_Item *obj)
Get the letter (string) set on a given index widget item.
Definition elm_index_item_eo.legacy.c:15
elm_list_item_append
Elm_Widget_Item * elm_list_item_append(Elm_List *obj, const char *label, Efl_Canvas_Object *icon, Efl_Canvas_Object *end, Evas_Smart_Cb func, const void *data)
Append a new item to the list object.
Definition elm_list_eo.legacy.c:129
elm_list_add
Evas_Object * elm_list_add(Evas_Object *parent)
Add a new list widget to the given parent Elementary (container) object.
Definition elm_list.c:2513
elm_separator_add
Evas_Object * elm_separator_add(Evas_Object *parent)
Add a separator object to parent.
Definition elm_separator.c:49
elm_win_util_standard_add
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition efl_ui_win.c:9587
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition efl_ui_win.c:9002
elm_win_autodel_set
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition efl_ui_win.c:6199
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition evas_object_main.c:1814
evas_object_size_hint_weight_set
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition evas_object_main.c:2638
evas_object_size_hint_align_set
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition evas_object_main.c:2650
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition evas_object_main.c:1236
evas_object_smart_callback_add
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition evas_object_smart.c:1040