2 * Simple Elementary example illustrating how to use elementary_codegen.
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.
9 * To use the elementary_codegen:
10 * elementary_codegen --prefix <myapp_myobj> <input.edj> <a_group> <source.c> <header.h>
12 * In the case of this example:
13 * elementary_codegen --prefix=codegen_example codegen_example.edj \
14 * elm/example/mylayout/default codegen_example_generated.c codegen_example_generated.h
17 * edje_cc codegen_example.edc && elementary_codegen --prefix=codegen_example \
18 * codegen_example.edj elm/example/mylayout/default 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`
26 #include "codegen_example_generated.h"
28 static Eina_Bool _btn_large = EINA_FALSE;
31 _swallow_btn_cb(void *data, Evas_Object *btn, void *event_info)
33 Evas_Object *layout = data;
35 if (_btn_large == EINA_FALSE)
37 _btn_large = EINA_TRUE;
38 codegen_example_swallow_grow_emit(layout);
39 elm_object_text_set(btn, "Reduce me!");
40 if (!codegen_example_table_clear(layout, EINA_TRUE))
41 fprintf(stderr, "Could not remove the items from the table!\n");
45 _btn_large = EINA_FALSE;
46 codegen_example_swallow_shrink_emit(layout);
47 elm_object_text_set(btn, "Enlarge me!");
52 _size_changed_cb(void *data, Evas_Object *layout, const char *emission, const char *source)
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);
64 _button_create(Evas_Object *parent, const char *label)
67 btn = elm_button_add(parent);
68 if (!btn) return NULL;
70 elm_object_text_set(btn, label);
71 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
72 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
78 elm_main(int argc, char **argv)
80 Evas_Object *win, *btn, *layout, *tbl_items[6];
81 const char *labels[] = {"One", "Two", "Three", "Four", "Five", "Six"};
84 elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj");
86 win = elm_win_util_standard_add("codegen", "Elementary CodeGen");
87 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
88 elm_win_autodel_set(win, EINA_TRUE);
91 layout = codegen_example_layout_add(win, NULL, NULL);
94 printf("Could not create the layout\n");
98 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99 elm_win_resize_object_add(win, layout);
100 evas_object_show(layout);
102 codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout);
105 const char *title = codegen_example_title_get(layout);
108 elm_win_title_set(win, title);
109 codegen_example_title_set(layout, title);
112 btn = _button_create(win, "Enlarge me!");
113 codegen_example_custom_set(layout, btn);
114 evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
116 for (i = 0; i < 6; i++)
118 tbl_items[i] = _button_create(win, labels[i]);
121 if (!codegen_example_table_pack(layout, tbl_items[i], i, i, 1,1))
122 fprintf(stderr, "Could not add the button to the table!\n");
126 if (!codegen_example_box_append(layout, tbl_items[i]))
127 fprintf(stderr, "Could not add the button to the box!\n");
130 evas_object_show(tbl_items[i]);
133 evas_object_resize(win, 500, 600);
134 evas_object_show(win);