summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2017-10-25 19:25:14 +0900
committerAmitesh Singh <amitesh.sh@samsung.com>2017-10-26 21:11:36 +0900
commit5298cb59d2dc21b5b4507e7e05d86c7b17580536 (patch)
tree799c6039b03955e1c99152474ff9eaf32f53c117 /src/lib/efl/interfaces
parentb358fc4b690453098f26156918e67e4f184d4cb8 (diff)
Efl.Ui.Format: implement generic format_string function
This generic format_string would be used in slider,progressbar and other widgets.This default function handles INT and DOUBLE eina value types for now. Ref T6204
Diffstat (limited to 'src/lib/efl/interfaces')
-rw-r--r--src/lib/efl/interfaces/efl_interfaces_main.c1
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.c63
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.eo4
3 files changed, 65 insertions, 3 deletions
diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c
index eb85ef2773..778108e699 100644
--- a/src/lib/efl/interfaces/efl_interfaces_main.c
+++ b/src/lib/efl/interfaces/efl_interfaces_main.c
@@ -68,7 +68,6 @@
68#include "interfaces/efl_ui_scrollable.eo.c" 68#include "interfaces/efl_ui_scrollable.eo.c"
69#include "interfaces/efl_ui_selectable.eo.c" 69#include "interfaces/efl_ui_selectable.eo.c"
70#include "interfaces/efl_ui_zoom.eo.c" 70#include "interfaces/efl_ui_zoom.eo.c"
71#include "interfaces/efl_ui_format.eo.c"
72 71
73EAPI void 72EAPI void
74__efl_internal_init(void) 73__efl_internal_init(void)
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c
new file mode 100644
index 0000000000..6cb64f3913
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_ui_format.c
@@ -0,0 +1,63 @@
1#include "config.h"
2#include "Efl.h"
3
4typedef struct
5{
6 const char *template;
7} Efl_Ui_Format_Data;
8
9static void
10_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
11{
12 const Eina_Value_Type *type = eina_value_type_get(&value);
13 Efl_Ui_Format_Data *sd = data;
14
15 if (type == EINA_VALUE_TYPE_DOUBLE)
16 {
17 double v;
18 eina_value_get(&value, &v);
19 eina_strbuf_append_printf(str, sd->template, v);
20 }
21 else if (type == EINA_VALUE_TYPE_INT)
22 {
23 int v;
24 eina_value_get(&value, &v);
25 eina_strbuf_append_printf(str, sd->template, v);
26 }
27 //XXX: handle other types e.g. struct tm
28 else
29 {
30 char *v = eina_value_to_string(&value);
31 eina_strbuf_append_printf(str, "%s", v);
32 free(v);
33 }
34}
35
36static void
37_default_format_free_cb(void *data)
38{
39 Efl_Ui_Format_Data *sd = data;
40
41 if (sd->template)
42 {
43 eina_stringshare_del(sd->template);
44 sd->template = NULL;
45 }
46}
47
48EOLIAN static void
49_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Format_Data *sd, const char *template)
50{
51 if (!template) return;
52 eina_stringshare_replace(&sd->template, template);
53 efl_ui_format_cb_set(obj, sd, _default_format_cb, _default_format_free_cb);
54}
55
56EOLIAN static const char *
57_efl_ui_format_format_string_get(Eo *obj EINA_UNUSED, Efl_Ui_Format_Data *sd)
58{
59 return sd->template;
60}
61
62#include "interfaces/efl_ui_format.eo.c"
63
diff --git a/src/lib/efl/interfaces/efl_ui_format.eo b/src/lib/efl/interfaces/efl_ui_format.eo
index 38d51c18bd..2f386dafa7 100644
--- a/src/lib/efl/interfaces/efl_ui_format.eo
+++ b/src/lib/efl/interfaces/efl_ui_format.eo
@@ -8,12 +8,12 @@ function Efl.Ui.Format_Func_Cb {
8 } 8 }
9}; 9};
10 10
11interface Efl.Ui.Format 11mixin Efl.Ui.Format
12{ 12{
13 [[interface class for format_func]] 13 [[interface class for format_func]]
14 methods { 14 methods {
15 @property format_cb { 15 @property format_cb {
16 set { 16 set @pure_virtual {
17 [[Set the format function pointer to format the string. 17 [[Set the format function pointer to format the string.
18 ]] 18 ]]
19 } 19 }