summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Vinicius Alvares Ceolin <flavio.ceolin@profusion.mobi>2012-09-13 14:06:45 +0000
committerFlavio Vinicius Alvares Ceolin <flavio.ceolin@profusion.mobi>2012-09-13 14:06:45 +0000
commit0d97114b7a1a98f2b9c81b15c9fe763c06fbf830 (patch)
treed916c27f6c283455b461af2b894cf2d2c7200ccf
parentbd9b1e7116e4a3386bcb13210852e1f866c3e404 (diff)
elementary_codegen: Adding a basic example
Just adding an example showing how to using the codegen. SVN revision: 76615
-rw-r--r--configure.ac1
-rw-r--r--src/examples/Makefile.am22
-rw-r--r--src/examples/codegen_example.c116
-rw-r--r--src/examples/codegen_example.edc81
4 files changed, 218 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 19287b11a..28fdf492f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -684,6 +684,7 @@ AC_SUBST(requirement_elm)
684 684
685EFL_WITH_BIN([eet], [eet-eet], [eet]) 685EFL_WITH_BIN([eet], [eet-eet], [eet])
686EFL_WITH_BIN([edje], [edje-cc], [edje_cc]) 686EFL_WITH_BIN([edje], [edje-cc], [edje_cc])
687EFL_WITH_BIN([elementary], [elementary-codegen], [elementary_codegen])
687 688
688EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"]) 689EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
689 690
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 9c3ce5ee6..8f61c8996 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -35,6 +35,9 @@ EDJE_FLAGS_VERBOSE_0 =
35EDJE_FLAGS_VERBOSE_1 = -v 35EDJE_FLAGS_VERBOSE_1 = -v
36EDJE_FLAGS = $(EDJE_FLAGS_$(V)) 36EDJE_FLAGS = $(EDJE_FLAGS_$(V))
37 37
38ELEMENTARY_CODEGEN = $(top_builddir)/src/bin/@ELEMENTARY_CODEGEN_PRG@
39ELEMENTARY_CODEGEN_FLAGS = --prefix=codegen_example
40
38SRCS = \ 41SRCS = \
39actionslider_example_01.c \ 42actionslider_example_01.c \
40bg_example_01.c \ 43bg_example_01.c \
@@ -52,6 +55,7 @@ calendar_example_05.c \
52calendar_example_06.c \ 55calendar_example_06.c \
53check_example_01.c \ 56check_example_01.c \
54clock_example.c \ 57clock_example.c \
58codegen_example.edc \
55colorselector_example_01.c \ 59colorselector_example_01.c \
56conformant_example_01.c \ 60conformant_example_01.c \
57conformant_example_02.c \ 61conformant_example_02.c \
@@ -148,11 +152,24 @@ endif
148if EFL_BUILD_EXAMPLES 152if EFL_BUILD_EXAMPLES
149files_DATA += \ 153files_DATA += \
150 theme_example.edj \ 154 theme_example.edj \
151 layout_example.edj 155 layout_example.edj\
156 codegen_example.edj
152 157
153clean-local: 158clean-local:
154 rm -f *.edj 159 rm -f *.edj
155 160
161codegen_example_generated.c codegen_example_generated.h: codegen_example.edj
162 $(ELEMENTARY_CODEGEN) $(ELEMENTARY_CODEGEN_FLAGS) codegen_example.edj \
163 elm/example/mylayout/default codegen_example_generated.c codegen_example_generated.h
164
165BUILT_SOURCES = codegen_example_generated.c codegen_example_generated.h
166
167codegen_example_SOURCES = \
168 codegen_example.c
169nodist_codegen_example_SOURCES = \
170codegen_example_generated.c \
171codegen_example_generated.h
172
156examples_PROGRAMS = \ 173examples_PROGRAMS = \
157actionslider_example_01 \ 174actionslider_example_01 \
158bg_example_01 \ 175bg_example_01 \
@@ -170,6 +187,7 @@ calendar_example_05 \
170calendar_example_06 \ 187calendar_example_06 \
171check_example_01 \ 188check_example_01 \
172clock_example \ 189clock_example \
190codegen_example \
173colorselector_example_01 \ 191colorselector_example_01 \
174conformant_example_01 \ 192conformant_example_01 \
175conformant_example_02 \ 193conformant_example_02 \
@@ -367,4 +385,4 @@ screenshots:
367 385
368endif 386endif
369 387
370EXTRA_DIST = dict.txt layout_example.edc theme_example.edc 388EXTRA_DIST = dict.txt layout_example.edc theme_example.edc codegen.edc
diff --git a/src/examples/codegen_example.c b/src/examples/codegen_example.c
new file mode 100644
index 000000000..a3c380e10
--- /dev/null
+++ b/src/examples/codegen_example.c
@@ -0,0 +1,116 @@
1/**
2 * Simple Elementary example illustrating how to use elementary_codegen.
3 *
4 * elementary_codegen is a tool that generates code to acessing the
5 * parts and programs with the keyword "api" of a specified
6 * group. This tool make easier working with edje avoiding common
7 * misspelling errors when acessing the parts and/or programs.
8 *
9 * To use the elementary_codegen:
10 * elementary_codegen --prefix <myapp_myobj> <input.edj> <a_group> <source.c> <header.h>
11 *
12 * In the case of this example:
13 * elemtary_codegen --prefix=codegen_example codegen_example.edj \
14 * elm/example/mylayout/default codegen_example_generated.c codegen_example_generated.h
15 *
16 * @verbatim
17 * edje_cc codegen_example.edc && elementary_codegen --prefix=codegen_example \
18 * codegen_example.edj example_group codegen_example_generated.c \
19 * codegen_example_generated.h
20 * gcc -c codegen_example_generated.c `pkg-config --libs --cflags ecore-evas edje elementary`
21 * gcc -o codegen_example codegen_example_generated.o \
22 * codegen_example.c `pkg-config --libs --cflags ecore-evas edje elementary`
23 * @endverbatim
24 */
25
26
27#include "codegen_example_generated.h"
28
29
30static Eina_Bool _btn_large = EINA_FALSE;
31
32static void
33_swallow_btn_cb(void *data, Evas_Object *btn, void *event_info)
34{
35 Evas_Object *layout = data;
36
37 if (_btn_large == EINA_FALSE)
38 {
39 _btn_large = EINA_TRUE;
40 codegen_example_swallow_grow_emit(layout);
41 elm_object_text_set(btn, "Reduce me!");
42 }
43 else
44 {
45 _btn_large = EINA_FALSE;
46 codegen_example_swallow_shrink_emit(layout);
47 elm_object_text_set(btn, "Enlarge me!");
48 }
49}
50
51static void
52_size_changed_cb(void *data, Evas_Object *layout, const char *emission, const char *source)
53{
54 Evas_Object *edje;
55 Evas_Coord w, h;
56
57 elm_layout_sizing_eval(layout);
58 edje = elm_layout_edje_get(layout);
59 edje_object_size_min_calc(edje, &w, &h);
60 printf("Minimum size for this theme: %dx%d\n", w, h);
61}
62
63EAPI_MAIN int
64elm_main(int argc, char **argv)
65{
66 Evas_Object *win, *bg, *btn, *layout;
67
68 elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj");
69 win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
70 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
71 elm_win_autodel_set(win, EINA_TRUE);
72
73 bg = elm_bg_add(win);
74 elm_bg_color_set(bg, 255,255 ,255);
75 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
76 elm_win_resize_object_add(win, bg);
77 evas_object_show(bg);
78
79 // Adding layout
80 layout = codegen_example_layout_add(win, NULL, NULL);
81 if (!layout)
82 {
83 printf("Could not create the layout\n");
84 return -1;
85 }
86
87 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
88 elm_win_resize_object_add(win, layout);
89 evas_object_show(layout);
90
91 codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout);
92
93 // Setting title
94 const char *title = codegen_example_title_get(layout);
95 if (title)
96 {
97 elm_win_title_set(win, title);
98 codegen_example_title_set(layout, title);
99 }
100
101 btn = elm_button_add(win);
102 elm_object_text_set(btn, "Enlarge me!");
103 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
105 codegen_example_custom_set(layout, btn);
106 evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
107
108 evas_object_resize(win, 160, 160);
109 evas_object_show(win);
110
111 elm_run();
112 elm_shutdown();
113
114 return 0;
115}
116ELM_MAIN()
diff --git a/src/examples/codegen_example.edc b/src/examples/codegen_example.edc
new file mode 100644
index 000000000..b74374308
--- /dev/null
+++ b/src/examples/codegen_example.edc
@@ -0,0 +1,81 @@
1collections {
2 group {
3 name: "elm/example/mylayout/default";
4
5 data {
6 item: "title" "elm_codegen Example";
7 }
8
9 parts {
10 part {
11 name: "example/title";
12 api: "title" "The example title";
13 type: TEXT;
14
15 description {
16 state: "default" 0.0;
17 color: 0 0 0 255;
18 rel1 {
19 relative: 0.0 0.0;
20 offset: 0 0;
21 }
22 rel2 {
23 relative: 1.0 0.2;
24 offset: -1 -1;
25 }
26 text {
27 text: "Using elementary_codegen";
28 size: 16;
29 font: "sans";
30 min: 1 1;
31 }
32 }
33 }
34
35 part {
36 name: "example/custom";
37 api: "custom" "The swallow part";
38 type: SWALLOW;
39
40 description {
41 state: "default" 0.0;
42 min: 160 50;
43 max: 160 50;
44 align: 0.5 1.0;
45 }
46 description {
47 state: "big" 0.0;
48 inherit: "default" 0.0;
49 min: 320 100;
50 max: 320 100;
51 }
52 } // example/custom
53
54 programs {
55 program {
56 name: "swallow,grow";
57 api: "swallow_grow" "Executed when the button enlarges";
58 signal: "button,enlarge";
59 action: STATE_SET "big" 0.0;
60 transition: LINEAR 0.5;
61 target: "example/custom";
62 after: "emit,changed";
63 }
64 program {
65 name: "swallow,shrink";
66 api: "swallow_shrink" "Executed when the button reduces";
67 signal: "button,reduce";
68 action: STATE_SET "default" 0.0;
69 transition: LINEAR 0.5;
70 target: "example/custom";
71 after: "emit,changed";
72 }
73 program {
74 name: "emit,changed";
75 action: SIGNAL_EMIT "size,changed" "";
76 api: "size_changed" "Emit the signal size,changed";
77 }
78 }
79 }
80 }
81}