From 4331c1e08eb43162635aa99125319d569dae9f45 Mon Sep 17 00:00:00 2001 From: Taehyub Kim Date: Wed, 10 Jun 2020 15:39:03 +0900 Subject: [PATCH] efl_ui_textpath: add the efl_ui_textpath_text_user_style_set API for applying the user text style Summary: For the text style customizing, added the new API to apply user text style. The following example is the user style sample. DEFAULT='font_size=16 color=#F00 underline=on underline_color=#00ffff'"; {F3899541} Test Plan: 1. run elementary_text (textpath) 2. toggle user style check box 3. see the result Reviewers: Hermet, kimcinoo, jsuya, bu5hm4n Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11953 --- src/bin/elementary/test_ui_textpath.c | 20 +++++++ src/lib/elementary/efl_ui_textpath.c | 73 ++++++++++++++++++++++-- src/lib/elementary/elm_textpath_legacy.h | 12 ++++ 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/bin/elementary/test_ui_textpath.c b/src/bin/elementary/test_ui_textpath.c index 40317a9627..41783386b1 100644 --- a/src/bin/elementary/test_ui_textpath.c +++ b/src/bin/elementary/test_ui_textpath.c @@ -56,6 +56,20 @@ _short_text_changed_cb(void *data, const Efl_Event *event) efl_text_set(txtpath, TEST_UI_TEXTPATH_LONG_TEXT); } +static char *user_style = "DEFAULT='font_size=16 color=#F00 underline=on underline_color=#00ffff'"; + +static void +_user_style_changed_cb(void *data, const Efl_Event *event) +{ + Evas_Object *txtpath = data; + Eina_Bool val = elm_check_selected_get(event->object); + + if (val) + elm_textpath_text_user_style_set(txtpath, user_style); + else + elm_textpath_text_user_style_set(txtpath, NULL); +} + static void _change_shape_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -138,6 +152,12 @@ test_ui_textpath(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve elm_box_pack_end(hbox, chk); efl_gfx_entity_visible_set(chk, EINA_TRUE); + chk = efl_add(EFL_UI_CHECK_CLASS, win); + efl_text_set(chk, "User style"); + efl_event_callback_add(chk, EFL_UI_EVENT_SELECTED_CHANGED, _user_style_changed_cb, txtpath); + elm_box_pack_end(hbox, chk); + efl_gfx_entity_visible_set(chk, EINA_TRUE); + hbox = elm_box_add(win); elm_box_horizontal_set(hbox, EINA_TRUE); efl_gfx_hint_weight_set(hbox, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND); diff --git a/src/lib/elementary/efl_ui_textpath.c b/src/lib/elementary/efl_ui_textpath.c index 3cb1d96809..539f996108 100644 --- a/src/lib/elementary/efl_ui_textpath.c +++ b/src/lib/elementary/efl_ui_textpath.c @@ -15,6 +15,8 @@ #define MY_CLASS EFL_UI_TEXTPATH_CLASS #define MY_CLASS_NAME "Efl.Ui.Textpath" +#define LEGACY_TEXT_PART_NAME "elm.text" +#define EFL_UI_TEXT_PART_NAME "efl.text" #define SLICE_DEFAULT_NO 99 typedef struct _Efl_Ui_Textpath_Point Efl_Ui_Textpath_Point; @@ -54,6 +56,7 @@ struct _Efl_Ui_Textpath_Data { Evas_Object *text_obj; char *text; + Eina_Strbuf *user_style; Efl_Gfx_Path *path; struct { double x, y; @@ -529,13 +532,40 @@ _sizing_eval(Efl_Ui_Textpath_Data *pd) } static void -_textpath_ellipsis_set(Efl_Ui_Textpath_Data *pd, Eina_Bool enabled) +_textpath_ellipsis_set(Eo *obj, Efl_Ui_Textpath_Data *pd, Eina_Bool enabled) { - edje_object_part_text_style_user_pop(pd->text_obj, "efl.text"); + char *text_part; + if (elm_widget_is_legacy(obj)) + text_part = LEGACY_TEXT_PART_NAME; + else + text_part = EFL_UI_TEXT_PART_NAME; + + edje_object_part_text_style_user_pop(pd->text_obj, text_part); if (enabled) - edje_object_part_text_style_user_push(pd->text_obj, "efl.text", - "DEFAULT='ellipsis=1.0'"); + { + if (pd->user_style) + { + eina_strbuf_replace_first(pd->user_style, "DEFAULT='", "DEFAULT='ellipsis=1.0 "); + edje_object_part_text_style_user_push(pd->text_obj, text_part, + eina_strbuf_string_get(pd->user_style)); + } + else + { + edje_object_part_text_style_user_push(pd->text_obj, text_part, + "DEFAULT='ellipsis=1.0 '"); + return; + } + } + else + { + if (pd->user_style) + { + eina_strbuf_replace_first(pd->user_style, "DEFAULT='ellipsis=1.0 ", "DEFAULT='"); + edje_object_part_text_style_user_push(pd->text_obj, text_part, + eina_strbuf_string_get(pd->user_style)); + } + } } static void @@ -563,7 +593,7 @@ _ellipsis_set(Efl_Ui_Textpath_Data *pd, Eo *obj) } } efl_gfx_entity_size_set(pd->text_obj, EINA_SIZE2D(w, h)); - _textpath_ellipsis_set(pd, is_ellipsis); + _textpath_ellipsis_set(obj, pd, is_ellipsis); } static void @@ -713,6 +743,7 @@ _efl_ui_textpath_efl_object_destructor(Eo *obj, Efl_Ui_Textpath_Data *pd) if (pd->text) free(pd->text); if (pd->text_obj) evas_object_del(pd->text_obj); + if (pd->user_style) eina_strbuf_free(pd->user_style); EINA_INLIST_FREE(pd->segments, seg) { pd->segments = eina_inlist_remove(pd->segments, EINA_INLIST_GET(seg)); @@ -1013,5 +1044,37 @@ elm_textpath_circle_set(Eo *obj, double x, double y, double radius, double start efl_gfx_hint_size_restricted_min_set(obj, EINA_SIZE2D(x * 2, y * 2)); } +EAPI void +elm_textpath_text_user_style_set(Eo *obj, const char *style) +{ + EFL_UI_TEXTPATH_DATA_GET(obj, pd); + if (!pd) return; + + char *text_part; + if (elm_widget_is_legacy(obj)) + text_part = LEGACY_TEXT_PART_NAME; + else + text_part = EFL_UI_TEXT_PART_NAME; + + if (pd->user_style) + { + edje_object_part_text_style_user_pop(pd->text_obj, text_part); + eina_strbuf_free(pd->user_style); + pd->user_style = NULL; + } + + if (style) + { + pd->user_style = eina_strbuf_new(); + eina_strbuf_append(pd->user_style, style); + + edje_object_part_text_style_user_pop(pd->text_obj, text_part); + edje_object_part_text_style_user_push(pd->text_obj, text_part, eina_strbuf_string_get(pd->user_style)); + } + + _ellipsis_set(pd, obj); + _sizing_eval(pd); +} + #include "efl_ui_textpath_legacy_eo.c" diff --git a/src/lib/elementary/elm_textpath_legacy.h b/src/lib/elementary/elm_textpath_legacy.h index 1795bdfa60..259c63b9bd 100644 --- a/src/lib/elementary/elm_textpath_legacy.h +++ b/src/lib/elementary/elm_textpath_legacy.h @@ -12,4 +12,16 @@ typedef Eo Elm_Textpath; */ EAPI Evas_Object *elm_textpath_add(Evas_Object *parent); +/** + * @brief Set the user text style + * + * @param[in] obj The textpath object + * @param[in] style The user text style. If the sytle is $null, the default style will be applied + * + * @ingroup Elm_Textpath + * + * @since 1.25 + */ +EAPI void elm_textpath_text_user_style_set(Evas_Object *obj, const char *style); + #include "efl_ui_textpath_eo.legacy.h"