summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorDaniel Hirt <hirt.danny@gmail.com>2018-11-12 15:14:11 +0200
committerDaniel Hirt <hirt.danny@gmail.com>2018-11-26 13:17:07 +0200
commitbaecca47b4fb231389664ec0cda09a56f3b91704 (patch)
tree6d85986b974a9706476541fe52c2bbc43dda841d /src/lib/elementary
parent64c0315af913f6ac11236c20f8d8a5a859cf1244 (diff)
Ui text: read init text properties from theme
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/efl_ui_text.c127
1 files changed, 122 insertions, 5 deletions
diff --git a/src/lib/elementary/efl_ui_text.c b/src/lib/elementary/efl_ui_text.c
index 5d65791a3a..6cded21d5d 100644
--- a/src/lib/elementary/efl_ui_text.c
+++ b/src/lib/elementary/efl_ui_text.c
@@ -1985,6 +1985,124 @@ _update_guide_text(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd)
1985 1985
1986} 1986}
1987 1987
1988/**
1989 * @internal
1990 * Returns the numeric value of HEX chars for example for ch = 'A'
1991 * the function will return 10.
1992 *
1993 * @param ch The HEX char.
1994 * @return numeric value of HEX.
1995 */
1996static int
1997_hex_string_get(char ch, Eina_Bool *ok)
1998{
1999 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
2000 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
2001 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
2002 *ok = EINA_FALSE;
2003 return 0;
2004}
2005
2006
2007static inline Eina_Bool
2008_format_color_parse(const char *str, int slen,
2009 unsigned char *r, unsigned char *g,
2010 unsigned char *b, unsigned char *a)
2011{
2012 Eina_Bool v = EINA_TRUE;
2013
2014 *r = *g = *b = *a = 0;
2015
2016 if (slen == 7) /* #RRGGBB */
2017 {
2018 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
2019 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
2020 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
2021 *a = 0xff;
2022 }
2023 else if (slen == 9) /* #RRGGBBAA */
2024 {
2025 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
2026 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
2027 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
2028 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
2029 }
2030 else if (slen == 4) /* #RGB */
2031 {
2032 *r = _hex_string_get(str[1], &v);
2033 *r = (*r << 4) | *r;
2034 *g = _hex_string_get(str[2], &v);
2035 *g = (*g << 4) | *g;
2036 *b = _hex_string_get(str[3], &v);
2037 *b = (*b << 4) | *b;
2038 *a = 0xff;
2039 }
2040 else if (slen == 5) /* #RGBA */
2041 {
2042 *r = _hex_string_get(str[1], &v);
2043 *r = (*r << 4) | *r;
2044 *g = _hex_string_get(str[2], &v);
2045 *g = (*g << 4) | *g;
2046 *b = _hex_string_get(str[3], &v);
2047 *b = (*b << 4) | *b;
2048 *a = _hex_string_get(str[4], &v);
2049 *a = (*a << 4) | *a;
2050 }
2051 else v = EINA_FALSE;
2052
2053 *r = (*r * *a) / 255;
2054 *g = (*g * *a) / 255;
2055 *b = (*b * *a) / 255;
2056 return v;
2057}
2058
2059/**
2060 * @internal
2061 * Updates the text properties of the object from the theme.
2062 *
2063 * This update functions skips any property that was already set,
2064 * to allow users to override the theme during the construction of the widget.
2065 */
2066static void
2067_update_text_theme(Eo *obj, Efl_Ui_Text_Data *sd)
2068{
2069 const char *font_name;
2070 const char *font_size;
2071 const char *colorcode;
2072
2073 int font_size_n;
2074 unsigned char r, g, b, a;
2075
2076 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
2077
2078 // Main Text
2079 // font_set
2080 font_name = edje_object_data_get(wd->resize_obj, "font.name");
2081 font_size = edje_object_data_get(wd->resize_obj, "font.size");
2082 font_size_n = font_size ? atoi(font_size) : 0;
2083 efl_text_font_set(sd->text_obj, font_name, font_size_n);
2084
2085 // color
2086 colorcode = edje_object_data_get(wd->resize_obj, "style.color");
2087 if (colorcode && _format_color_parse(colorcode, strlen(colorcode), &r, &g, &b, &a))
2088 {
2089 efl_text_normal_color_set(sd->text_obj, r, g, b, a);
2090 }
2091
2092 // Guide Text
2093 font_name = edje_object_data_get(wd->resize_obj, "guide.font.name");
2094 font_size = edje_object_data_get(wd->resize_obj, "guide.font.size");
2095 font_size_n = font_size ? atoi(font_size) : 0;
2096 efl_text_font_set(sd->text_guide_obj, font_name, font_size_n);
2097
2098 // color
2099 colorcode = edje_object_data_get(wd->resize_obj, "guide.style.color");
2100 if (_format_color_parse(colorcode, strlen(colorcode), &r, &g, &b, &a))
2101 {
2102 efl_text_normal_color_set(sd->text_guide_obj, r, g, b, a);
2103 }
2104}
2105
1988EOLIAN static Eo * 2106EOLIAN static Eo *
1989_efl_ui_text_efl_object_constructor(Eo *obj, Efl_Ui_Text_Data *sd) 2107_efl_ui_text_efl_object_constructor(Eo *obj, Efl_Ui_Text_Data *sd)
1990{ 2108{
@@ -2042,11 +2160,9 @@ _efl_ui_text_efl_object_finalize(Eo *obj,
2042 efl_event_callback_add(obj, EFL_EVENT_CALLBACK_ADD, _cb_added, NULL); 2160 efl_event_callback_add(obj, EFL_EVENT_CALLBACK_ADD, _cb_added, NULL);
2043 efl_event_callback_add(obj, EFL_EVENT_CALLBACK_DEL, _cb_deleted, NULL); 2161 efl_event_callback_add(obj, EFL_EVENT_CALLBACK_DEL, _cb_deleted, NULL);
2044 2162
2045 // FIXME: use the theme, when a proper theming option is available 2163 //TODO: complete the usage of the text theme
2046 // (possibly, text_classes). 2164 _update_text_theme(obj, sd);
2047 // For now, set this for easier setup 2165 //efl_text_font_set(sd->text_obj, "Sans", 12);
2048 efl_text_font_set(sd->text_obj, "Sans", 12);
2049 efl_text_normal_color_set(sd->text_obj, 255, 255, 255, 255);
2050 sd->single_line = !efl_text_multiline_get(sd->text_obj); 2166 sd->single_line = !efl_text_multiline_get(sd->text_obj);
2051 2167
2052 efl_text_set(sd->text_obj, ""); 2168 efl_text_set(sd->text_obj, "");
@@ -3919,6 +4035,7 @@ _efl_ui_text_async_efl_object_constructor(Eo *obj, void *_pd EINA_UNUSED)
3919 elm_widget_theme_klass_set(obj, "text"); 4035 elm_widget_theme_klass_set(obj, "text");
3920 obj = efl_constructor(efl_super(obj, EFL_UI_TEXT_ASYNC_CLASS)); 4036 obj = efl_constructor(efl_super(obj, EFL_UI_TEXT_ASYNC_CLASS));
3921 4037
4038 _update_text_theme(obj, sd);
3922 return obj; 4039 return obj;
3923} 4040}
3924 4041