summaryrefslogtreecommitdiff
path: root/src/examples/elementary/efl_ui_list_view_example_3.c
diff options
context:
space:
mode:
authorSangHyeon Jade Lee <sh10233.lee@samsung.com>2018-11-05 14:27:05 +0900
committerHermet Park <hermetpark@gmail.com>2018-11-05 14:27:05 +0900
commite97b6b72bebfc91f44c4ab98f3ff1b7920344c07 (patch)
tree9e1d059c319b9208114b05df5356961d81ff06a0 /src/examples/elementary/efl_ui_list_view_example_3.c
parentc4e0d3f69d8203ad3ff4f3fdeb0a0adfaffdd1cd (diff)
efl_ui : change efl_ui_view_list to efl_ui_list_view.
Summary: View is not a namespace, but an interface, So, View_List cannot be under the view namespace for now. it looks more suite to be end as View than List on this widget name. Firstly, it follows our common naming rules of class. Also, List_View is commonly presentable name on most UI frameworks, so it is very easy to understand what this widget can do for the user. Test Plan: Make works. Example is not works for now til stable model interface. Reviewers: felipealmeida, woohyun, cedric, Hermet Reviewed By: Hermet Subscribers: larryolj, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7234
Diffstat (limited to 'src/examples/elementary/efl_ui_list_view_example_3.c')
-rw-r--r--src/examples/elementary/efl_ui_list_view_example_3.c332
1 files changed, 332 insertions, 0 deletions
diff --git a/src/examples/elementary/efl_ui_list_view_example_3.c b/src/examples/elementary/efl_ui_list_view_example_3.c
new file mode 100644
index 0000000000..46d5ca5813
--- /dev/null
+++ b/src/examples/elementary/efl_ui_list_view_example_3.c
@@ -0,0 +1,332 @@
1// gcc -o efl_ui_list_view_example_3 efl_ui_list_view_example_3.c `pkg-config --cflags --libs elementary`
2
3#ifdef HAVE_CONFIG_H
4# include "config.h"
5#else
6# define EFL_BETA_API_SUPPORT 1
7# define EFL_EO_API_SUPPORT 1
8#endif
9
10#define ELM_INTERFACE_ATSPI_SELECTION_PROTECTED
11
12#include <Eo.h>
13#include <Elementary.h>
14#include <Efl.h>
15#include <Eio.h>
16#include <stdio.h>
17
18const char *subtexts[] = {
19 "Captain",
20 "Princess ",
21 "Actor",
22 "Translator",
23 "Jedi",
24 "Singer",
25 "Fighter"
26 };
27
28const char *texts[] = {
29 "Morpheus",
30 "Leia",
31 "Chuck Norris",
32 "Nyota Uhura",
33 "Darth Vader",
34 "Elvis Presley",
35 "Chun-Li"
36 };
37
38char edj_path[PATH_MAX];
39
40struct _Priv_Data
41{
42 Eo *model;
43 Evas_Object *list1;
44 Evas_Object *list2;
45 Evas_Object *e_name;
46 Evas_Object *e_occ;
47 Evas_Object *selected;
48};
49typedef struct _Priv_Data Priv_Data;
50
51static void
52_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
53{
54 Priv_Data *priv = (Priv_Data*)data;
55 efl_unref(priv->model);
56}
57
58static void
59_focused(void *data, const Efl_Event *event)
60{
61 Priv_Data *priv = (Priv_Data*)data;
62 Evas_Object *focused = efl_ui_focus_manager_focus_get(event->object);
63
64 if (focused)
65 priv->selected = focused;
66}
67
68static void
69_bt_add_clicked(void *data, Evas_Object *obj, void *event_info)
70{
71 Priv_Data *priv = (Priv_Data*)data;
72 Eina_Value vtext, value;
73 Efl_Model_Item *child;
74
75 eina_value_setup(&vtext, EINA_VALUE_TYPE_STRING);
76 eina_value_setup(&value, EINA_VALUE_TYPE_UCHAR);
77 child = efl_model_child_add(priv->model);
78
79 eina_value_set(&vtext, elm_object_text_get(priv->e_name));
80 efl_model_property_set(child, "name", &vtext);
81
82 eina_value_set(&vtext, elm_object_text_get(priv->e_occ));
83 efl_model_property_set(child, "occupation", &vtext);
84
85 eina_value_set(&value, EINA_FALSE);
86 efl_model_property_set(child, "selected", &vtext);
87
88 eina_value_flush(&vtext);
89 eina_value_flush(&value);
90}
91
92static void
93_bt_del_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
94{
95 Priv_Data *priv = (Priv_Data*)data;
96 Eo *child = NULL;
97
98 //l = efl_ui_focus_manager_focus_get(priv->list1);
99 if(priv->selected)
100 {
101 printf("focused %p\n", priv->selected);
102 child = efl_ui_view_model_get(priv->selected);
103 efl_model_child_del(priv->model, child);
104 priv->selected = NULL;
105 }
106 else
107 {
108 printf("no focused\n");
109 }
110}
111
112static void
113_bt_none_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
114{
115 Evas_Object *li = data;
116 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_NONE);
117}
118
119static void
120_bt_donly_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
121{
122 Evas_Object *li = data;
123 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
124}
125
126static void
127_bt_default_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
128{
129 Evas_Object *li = data;
130 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DEFAULT);
131}
132
133static void
134_bt_set_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
135{
136 Priv_Data *priv = data;
137 efl_ui_view_model_set(priv->list2, priv->model);
138}
139
140static void
141_bt_unset_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
142{
143 Evas_Object *li = data;
144 efl_ui_view_model_set(li, NULL);
145}
146static void
147_realized_1_cb(void *data EINA_UNUSED, const Efl_Event *event)
148{
149 Efl_Ui_List_View_Item_Event *ie = event->info;
150
151 evas_object_size_hint_weight_set(ie->layout, EVAS_HINT_EXPAND, 0);
152 evas_object_size_hint_align_set(ie->layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
153 efl_ui_model_connect(ie->layout, "efl.text", "name");
154 efl_ui_model_connect(ie->layout, "signal/efl,state,%v", "odd_style");
155}
156
157static void
158_realized_2_cb(void *data EINA_UNUSED, const Efl_Event *event)
159{
160 Efl_Ui_List_View_Item_Event *ie = event->info;
161 printf("relized 2\n");
162
163 elm_object_focus_allow_set(ie->layout, EINA_TRUE);
164 evas_object_size_hint_weight_set(ie->layout, EVAS_HINT_EXPAND, 0);
165 evas_object_size_hint_align_set(ie->layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
166 efl_ui_model_connect(ie->layout, "efl.text", "occupation");
167}
168
169static Efl_Model*
170_make_model()
171{
172 Eina_Value vtext, value;
173 Efl_Model_Item *model, *child;
174 unsigned int i, len;
175
176 model = efl_add(EFL_MODEL_ITEM_CLASS, efl_main_loop_get());
177 eina_value_setup(&vtext, EINA_VALUE_TYPE_STRING);
178 eina_value_setup(&value, EINA_VALUE_TYPE_UCHAR);
179
180 len = sizeof(texts)/sizeof(const char*);
181 for (i = 0; i < (len); i++)
182 {
183 child = efl_model_child_add(model);
184
185 i%2 ? eina_value_set(&vtext, "even") : eina_value_set(&vtext, "odd");
186 efl_model_property_set(child, "odd_style", &vtext);
187
188 eina_value_set(&vtext, texts[(i % len)]);
189 efl_model_property_set(child, "name", &vtext);
190
191 eina_value_set(&vtext, subtexts[(i % len)]);
192 efl_model_property_set(child, "occupation", &vtext);
193
194 eina_value_set(&value, EINA_FALSE);
195 efl_model_property_set(child, "selected", &value);
196 }
197
198 eina_value_flush(&vtext);
199 eina_value_flush(&value);
200 return model;
201}
202
203EAPI_MAIN int
204elm_main(int argc, char **argv)
205{
206 Priv_Data *priv;
207 Evas_Object *win, *bx, *vbx, *bt;
208 Efl_Ui_Layout_Factory *factory;
209
210 priv = alloca(sizeof(Priv_Data));
211 memset(priv, 0, sizeof(Priv_Data));
212
213 win = elm_win_util_standard_add("list_view3", "List_View3");
214 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
215 elm_win_autodel_set(win, EINA_TRUE);
216
217 bx = elm_box_add(win);
218 elm_box_horizontal_set(bx, EINA_TRUE);
219 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
220 elm_win_resize_object_add(win, bx);
221 evas_object_show(bx);
222
223 priv->model = _make_model();
224 factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win);
225 efl_ui_model_connect(factory, "efl.text", "filename");
226 efl_ui_layout_factory_theme_config(factory, "list_item", NULL, "default");
227
228 priv->list1 = efl_add(EFL_UI_LIST_VIEW_CLASS, win, efl_ui_view_model_set(efl_added, priv->model));
229 efl_event_callback_add(priv->list1, EFL_UI_LIST_VIEW_EVENT_ITEM_REALIZED, _realized_1_cb, priv);
230 evas_object_size_hint_weight_set(priv->list1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231 evas_object_size_hint_align_set(priv->list1, EVAS_HINT_FILL, EVAS_HINT_FILL);
232 elm_box_pack_end(bx, priv->list1);
233 efl_ui_list_view_layout_factory_set(priv->list1, factory);
234
235 factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win);
236 efl_ui_model_connect(factory, "efl.text", "filename");
237 efl_ui_model_connect(factory, "signal/efl,state,%v", "selected");
238 efl_ui_layout_factory_theme_config(factory, "list_item", NULL, "default");
239 priv->list2 = efl_add(EFL_UI_LIST_VIEW_CLASS, win, efl_ui_view_model_set(efl_added, priv->model));
240 efl_event_callback_add(priv->list2, EFL_UI_LIST_VIEW_EVENT_ITEM_REALIZED, _realized_2_cb, priv->list2);
241 evas_object_size_hint_weight_set(priv->list2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
242 evas_object_size_hint_align_set(priv->list2, EVAS_HINT_FILL, EVAS_HINT_FILL);
243 efl_ui_list_view_layout_factory_set(priv->list2, factory);
244
245 vbx = elm_box_add(win);
246 elm_box_pack_end(bx, vbx);
247
248 bt = elm_label_add(win);
249 elm_object_text_set(bt, "Name:");
250 elm_box_pack_end(vbx, bt);
251 evas_object_show(bt);
252
253 priv->e_name = elm_entry_add(win);
254 elm_box_pack_end(vbx, priv->e_name);
255 elm_object_text_set(priv->e_name, "Neo");
256 evas_object_size_hint_weight_set(priv->e_name, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
257 evas_object_size_hint_align_set(priv->e_name, EVAS_HINT_FILL, EVAS_HINT_FILL);
258 evas_object_show(priv->e_name);
259
260 bt = elm_label_add(win);
261 elm_object_text_set(bt, "Occupation:");
262 elm_box_pack_end(vbx, bt);
263 evas_object_show(bt);
264
265 priv->e_occ = elm_entry_add(win);
266 elm_box_pack_end(vbx, priv->e_occ);
267 elm_object_text_set(priv->e_occ, "Chosen");
268 evas_object_size_hint_weight_set(priv->e_occ, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
269 evas_object_size_hint_align_set(priv->e_occ, EVAS_HINT_FILL, EVAS_HINT_FILL);
270 evas_object_show(priv->e_occ);
271
272 bt = elm_button_add(win);
273 elm_object_text_set(bt, "Add Item");
274 evas_object_smart_callback_add(bt, "clicked", _bt_add_clicked, priv);
275 evas_object_show(bt);
276 elm_box_pack_end(vbx, bt);
277
278 bt = elm_button_add(win);
279 elm_object_text_set(bt, "Delete Item");
280 evas_object_smart_callback_add(bt, "clicked", _bt_del_clicked, priv);
281 evas_object_show(bt);
282 elm_box_pack_end(vbx, bt);
283
284 bt = elm_button_add(win);
285 elm_object_text_set(bt, "Select None");
286 evas_object_smart_callback_add(bt, "clicked", _bt_none_clicked, priv->list2);
287 evas_object_show(bt);
288 elm_box_pack_end(vbx, bt);
289
290 bt = elm_button_add(win);
291 elm_object_text_set(bt, "Select DisplayOnly");
292 evas_object_smart_callback_add(bt, "clicked", _bt_donly_clicked, priv->list2);
293 evas_object_show(bt);
294 elm_box_pack_end(vbx, bt);
295
296 bt = elm_button_add(win);
297 elm_object_text_set(bt, "Select Default");
298 evas_object_smart_callback_add(bt, "clicked", _bt_default_clicked, priv->list2);
299 evas_object_show(bt);
300 elm_box_pack_end(vbx, bt);
301
302 bt = elm_button_add(win);
303 elm_object_text_set(bt, "Model Set");
304 evas_object_smart_callback_add(bt, "clicked", _bt_set_clicked, priv);
305 evas_object_show(bt);
306 elm_box_pack_end(vbx, bt);
307
308
309 bt = elm_button_add(win);
310 elm_object_text_set(bt, "Model Unset");
311 evas_object_smart_callback_add(bt, "clicked", _bt_unset_clicked, priv->list2);
312 evas_object_show(bt);
313 elm_box_pack_end(vbx, bt);
314
315 elm_box_pack_end(bx, priv->list2);
316 efl_event_callback_add(priv->list2, EFL_UI_FOCUS_MANAGER_EVENT_FOCUS_CHANGED, _focused ,priv);
317
318 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, priv);
319
320 //showall
321 evas_object_show(priv->list1);
322 evas_object_show(priv->list2);
323 evas_object_show(bx);
324 evas_object_show(vbx);
325 evas_object_resize(win, 400, 320);
326 evas_object_show(win);
327
328 elm_run();
329
330 return 0;
331}
332ELM_MAIN()