summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2016-07-01 20:57:42 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2016-07-05 14:13:03 -0300
commit132f8f1f375ae8bf376c5b46f04fc67e7986c7d2 (patch)
tree27c94ca7628e2ff1f0ba5dcf83e8575a0eb241e4
parentae26833fbd550ebb92f7305db118db50935c0d50 (diff)
elementary: add example layout_model_connect
-rw-r--r--src/examples/elementary/Makefile.am2
-rw-r--r--src/examples/elementary/layout_model_connect.c149
2 files changed, 151 insertions, 0 deletions
diff --git a/src/examples/elementary/Makefile.am b/src/examples/elementary/Makefile.am
index 08f5e13f1c..19b65f7b55 100644
--- a/src/examples/elementary/Makefile.am
+++ b/src/examples/elementary/Makefile.am
@@ -116,6 +116,7 @@ layout_example.edc \
116layout_example_01.c \ 116layout_example_01.c \
117layout_example_02.c \ 117layout_example_02.c \
118layout_example_03.c \ 118layout_example_03.c \
119layout_model_connect.c \
119list_example_01.c \ 120list_example_01.c \
120list_example_02.c \ 121list_example_02.c \
121list_example_03.c \ 122list_example_03.c \
@@ -313,6 +314,7 @@ label_example_01 \
313layout_example_01 \ 314layout_example_01 \
314layout_example_02 \ 315layout_example_02 \
315layout_example_03 \ 316layout_example_03 \
317layout_model_connect \
316list_example_01 \ 318list_example_01 \
317list_example_02 \ 319list_example_02 \
318list_example_03 \ 320list_example_03 \
diff --git a/src/examples/elementary/layout_model_connect.c b/src/examples/elementary/layout_model_connect.c
new file mode 100644
index 0000000000..5cfd43c396
--- /dev/null
+++ b/src/examples/elementary/layout_model_connect.c
@@ -0,0 +1,149 @@
1// gcc -o layout_model_connect layout_model_connect.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#include <Elementary.h>
11#include <Efl.h>
12#include <Eio.h>
13#include <stdio.h>
14#include <Eio.h>
15
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17
18struct _Layout_Model_Data
19{
20 Eo *fileview;
21 Eo *model;
22 Evas_Object *label;
23 Evas_Object *entry;
24};
25typedef struct _Layout_Model_Data Layout_Model_Data;
26
27static void
28_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
29{
30 Layout_Model_Data *priv = (Layout_Model_Data*)data;
31 eo_unref(priv->fileview);
32 eo_unref(priv->model);
33}
34
35static void
36_list_selected_cb(void *data EINA_UNUSED, const Eo_Event *event)
37{
38 Layout_Model_Data *priv = data;
39 Eo *child = event->info;
40
41 printf("LIST selected model\n");
42 efl_ui_view_model_set(priv->label, child);
43 efl_ui_view_model_set(priv->entry, child);
44}
45
46
47static void
48_update_cb(void *data, Evas_Object *obj, void *ev)
49{
50 Layout_Model_Data *priv = data;
51
52 const char *text = elm_object_text_get(priv->entry);
53 elm_layout_text_set(priv->label, "default", text);
54}
55
56static void
57_widget_init(Evas_Object *widget)
58{
59 evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
60 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
61 evas_object_show(widget);
62}
63
64Evas_Object *
65_label_init(Evas_Object *win, Evas_Object *box, const char *text)
66{
67 Evas_Object *widget = elm_label_add(win);
68 elm_label_line_wrap_set(widget, ELM_WRAP_CHAR);
69 elm_object_text_set(widget, text);
70 elm_box_pack_end(box, widget);
71 evas_object_size_hint_weight_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
72 evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
73 evas_object_show(widget);
74
75 return widget;
76}
77
78EAPI_MAIN int
79elm_main(int argc, char **argv)
80{
81 Layout_Model_Data *priv;
82 Evas_Object *win, *panes, *bxr, *genlist, *bt;
83 char *dirname;
84
85 priv = alloca(sizeof(Layout_Model_Data));
86 memset(priv, 0, sizeof(Layout_Model_Data));
87
88 //win
89 win = elm_win_util_standard_add("viewlist", "Viewlist");
90 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
91 elm_win_autodel_set(win, EINA_TRUE);
92
93 panes = elm_panes_add(win);
94 evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
95 elm_win_resize_object_add(win, panes);
96
97 if(argv[1] != NULL) dirname = argv[1];
98 else dirname = EFL_MODEL_TEST_FILENAME_PATH;
99
100 priv->model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
101
102 genlist = elm_genlist_add(win);
103 priv->fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_NONE, NULL));
104 elm_view_list_property_connect(priv->fileview, "filename", "elm.text");
105 elm_view_list_model_set(priv->fileview, priv->model);
106 _widget_init(genlist);
107 elm_object_part_content_set(panes, "left", genlist);
108 elm_obj_panes_content_left_size_set(panes, 0.3);
109 eo_event_callback_add(priv->fileview, ELM_VIEW_LIST_EVENT_MODEL_SELECTED, _list_selected_cb, priv);
110
111 bxr = elm_box_add(win);
112 _widget_init(bxr);
113 elm_object_part_content_set(panes, "right", bxr);
114
115 /*Label widget */
116
117 _label_init(win, bxr, "FILENAME:");
118 priv->label = _label_init(win, bxr, "");
119 efl_ui_model_connect(priv->label, "default", "path"); //connect "default" to "filename" property
120
121 /* Entry widget */
122 priv->entry = elm_entry_add(win);
123 efl_ui_model_connect(priv->entry, "elm.text", "path"); //connect "elm.text" to "path" property
124 elm_entry_single_line_set(priv->entry, EINA_TRUE);
125 elm_box_pack_end(bxr, priv->entry);
126 evas_object_size_hint_weight_set(priv->entry, EVAS_HINT_FILL, 0);
127 evas_object_size_hint_align_set(priv->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
128 evas_object_show(priv->entry);
129
130 /* Button widget */
131 bt = elm_button_add(win);
132 elm_box_pack_end(bxr, bt);
133 elm_object_text_set(bt, "update model");
134 evas_object_smart_callback_add(bt, "clicked", _update_cb, priv);
135 evas_object_show(bt);
136
137 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, priv);
138 //showall
139 evas_object_resize(win, 800, 400);
140 evas_object_show(panes);
141 evas_object_show(win);
142
143 elm_run();
144 elm_shutdown();
145 ecore_shutdown();
146
147 return 0;
148}
149ELM_MAIN()