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.
This commit is contained in:
Daniel Hirt 2017-06-15 12:30:55 +03:00
parent 6033323e5c
commit d0da405620
3 changed files with 81 additions and 19 deletions

View File

@ -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;
}
}

View File

@ -31,4 +31,3 @@ enum Efl.Text.Cursor.Cursor_Type
before, [[Cursor type before]]
under [[Cursor type under]]
}

View File

@ -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