summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces
diff options
context:
space:
mode:
Diffstat (limited to '')
-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 }