[access] move mouse postion if an object has a highlight by highlight_cycle(); not...
[framework/uifw/elementary.git] / src / examples / codegen_example.c
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
30 static Eina_Bool _btn_large = EINA_FALSE;
31
32 static 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         if (!codegen_example_table_clear(layout, EINA_TRUE))
43           fprintf(stderr, "Could not remove the items from the table!\n");
44      }
45    else
46      {
47         _btn_large = EINA_FALSE;
48         codegen_example_swallow_shrink_emit(layout);
49         elm_object_text_set(btn, "Enlarge me!");
50      }
51 }
52
53 static void
54 _size_changed_cb(void *data, Evas_Object *layout, const char *emission, const char *source)
55 {
56    Evas_Object *edje;
57    Evas_Coord w, h;
58
59    elm_layout_sizing_eval(layout);
60    edje = elm_layout_edje_get(layout);
61    edje_object_size_min_calc(edje, &w, &h);
62    printf("Minimum size for this theme: %dx%d\n", w, h);
63 }
64
65 static Evas_Object *
66 _button_create(Evas_Object *parent, const char *label)
67 {
68    Evas_Object *btn;
69    btn = elm_button_add(parent);
70    if (!btn) return NULL;
71
72    elm_object_text_set(btn, label);
73    evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74    evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
75
76    return btn;
77 }
78
79 EAPI_MAIN int
80 elm_main(int argc, char **argv)
81 {
82     Evas_Object *win, *bg, *btn, *layout, *tbl_items[6];
83     const char *labels[] = {"One", "Two", "Three", "Four", "Five", "Six"};
84     int i;
85
86    elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj");
87    win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
88    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
89    elm_win_autodel_set(win, EINA_TRUE);
90
91    bg = elm_bg_add(win);
92    elm_bg_color_set(bg, 255,255 ,255);
93    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
94    elm_win_resize_object_add(win, bg);
95    evas_object_show(bg);
96
97    // Adding layout
98    layout = codegen_example_layout_add(win, NULL, NULL);
99    if (!layout)
100      {
101         printf("Could not create the layout\n");
102         return -1;
103      }
104
105    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106    elm_win_resize_object_add(win, layout);
107    evas_object_show(layout);
108
109    codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout);
110
111    // Setting title
112    const char *title = codegen_example_title_get(layout);
113    if (title)
114      {
115         elm_win_title_set(win, title);
116         codegen_example_title_set(layout, title);
117      }
118
119    btn = _button_create(win, "Enlarge me!");
120    codegen_example_custom_set(layout, btn);
121    evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
122
123    for (i = 0; i < 6; i++)
124      {
125         tbl_items[i] = _button_create(win, labels[i]);
126         if (i < 3)
127           {
128              if (!codegen_example_table_pack(layout, tbl_items[i], i, i, 1,1))
129                fprintf(stderr, "Could not add the button to the table!\n");
130           }
131         else
132           {
133              if (!codegen_example_box_append(layout, tbl_items[i]))
134                fprintf(stderr, "Could not add the button to the box!\n");
135           }
136
137         evas_object_show(tbl_items[i]);
138      }
139
140    evas_object_resize(win, 500, 600);
141    evas_object_show(win);
142
143    elm_run();
144    elm_shutdown();
145
146    return 0;
147 }
148 ELM_MAIN()