summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2015-11-23 14:44:52 +0200
committerDaniel Hirt <daniel.hirt@samsung.com>2015-11-23 14:44:52 +0200
commit9e295e05293b6fcbd4d253e916d476ef905b9d94 (patch)
tree578da92647464615f79d9897e90c007b55e696a0
Elm Entry Hyphen Demo: add initial files
-rw-r--r--Makefile15
-rw-r--r--demo.c163
2 files changed, 178 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3c100d2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
1CC?=gcc
2EDJE_CC?=edje_cc
3CFLAGS?=
4LIBS?=
5LDFLAGS?=
6CFLAGS+=-ggdb3 `pkg-config --cflags elementary edje evas`
7LIBS+=`pkg-config --libs elementary edje evas`
8
9all: demo
10
11demo: demo.c
12 $(CC) demo.c $(CFLAGS) $(LDFLAGS) $(LIBS) -o demo
13
14clean:
15 rm demo
diff --git a/demo.c b/demo.c
new file mode 100644
index 0000000..27eecf8
--- /dev/null
+++ b/demo.c
@@ -0,0 +1,163 @@
1#include <Elementary.h>
2#include <unistd.h>
3
4#define ADD_STYLE(name) \
5 typedef struct \
6 { \
7 const char *desc; \
8 const char *style; \
9 } name##_Style; \
10 size_t _##name##_style_idx = 0;
11
12#define INIT_STYLE(name) \
13 static const name##_Style _##name##_options[] =
14
15#define GET_STYLE_STYLE(name) _##name##_options[_##name##_style_idx].style
16#define GET_STYLE_DESC(name) _##name##_options[_##name##_style_idx].desc
17
18#define CYCLE_STYLE(name) \
19 _##name##_style_idx++; \
20 if (_##name##_style_idx >= (sizeof(_##name##_options) / sizeof(_##name##_options[0]))) \
21 _##name##_style_idx = 0
22
23ADD_STYLE(Wrap);
24INIT_STYLE(Wrap)
25{
26 {"Word Wrapping", "wrap=word"},
27 {"Char Wrapping", "wrap=char"},
28 {"Hyphenation Wrapping", "wrap=hyphenation"},
29};
30
31ADD_STYLE(Lang);
32INIT_STYLE(Lang)
33{
34 {"English (en_US)", "lang=en_US"},
35 {"English (en_GB)", "lang=en_GB"},
36 {"Dutch (nl_NL)", "lang=nl_NL"},
37};
38
39static char _cur_style[128];
40
41static void
42_style_reapply(Evas_Object *entry)
43{
44 size_t len = strlen(GET_STYLE_STYLE(Wrap)) + strlen(GET_STYLE_STYLE(Lang));
45 static const int prefix_len = sizeof("DEFAULT=' '");
46
47 sprintf(_cur_style, "DEFAULT='%s %s'", GET_STYLE_STYLE(Wrap), GET_STYLE_STYLE(Lang));
48 _cur_style[len + prefix_len] = '\0';
49
50 printf("Setting style to: %s\n", _cur_style);
51 elm_entry_text_style_user_push(entry, _cur_style);
52}
53
54static void
55_on_wrap_bt_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
56{
57 Evas_Object *entry = data;
58
59 CYCLE_STYLE(Wrap);
60 _style_reapply(entry);
61 elm_object_text_set(obj, GET_STYLE_DESC(Wrap));
62}
63
64static void
65_on_lang_bt_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
66{
67 Evas_Object *entry = data;
68
69 CYCLE_STYLE(Lang);
70 _style_reapply(entry);
71 elm_object_text_set(obj, GET_STYLE_DESC(Lang));
72}
73
74static void
75_main_win_del_cb(void *data, Evas_Object *obj, void *event)
76{
77 elm_exit();
78}
79
80static void
81_init_demo(void)
82{
83 Evas_Object *win, *bg;
84 Evas_Object *box, *box2, *bt, *bt2;
85 Evas_Object *entry;
86 Evas_Coord w = 600, h = 600;
87
88 const char *buf =
89 "<font_size=14>Lorem ipsum dolor sit amet, cons&shy;ectetur adipisicing elit,"
90 " sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
91 " Ut enim ad minim veniam, quis nostrud exer&shy;citation ullamco"
92 " laboris nisi ut aliquip ex ea com&shy;modo consequat. Duis aute"
93 " irure dolor in repre&shy;henderit in voluptate velit esse cillum"
94 " dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat"
95 " non proident, sunt in culpa qui oficia deserunt mollit anim"
96 " id est lab&shy;orum.";
97
98 /* Window */
99 win = elm_win_util_standard_add("demo-win", "Hyphenation Demo");
100 elm_win_autodel_set(win, EINA_TRUE);
101 evas_object_smart_callback_add(win, "delete,request", _main_win_del_cb,
102 NULL);
103
104 evas_object_resize(win, w, h);
105 evas_object_show(win);
106
107 /* Background */
108 bg = elm_bg_add(win);
109 elm_win_resize_object_add(win, bg);
110 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111 evas_object_show(bg);
112
113 /* Layout */
114 box = elm_box_add(win);
115 elm_win_resize_object_add(win, box);
116 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
118 evas_object_show(box);
119
120 entry = elm_entry_add(box);
121 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.95);
122 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
123 elm_box_pack_end(box, entry);
124 elm_object_text_set(entry, buf);
125 evas_object_show(entry);
126
127 box2 = elm_box_add(box);
128 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0);
129 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
130 elm_box_pack_end(box, box2);
131 evas_object_show(box2);
132
133 bt = elm_button_add(box2);
134 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
136 elm_box_pack_end(box2, bt);
137 elm_object_text_set(bt, GET_STYLE_DESC(Wrap));
138 evas_object_smart_callback_add(bt, "clicked", _on_wrap_bt_click, entry);
139 elm_object_scale_set(bt, 2.0);
140 evas_object_show(bt);
141
142 bt2 = elm_button_add(box2);
143 evas_object_size_hint_weight_set(bt2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
144 evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
145 elm_box_pack_end(box2, bt2);
146 elm_object_text_set(bt2, GET_STYLE_DESC(Lang));
147 evas_object_smart_callback_add(bt2, "clicked", _on_lang_bt_click, entry);
148 elm_object_scale_set(bt2, 2.0);
149 evas_object_show(bt2);
150}
151
152EAPI_MAIN int
153elm_main (int argc, char **argv)
154{
155 elm_init(argc, argv);
156
157 _init_demo();
158
159 elm_run();
160
161 return 0;
162}
163ELM_MAIN()