From b65e5ed1ec193214bf5c8b656d295a030b65957b Mon Sep 17 00:00:00 2001 From: Flavio Vinicius Alvares Ceolin Date: Thu, 13 Sep 2012 14:06:45 +0000 Subject: [PATCH] elementary_codegen: Adding a basic example Just adding an example showing how to using the codegen. SVN revision: 76615 --- legacy/elementary/configure.ac | 1 + legacy/elementary/src/examples/Makefile.am | 22 +++- .../elementary/src/examples/codegen_example.c | 116 ++++++++++++++++++ .../src/examples/codegen_example.edc | 81 ++++++++++++ 4 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 legacy/elementary/src/examples/codegen_example.c create mode 100644 legacy/elementary/src/examples/codegen_example.edc diff --git a/legacy/elementary/configure.ac b/legacy/elementary/configure.ac index 19287b11ae..28fdf492fd 100644 --- a/legacy/elementary/configure.ac +++ b/legacy/elementary/configure.ac @@ -684,6 +684,7 @@ AC_SUBST(requirement_elm) EFL_WITH_BIN([eet], [eet-eet], [eet]) EFL_WITH_BIN([edje], [edje-cc], [edje_cc]) +EFL_WITH_BIN([elementary], [elementary-codegen], [elementary_codegen]) EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"]) diff --git a/legacy/elementary/src/examples/Makefile.am b/legacy/elementary/src/examples/Makefile.am index 9c3ce5ee6f..8f61c8996d 100644 --- a/legacy/elementary/src/examples/Makefile.am +++ b/legacy/elementary/src/examples/Makefile.am @@ -35,6 +35,9 @@ EDJE_FLAGS_VERBOSE_0 = EDJE_FLAGS_VERBOSE_1 = -v EDJE_FLAGS = $(EDJE_FLAGS_$(V)) +ELEMENTARY_CODEGEN = $(top_builddir)/src/bin/@ELEMENTARY_CODEGEN_PRG@ +ELEMENTARY_CODEGEN_FLAGS = --prefix=codegen_example + SRCS = \ actionslider_example_01.c \ bg_example_01.c \ @@ -52,6 +55,7 @@ calendar_example_05.c \ calendar_example_06.c \ check_example_01.c \ clock_example.c \ +codegen_example.edc \ colorselector_example_01.c \ conformant_example_01.c \ conformant_example_02.c \ @@ -148,11 +152,24 @@ endif if EFL_BUILD_EXAMPLES files_DATA += \ theme_example.edj \ - layout_example.edj + layout_example.edj\ + codegen_example.edj clean-local: rm -f *.edj +codegen_example_generated.c codegen_example_generated.h: codegen_example.edj + $(ELEMENTARY_CODEGEN) $(ELEMENTARY_CODEGEN_FLAGS) codegen_example.edj \ + elm/example/mylayout/default codegen_example_generated.c codegen_example_generated.h + +BUILT_SOURCES = codegen_example_generated.c codegen_example_generated.h + +codegen_example_SOURCES = \ + codegen_example.c +nodist_codegen_example_SOURCES = \ +codegen_example_generated.c \ +codegen_example_generated.h + examples_PROGRAMS = \ actionslider_example_01 \ bg_example_01 \ @@ -170,6 +187,7 @@ calendar_example_05 \ calendar_example_06 \ check_example_01 \ clock_example \ +codegen_example \ colorselector_example_01 \ conformant_example_01 \ conformant_example_02 \ @@ -367,4 +385,4 @@ screenshots: endif -EXTRA_DIST = dict.txt layout_example.edc theme_example.edc +EXTRA_DIST = dict.txt layout_example.edc theme_example.edc codegen.edc diff --git a/legacy/elementary/src/examples/codegen_example.c b/legacy/elementary/src/examples/codegen_example.c new file mode 100644 index 0000000000..a3c380e106 --- /dev/null +++ b/legacy/elementary/src/examples/codegen_example.c @@ -0,0 +1,116 @@ +/** + * Simple Elementary example illustrating how to use elementary_codegen. + * + * elementary_codegen is a tool that generates code to acessing the + * parts and programs with the keyword "api" of a specified + * group. This tool make easier working with edje avoiding common + * misspelling errors when acessing the parts and/or programs. + * + * To use the elementary_codegen: + * elementary_codegen --prefix + * + * In the case of this example: + * elemtary_codegen --prefix=codegen_example codegen_example.edj \ + * elm/example/mylayout/default codegen_example_generated.c codegen_example_generated.h + * + * @verbatim + * edje_cc codegen_example.edc && elementary_codegen --prefix=codegen_example \ + * codegen_example.edj example_group codegen_example_generated.c \ + * codegen_example_generated.h + * gcc -c codegen_example_generated.c `pkg-config --libs --cflags ecore-evas edje elementary` + * gcc -o codegen_example codegen_example_generated.o \ + * codegen_example.c `pkg-config --libs --cflags ecore-evas edje elementary` + * @endverbatim + */ + + +#include "codegen_example_generated.h" + + +static Eina_Bool _btn_large = EINA_FALSE; + +static void +_swallow_btn_cb(void *data, Evas_Object *btn, void *event_info) +{ + Evas_Object *layout = data; + + if (_btn_large == EINA_FALSE) + { + _btn_large = EINA_TRUE; + codegen_example_swallow_grow_emit(layout); + elm_object_text_set(btn, "Reduce me!"); + } + else + { + _btn_large = EINA_FALSE; + codegen_example_swallow_shrink_emit(layout); + elm_object_text_set(btn, "Enlarge me!"); + } +} + +static void +_size_changed_cb(void *data, Evas_Object *layout, const char *emission, const char *source) +{ + Evas_Object *edje; + Evas_Coord w, h; + + elm_layout_sizing_eval(layout); + edje = elm_layout_edje_get(layout); + edje_object_size_min_calc(edje, &w, &h); + printf("Minimum size for this theme: %dx%d\n", w, h); +} + +EAPI_MAIN int +elm_main(int argc, char **argv) +{ + Evas_Object *win, *bg, *btn, *layout; + + elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj"); + win = elm_win_add(NULL, "layout", ELM_WIN_BASIC); + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + elm_win_autodel_set(win, EINA_TRUE); + + bg = elm_bg_add(win); + elm_bg_color_set(bg, 255,255 ,255); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bg); + evas_object_show(bg); + + // Adding layout + layout = codegen_example_layout_add(win, NULL, NULL); + if (!layout) + { + printf("Could not create the layout\n"); + return -1; + } + + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, layout); + evas_object_show(layout); + + codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout); + + // Setting title + const char *title = codegen_example_title_get(layout); + if (title) + { + elm_win_title_set(win, title); + codegen_example_title_set(layout, title); + } + + btn = elm_button_add(win); + elm_object_text_set(btn, "Enlarge me!"); + evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL); + codegen_example_custom_set(layout, btn); + evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout); + + evas_object_resize(win, 160, 160); + evas_object_show(win); + + elm_run(); + elm_shutdown(); + + return 0; +} +ELM_MAIN() diff --git a/legacy/elementary/src/examples/codegen_example.edc b/legacy/elementary/src/examples/codegen_example.edc new file mode 100644 index 0000000000..b743743083 --- /dev/null +++ b/legacy/elementary/src/examples/codegen_example.edc @@ -0,0 +1,81 @@ +collections { + group { + name: "elm/example/mylayout/default"; + + data { + item: "title" "elm_codegen Example"; + } + + parts { + part { + name: "example/title"; + api: "title" "The example title"; + type: TEXT; + + description { + state: "default" 0.0; + color: 0 0 0 255; + rel1 { + relative: 0.0 0.0; + offset: 0 0; + } + rel2 { + relative: 1.0 0.2; + offset: -1 -1; + } + text { + text: "Using elementary_codegen"; + size: 16; + font: "sans"; + min: 1 1; + } + } + } + + part { + name: "example/custom"; + api: "custom" "The swallow part"; + type: SWALLOW; + + description { + state: "default" 0.0; + min: 160 50; + max: 160 50; + align: 0.5 1.0; + } + description { + state: "big" 0.0; + inherit: "default" 0.0; + min: 320 100; + max: 320 100; + } + } // example/custom + + programs { + program { + name: "swallow,grow"; + api: "swallow_grow" "Executed when the button enlarges"; + signal: "button,enlarge"; + action: STATE_SET "big" 0.0; + transition: LINEAR 0.5; + target: "example/custom"; + after: "emit,changed"; + } + program { + name: "swallow,shrink"; + api: "swallow_shrink" "Executed when the button reduces"; + signal: "button,reduce"; + action: STATE_SET "default" 0.0; + transition: LINEAR 0.5; + target: "example/custom"; + after: "emit,changed"; + } + program { + name: "emit,changed"; + action: SIGNAL_EMIT "size,changed" ""; + api: "size_changed" "Emit the signal size,changed"; + } + } + } + } +}