From 9906cd211f805d971733f0815617256429f0304e Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Thu, 26 Oct 2017 11:40:44 +0900 Subject: [PATCH] evas textblocke: add align=end for putting a text at the opposite side of LTR/RTL Summary: There is a requirement for putting text at right side for LTR and at left side for RTL. It satisfies that reqirement easily. It also add "start" keywork for "align" tag. "start" will be same with "auto". Intuitionally, developer will try "align=start" if they once saw "align=end" in elsewhere. On the other hand, it only add "END" as new enumeration value for efl interface. @feature Test Plan: N/A Reviewers: herdsman, cedric, jpeg, raster Reviewed By: raster Subscribers: woohyun Differential Revision: https://phab.enlightenment.org/D5342 --- src/lib/efl/interfaces/efl_text_format.eo | 3 +- src/lib/evas/canvas/evas_object_textblock.c | 36 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/lib/efl/interfaces/efl_text_format.eo b/src/lib/efl/interfaces/efl_text_format.eo index 0ec06a91d4..5e14893f06 100644 --- a/src/lib/efl/interfaces/efl_text_format.eo +++ b/src/lib/efl/interfaces/efl_text_format.eo @@ -14,7 +14,8 @@ enum Efl.Text.Format.Horizontal_Alignment_Type { locale, [[Respects locale's langauge settings]] left, [[Text is placed at the left end of the line]] right, [[Text is placed at the right end of the line]] - center [[Text is places at the center of the line]] + center, [[Text is places at the center of the line]] + end [[Text is places at opposite side of LTR/RTL (bidirectional) settings]] } enum Efl.Text.Format.Vertical_Alignment_Type { diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 44006d2860..ea0a4ffb69 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -425,7 +425,8 @@ typedef enum _Evas_Textblock_Align_Auto { EVAS_TEXTBLOCK_ALIGN_AUTO_NONE, EVAS_TEXTBLOCK_ALIGN_AUTO_NORMAL, - EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE + EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE, + EVAS_TEXTBLOCK_ALIGN_AUTO_END } Evas_Textblock_Align_Auto; struct _Evas_Object_Textblock_Item @@ -1957,6 +1958,8 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * @li "middle" - Alias for "center" * @li "left" - Puts the text at the left of the line * @li "right" - Puts the text at the right of the line + * @li "start" - Respects LTR/RTL settings. It is same with "auto" + * @li "end" - Puts the text at the opposite side of LTR/RTL settings * @li - A number between 0.0 and 1.0 where 0.0 represents * "left" and 1.0 represents "right" * @li % - A percentage between 0% and 100% where 0% @@ -1965,11 +1968,16 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * align= * @endcode */ - if (len == 4 && !strcmp(param, "auto")) + if ((len == 4 && !strcmp(param, "auto")) || + (len == 5 && !strcmp(param, "start"))) { fmt->halign_auto = EVAS_TEXTBLOCK_ALIGN_AUTO_NORMAL; } - if (len == 6 && !strcmp(param, "locale")) + else if (len == 3 && !strcmp(param, "end")) + { + fmt->halign_auto = EVAS_TEXTBLOCK_ALIGN_AUTO_END; + } + else if (len == 6 && !strcmp(param, "locale")) { fmt->halign_auto = EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE; } @@ -3537,6 +3545,20 @@ _layout_line_align_get(Ctxt *c) return 0.0; } } + else if ((c->align_auto == EVAS_TEXTBLOCK_ALIGN_AUTO_END) && c->ln) + { + if (c->ln->items && c->ln->items->text_node && + (c->ln->par->direction == EVAS_BIDI_DIRECTION_RTL)) + { + /* Align left*/ + return 0.0; + } + else + { + /* Align right */ + return 1.0; + } + } else if (c->align_auto == EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE) { if (evas_common_language_direction_get() == EVAS_BIDI_DIRECTION_RTL) @@ -15614,6 +15636,10 @@ _efl_canvas_text_efl_text_format_halign_set(Eo *obj, Efl_Canvas_Text_Data *o, Ef { _FMT_SET(halign_auto, EVAS_TEXTBLOCK_ALIGN_AUTO_NORMAL); } + else if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_END) + { + _FMT_SET(halign_auto, EVAS_TEXTBLOCK_ALIGN_AUTO_END); + } else if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_LOCALE) { _FMT_SET(halign_auto, EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE); @@ -15645,6 +15671,10 @@ _efl_canvas_text_efl_text_format_halign_get(Eo *obj EINA_UNUSED, Efl_Canvas_Text { ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_AUTO; } + else if (_FMT(halign_auto) == EVAS_TEXTBLOCK_ALIGN_AUTO_END) + { + ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_END; + } else if (_FMT(halign_auto) == EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE) { ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_LOCALE;