|
这个代码展示了如何创建一个表情符号选择器输入小部件。 首先定义回调方法。 然后,有_insert_emoticon_cb保存一个网格的主要逻辑——创建一个inwin可用的表情符号。 这个测试的emoticon_test方法创建基本的UI。
- //gengrid item class methods
- static char *_emoticon_label_get(void *data, Evas_Object *obj, const char *part) {
- return strdup(data);
- }
- static Evas_Object *_emoticon_content_get(void *data, Evas_Object *obj, const char *part) {
- if (strcmp(part, "elm.swallow.icon"))
- return NULL;
- Evas_Object *o = elm_layout_add(obj);
- if (!elm_layout_theme_set(o, "entry/emoticon", data, "default")) {
- return NULL;
- }
- return o;
- }
- static void _emoticon_del(void *data, Evas_Object *obj) {
- free(data);
- }
- //called when user chooses emoticon
- static void _emoticon_selected_cb(void *data, Evas_Object *obj, void *event) {
- appdata_s *ad = data;
- Elm_Object_Item *gg_it = event;
- char *emoticon = elm_object_item_data_get(gg_it);
- char buf[512];
- snprintf(buf, sizeof(buf), "<item size=64x64 vsize=full href=emoticon/%s></item>", emoticon);
- elm_entry_entry_insert(ad->entry, buf);
- elm_object_focus_set(ad->entry, EINA_TRUE);
- evas_object_del(ad->inwin);
- }
- //create grid with available emoticons
- static Evas_Object *create_emoticon_grid(appdata_s *ad) {
- Elm_Gengrid_Item_Class *gic;
- gic = elm_gengrid_item_class_new();
- gic->item_style = "default";
- gic->func.text_get = _emoticon_label_get;
- gic->func.content_get = _emoticon_content_get;
- gic->func.del = _emoticon_del;
-
- char* theme = elm_theme_list_item_path_get("default", NULL);
- if (!theme)
- return NULL;
-
- Eina_List *emos = edje_file_collection_list(theme);
- free(theme);
- if (!emos)
- return NULL;
- Evas_Object *grid = elm_gengrid_add(ad->win);
- elm_gengrid_item_size_set(grid, 64, 80);
- 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);
- Eina_List *item;
- char* emoticon;
- EINA_LIST_FOREACH(emos, item, emoticon)
- {
- char name[512];
- if (strncmp(emoticon, "elm/entry/emoticon/", 19))
- continue;
- sscanf(emoticon, "elm/entry/emoticon/%[^/]/default", name);
- elm_gengrid_item_append(grid, gic, strdup(name), _emoticon_selected_cb, ad);
- }
- edje_file_collection_list_free(emos);
- elm_gengrid_item_class_free(gic);
- return grid;
- }
- //show inwin with emoticon list
- static void _insert_emoticon_cb(void *data, Evas_Object *obj, void *event) {
- appdata_s *ad = data;
-
- Evas_Object *inwin = elm_win_inwin_add(ad->win);
- evas_object_size_hint_weight_set(inwin, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(inwin, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(inwin);
-
- Evas_Object *box = elm_box_add(ad->win);
- evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_win_inwin_content_set(inwin, box);
- ad->inwin = inwin;
- evas_object_show(box);
-
- Evas_Object *naviframe = elm_naviframe_add(ad->win);
- evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_box_pack_end(box, naviframe);
- evas_object_show(naviframe);
-
- Evas_Object *grid = create_emoticon_grid(ad);
- elm_naviframe_item_simple_push(naviframe, grid);
- elm_naviframe_item_simple_promote(naviframe, grid);
- }
- //main test function(with editable entry and "insert emoticon" button
- static void emoticon_test(appdata_s *ad) {
- Evas_Object *box = elm_box_add(ad->win);
- evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(ad->win, box);
- evas_object_show(box);
- Evas_Object* entry = elm_entry_add(ad->win);
- evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.1);
- elm_entry_entry_insert(entry, "sample text");
- evas_object_show(entry);
- elm_box_pack_end(box, entry);
- ad->entry = entry;
- Evas_Object *button = elm_button_add(ad->win);
- elm_object_text_set(button, "Insert emoticon");
- evas_object_show(button);
- elm_box_pack_end(box, button);
- evas_object_smart_callback_add(button, "clicked", _insert_emoticon_cb, ad);
- }
复制代码
|
|