herdsman pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=d0da405620613c83e94e89a192f7982954cf5e90

commit d0da405620613c83e94e89a192f7982954cf5e90
Author: Daniel Hirt <hirt.da...@gmail.com>
Date:   Thu Jun 15 12:30:55 2017 +0300

    Efl text format: change "halign" and "valign" to use enums
    
    Value-based alignment (e.g. 0.5, 0.3 etc) isn't very practical.
    Horizontal and vertical alignments will be assigned with enums
    "left", "center", "right", "auto", "locale", for horizontal alignment,
    and "top", "center" and "bottom" for vertical alignment.
    
    This changes the previously added "halign" and "valign" properties.
---
 src/lib/efl/interfaces/efl_text_format.eo   | 32 ++++++++++----
 src/lib/efl/interfaces/efl_text_types.eot   |  1 -
 src/lib/evas/canvas/evas_object_textblock.c | 67 ++++++++++++++++++++++++-----
 3 files changed, 81 insertions(+), 19 deletions(-)

diff --git a/src/lib/efl/interfaces/efl_text_format.eo 
b/src/lib/efl/interfaces/efl_text_format.eo
index d904ec246a..52c8e27911 100644
--- a/src/lib/efl/interfaces/efl_text_format.eo
+++ b/src/lib/efl/interfaces/efl_text_format.eo
@@ -7,6 +7,24 @@ enum Efl.Text.Format.Wrap {
    hyphenation [[Wrap mode hyphenation]]
 }
 
+enum Efl.Text.Format.Horizontal_Alignment_Type {
+   [[Horizontal alignment of the text]]
+   legacy: efl_text_horizontal_alignment;
+   auto,    [[Respects LTR/RTL (bidirectional) settings]]
+   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]]
+}
+
+enum Efl.Text.Format.Vertical_Alignment_Type {
+   [[Horizontal alignment of the text]]
+   legacy: efl_text_vertical_alignment;
+   top,    [[Text is placed at the top]]
+   center, [[Text is placed at the center]]
+   bottom  [[Text is placed at the bottom]]
+}
+
 interface Efl.Text.Format {
    [[The look and layout of the text
 
@@ -40,18 +58,16 @@ interface Efl.Text.Format {
       }
 
       @property halign {
-         [[Horizontal alignment of text (number from 0.0 to 1.0)]]
-         values
-         {
-            value: double;
+         [[Horizontal alignment of text]]
+         values {
+            value: Efl.Text.Format.Horizontal_Alignment_Type;
          }
       }
 
       @property valign {
-         [[Vertical alignment of text (number from -1.0 to 1.0)]]
-         values
-         {
-            value: double;
+         [[Vertical alignment of text]]
+         values {
+            value: Efl.Text.Format.Vertical_Alignment_Type;
          }
       }
 
diff --git a/src/lib/efl/interfaces/efl_text_types.eot 
b/src/lib/efl/interfaces/efl_text_types.eot
index 3fe14a2021..bb7362d270 100644
--- a/src/lib/efl/interfaces/efl_text_types.eot
+++ b/src/lib/efl/interfaces/efl_text_types.eot
@@ -31,4 +31,3 @@ enum Efl.Text.Cursor.Cursor_Type
    before, [[Cursor type before]]
    under [[Cursor type under]]
 }
-
diff --git a/src/lib/evas/canvas/evas_object_textblock.c 
b/src/lib/evas/canvas/evas_object_textblock.c
index 2d8f7887f3..61b76a4b4e 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -15379,35 +15379,82 @@ _efl_canvas_text_efl_text_format_multiline_get(Eo 
*obj EINA_UNUSED, Efl_Canvas_T
 }
 
 static void
-_efl_canvas_text_efl_text_format_halign_set(Eo *obj EINA_UNUSED, 
Efl_Canvas_Text_Data *o EINA_UNUSED, double value EINA_UNUSED)
+_efl_canvas_text_efl_text_format_halign_set(Eo *obj, Efl_Canvas_Text_Data *o, 
Efl_Text_Format_Horizontal_Alignment_Type type)
 {
-   if (value < 0.0)
+   if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_AUTO)
      {
-        _FMT_SET(halign_auto, EINA_TRUE);
+        _FMT_SET(halign_auto, EVAS_TEXTBLOCK_ALIGN_AUTO_NORMAL);
+     }
+   else if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_LOCALE)
+     {
+        _FMT_SET(halign_auto, EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE);
      }
    else
      {
+        double value = 0.0; // EFL_TEXT_HORIZONTAL_ALIGNMENT_LEFT
         _FMT(halign_auto) = EINA_FALSE;
+
+        if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_CENTER)
+          {
+             value = 0.5;
+          }
+        else if (type == EFL_TEXT_HORIZONTAL_ALIGNMENT_RIGHT)
+          {
+             value = 1.0;
+          }
         _FMT_SET(halign, value);
      }
 }
 
-static double
-_efl_canvas_text_efl_text_format_halign_get(Eo *obj EINA_UNUSED, 
Efl_Canvas_Text_Data *o EINA_UNUSED)
+static Efl_Text_Format_Horizontal_Alignment_Type
+_efl_canvas_text_efl_text_format_halign_get(Eo *obj EINA_UNUSED, 
Efl_Canvas_Text_Data *o)
 {
-   return (_FMT(halign_auto) ? -1.0 : _FMT(halign));
+   Efl_Text_Format_Horizontal_Alignment_Type ret =
+      EFL_TEXT_HORIZONTAL_ALIGNMENT_LEFT;
+
+   if (_FMT(halign_auto) == EVAS_TEXTBLOCK_ALIGN_AUTO_NORMAL)
+     {
+        ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_AUTO;
+     }
+   else if (_FMT(halign_auto) == EVAS_TEXTBLOCK_ALIGN_AUTO_LOCALE)
+     {
+        ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_LOCALE;
+     }
+   else if (EINA_DBL_EQ(_FMT(halign), 0.5))
+     {
+        ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_CENTER;
+     }
+   else if (EINA_DBL_EQ(_FMT(halign), 1.0))
+     {
+        ret = EFL_TEXT_HORIZONTAL_ALIGNMENT_RIGHT;
+     }
+   return ret;
 }
 
 static void
-_efl_canvas_text_efl_text_format_valign_set(Eo *obj EINA_UNUSED, 
Efl_Canvas_Text_Data *o EINA_UNUSED, double value EINA_UNUSED)
+_efl_canvas_text_efl_text_format_valign_set(Eo *obj, Efl_Canvas_Text_Data *o,
+      Efl_Text_Format_Vertical_Alignment_Type type)
 {
-   _FMT_SET(valign, value);
+   double value = 0.0; // EFL_TEXT_VERTICAL_ALIGNMENT_TOP
+   if (type == EFL_TEXT_VERTICAL_ALIGNMENT_CENTER)
+     {
+        value = 0.5;
+     }
+   else if (type == EFL_TEXT_VERTICAL_ALIGNMENT_BOTTOM)
+     {
+        value = 1.0;
+     }
+   if (!EINA_DBL_EQ(o->valign, value))
+     {
+        o->valign = value;
+        _canvas_text_format_changed(obj, o);
+     }
 }
 
-static double
+static Efl_Text_Format_Vertical_Alignment_Type
 _efl_canvas_text_efl_text_format_valign_get(Eo *obj EINA_UNUSED, 
Efl_Canvas_Text_Data *o EINA_UNUSED)
 {
-   return _FMT(valign);
+   return o->valign;
 }
 
 static void

-- 


Reply via email to