summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-03-08 19:19:36 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-03-08 19:21:24 +0900
commit437ae4a3d3b0d00a279fb93f4341c9205d785c36 (patch)
tree15d816e08ba9803f4fa21f66283fd7597e64fc1f
parent49e7a8ee6982aa5f16cbde72b7729f1cef838e14 (diff)
elm_test: Add a test case for Emojis
Yay to full color characters. The list of selected emojis is quite random. Some more could be added. Just two remarks: - Aren't they supposed to scale down? - Why is my grinning face always ugly?
-rw-r--r--src/bin/elementary/test.c2
-rw-r--r--src/bin/elementary/test_label.c123
2 files changed, 125 insertions, 0 deletions
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index a850816d18..eaac07b474 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -206,6 +206,7 @@ void test_label(void *data, Evas_Object *obj, void *event_info);
206void test_label_slide(void *data, Evas_Object *obj, void *event_info); 206void test_label_slide(void *data, Evas_Object *obj, void *event_info);
207void test_label_wrap(void *data, Evas_Object *obj, void *event_info); 207void test_label_wrap(void *data, Evas_Object *obj, void *event_info);
208void test_label_ellipsis(void *data, Evas_Object *obj, void *event_info); 208void test_label_ellipsis(void *data, Evas_Object *obj, void *event_info);
209void test_label_emoji(void *data, Evas_Object *obj, void *event_info);
209void test_conformant(void *data, Evas_Object *obj, void *event_info); 210void test_conformant(void *data, Evas_Object *obj, void *event_info);
210void test_conformant2(void *data, Evas_Object *obj, void *event_info); 211void test_conformant2(void *data, Evas_Object *obj, void *event_info);
211void test_conformant_indicator(void *data, Evas_Object *obj, void *event_info); 212void test_conformant_indicator(void *data, Evas_Object *obj, void *event_info);
@@ -954,6 +955,7 @@ add_tests:
954 ADD_TEST(NULL, "Text", "Label Slide", test_label_slide); 955 ADD_TEST(NULL, "Text", "Label Slide", test_label_slide);
955 ADD_TEST(NULL, "Text", "Label Wrap", test_label_wrap); 956 ADD_TEST(NULL, "Text", "Label Wrap", test_label_wrap);
956 ADD_TEST(NULL, "Text", "Label Ellipsis", test_label_ellipsis); 957 ADD_TEST(NULL, "Text", "Label Ellipsis", test_label_ellipsis);
958 ADD_TEST(NULL, "Text", "Label Emoji", test_label_emoji);
957 959
958 //------------------------------// 960 //------------------------------//
959 ADD_TEST(NULL, "Stored Surface Buffer", "Launcher", test_launcher); 961 ADD_TEST(NULL, "Stored Surface Buffer", "Launcher", test_launcher);
diff --git a/src/bin/elementary/test_label.c b/src/bin/elementary/test_label.c
index 8aaf2ef72e..3de41f6fd6 100644
--- a/src/bin/elementary/test_label.c
+++ b/src/bin/elementary/test_label.c
@@ -374,3 +374,126 @@ test_label_ellipsis(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *
374 evas_object_resize(win, 300, 100); 374 evas_object_resize(win, 300, 100);
375 evas_object_show(win); 375 evas_object_show(win);
376} 376}
377
378
379/*** Label Emoji *************************************************************/
380static char *
381_fontlist_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
382{
383 return strdup(data);
384}
385
386static void
387_font_set(Evas_Object *label, const char *font)
388{
389 // Note: u1F420 doesn't work but U0001F420 does.
390 const char *emojis = u8""
391 "<font='%s',Sans font_size=16 align=left>"
392 "Grinning Face: \U0001f600<br/>"
393 "Face with Tears of Joy: \xf0\x9f\x98\x82<br/>"
394 "Panda Face: \xf0\x9f\x90\xbc<br/>"
395 "Ghost: \xf0\x9f\x91\xbb<br/>"
396 "Tropical Fish: \U0001F420<br/>"
397 "Mosque: \U0001f54c<br/>"
398 "Pencil: \u270f<br/>"
399 "Person With Ball: \u26f9<br/>"
400 "Birthday Cake: \U0001F382<br/>"
401 "Dog Face: \U0001F436<br/>"
402 "Music: \U0001F3B5 \U0001F3B6 \U0001F3BC<br/>"
403 "Person Shrugging: \U0001F937<br/>"
404 "</>";
405
406 elm_object_text_set(label, eina_slstr_printf(emojis, font));
407}
408
409static void
410_font_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
411{
412 Elm_Object_Item *item = event_info;
413 Evas_Object *lb = data;
414 const char *font;
415
416 font = elm_object_item_text_get(item);
417 elm_object_text_set(obj, font);
418 elm_combobox_hover_end(obj);
419 _font_set(lb, font);
420}
421
422static void
423_font_item_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
424{
425 free(data);
426}
427
428void
429test_label_emoji(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
430{
431 Evas_Object *win, *bx, *txt, *cmb;
432 Elm_Genlist_Item_Class *itc;
433 Eina_List *list, *l;
434 const char *font;
435 Evas *evas;
436
437 const char *font_patterns[] = { "emoji", "symbola" };
438
439 win = elm_win_util_standard_add("label-emoji", "Label Emoji");
440 elm_win_autodel_set(win, EINA_TRUE);
441
442 bx = elm_box_add(win);
443 elm_box_padding_set(bx, 0, ELM_SCALE_SIZE(10));
444 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
445 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
446 elm_win_resize_object_add(win, bx);
447 evas_object_show(bx);
448
449 txt = elm_entry_add(win);
450 elm_entry_editable_set(txt, EINA_TRUE);
451 elm_entry_scrollable_set(txt, EINA_TRUE);
452 evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
453 evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
454 elm_box_pack_end(bx, txt);
455 evas_object_show(txt);
456
457 cmb = elm_combobox_add(win);
458 elm_entry_editable_set(cmb, EINA_FALSE);
459 evas_object_size_hint_weight_set(cmb, EVAS_HINT_EXPAND, 0.0);
460 evas_object_size_hint_align_set(cmb, EVAS_HINT_FILL, EVAS_HINT_FILL);
461 elm_box_pack_end(bx, cmb);
462
463 itc = elm_genlist_item_class_new();
464 itc->item_style = "default";
465 itc->func.text_get = _fontlist_text_get;
466
467 evas = evas_object_evas_get(win);
468 list = evas_font_available_list(evas);
469 EINA_LIST_FOREACH(list, l, font)
470 {
471 size_t k;
472
473 if (!font) continue;
474 for (k = 0; k < EINA_C_ARRAY_LENGTH(font_patterns); k++)
475 {
476 if (strcasestr(font, font_patterns[k]))
477 {
478 Elm_Object_Item *it;
479
480 it = elm_genlist_item_append(cmb, itc, strdup(font), NULL,
481 ELM_GENLIST_ITEM_NONE,
482 NULL, NULL);
483 elm_object_item_del_cb_set(it, _font_item_del_cb);
484 }
485 }
486 }
487 evas_font_available_list_free(evas, list);
488
489 evas_object_smart_callback_add(cmb, "item,pressed", _font_item_sel_cb, txt);
490
491 elm_genlist_item_class_free(itc);
492
493 elm_object_text_set(cmb, "Sans");
494 _font_set(txt, "Sans");
495 evas_object_show(cmb);
496
497 evas_object_resize(win, 300, 400);
498 evas_object_show(win);
499}