summaryrefslogtreecommitdiff
path: root/src/bin/options_font.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2020-12-01 21:10:06 +0100
committerBoris Faure <billiob@gmail.com>2020-12-01 21:10:06 +0100
commite21c07d11416346943019794cbee4da7e1712333 (patch)
tree55b672ca71bd1a0d548f3400532248b5a776a36e /src/bin/options_font.c
parent070fa1defb683aa664740389725a1f0bb0a19058 (diff)
options_font: the long awaited font search!
Diffstat (limited to 'src/bin/options_font.c')
-rw-r--r--src/bin/options_font.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/bin/options_font.c b/src/bin/options_font.c
index 39ccc4e..05fc932 100644
--- a/src/bin/options_font.c
+++ b/src/bin/options_font.c
@@ -24,6 +24,8 @@ typedef struct _Font_Ctx
24 Evas_Object *op_fbig; 24 Evas_Object *op_fbig;
25 Evas_Object *cx; 25 Evas_Object *cx;
26 Evas_Object *term; 26 Evas_Object *term;
27 Evas_Object *filter;
28 const char *filter_data;
27 Eina_List *fonts; 29 Eina_List *fonts;
28 Eina_Hash *fonthash; 30 Eina_Hash *fonthash;
29 Config *config; 31 Config *config;
@@ -374,6 +376,38 @@ _cb_font_bolditalic(void *data,
374 config_save(config); 376 config_save(config);
375} 377}
376 378
379static Eina_Bool
380_cb_font_filter_get(void *data,
381 Evas_Object *obj EINA_UNUSED,
382 void *filter_key)
383{
384 const Font *f = data;
385 const char *key = filter_key;
386
387 /* test whether there's a filter */
388 if ((!key) || (!key[0]))
389 return EINA_TRUE;
390
391 /* If filter matches, show item */
392 if (strcasestr(f->pretty_name, key))
393 return EINA_TRUE;
394
395 /* Default case should return false (item fails filter hence will be hidden */
396 return EINA_FALSE;
397}
398
399void
400_entry_change_cb(void *data, Evas_Object *obj, void *event EINA_UNUSED)
401{
402 Font_Ctx *ctx = data;
403
404 if (ctx->filter_data)
405 eina_stringshare_del(ctx->filter_data);
406
407 ctx->filter_data = eina_stringshare_add(elm_object_text_get(obj));
408 elm_genlist_filter_set(ctx->op_fontlist, (void *)(ctx->filter_data));
409}
410
377static void 411static void
378_parent_del_cb(void *data, 412_parent_del_cb(void *data,
379 Evas *_e EINA_UNUSED, 413 Evas *_e EINA_UNUSED,
@@ -398,6 +432,8 @@ _parent_del_cb(void *data,
398 evas_object_smart_callback_del_full(ctx->op_fontslider, "delay,changed", 432 evas_object_smart_callback_del_full(ctx->op_fontslider, "delay,changed",
399 _cb_op_fontsize_sel, ctx); 433 _cb_op_fontsize_sel, ctx);
400 434
435 eina_stringshare_del(ctx->filter_data);
436
401 free(ctx); 437 free(ctx);
402} 438}
403 439
@@ -469,10 +505,19 @@ options_font(Evas_Object *opbox, Evas_Object *term)
469 elm_box_pack_end(bx0, bx); 505 elm_box_pack_end(bx0, bx);
470 evas_object_show(bx); 506 evas_object_show(bx);
471 507
508 ctx->filter = o = elm_entry_add(bx);
509 elm_entry_single_line_set(o, EINA_TRUE);
510 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
511 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
512 elm_object_part_text_set(o, "guide", _("Search font"));
513 elm_box_pack_end(bx0, o);
514 evas_object_show(o);
515
472 it_class = elm_genlist_item_class_new(); 516 it_class = elm_genlist_item_class_new();
473 it_class->item_style = "end_icon"; 517 it_class->item_style = "end_icon";
474 it_class->func.text_get = _cb_op_font_text_get; 518 it_class->func.text_get = _cb_op_font_text_get;
475 it_class->func.content_get = _cb_op_font_content_get; 519 it_class->func.content_get = _cb_op_font_content_get;
520 it_class->func.filter_get = _cb_font_filter_get;
476 521
477 it_group = elm_genlist_item_class_new(); 522 it_group = elm_genlist_item_class_new();
478 it_group->item_style = "group_index"; 523 it_group->item_style = "group_index";
@@ -603,4 +648,8 @@ options_font(Evas_Object *opbox, Evas_Object *term)
603 evas_object_geometry_get(term, NULL, NULL, &ctx->tsize_w, &ctx->tsize_h); 648 evas_object_geometry_get(term, NULL, NULL, &ctx->tsize_w, &ctx->tsize_h);
604 evas_object_event_callback_add(term, EVAS_CALLBACK_RESIZE, 649 evas_object_event_callback_add(term, EVAS_CALLBACK_RESIZE,
605 _cb_term_resize, ctx); 650 _cb_term_resize, ctx);
651
652 elm_object_focus_set(ctx->filter, EINA_TRUE);
653 evas_object_smart_callback_add(ctx->filter, "changed,user",
654 _entry_change_cb, ctx);
606} 655}