efl
141 строка · 4.3 Кб
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* elementary_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 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`
23* @endverbatim
24*/
25
26#include "codegen_example_generated.h"
27
28static Eina_Bool _btn_large = EINA_FALSE;
29
30static void
31_swallow_btn_cb(void *data, Evas_Object *btn, void *event_info EINA_UNUSED)
32{
33Evas_Object *layout = data;
34
35if (_btn_large == EINA_FALSE)
36{
37_btn_large = EINA_TRUE;
38codegen_example_swallow_grow_emit(layout);
39elm_object_text_set(btn, "Reduce me!");
40if (!codegen_example_table_clear(layout, EINA_TRUE))
41fprintf(stderr, "Could not remove the items from the table!\n");
42}
43else
44{
45_btn_large = EINA_FALSE;
46codegen_example_swallow_shrink_emit(layout);
47elm_object_text_set(btn, "Enlarge me!");
48}
49}
50
51static void
52_size_changed_cb(void *data EINA_UNUSED, Evas_Object *layout,
53const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
54{
55Evas_Object *edje;
56Evas_Coord w, h;
57
58elm_layout_sizing_eval(layout);
59edje = elm_layout_edje_get(layout);
60edje_object_size_min_calc(edje, &w, &h);
61printf("Minimum size for this theme: %dx%d\n", w, h);
62}
63
64static Evas_Object *
65_button_create(Evas_Object *parent, const char *label)
66{
67Evas_Object *btn;
68btn = elm_button_add(parent);
69if (!btn) return NULL;
70
71elm_object_text_set(btn, label);
72evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
74
75return btn;
76}
77
78EAPI_MAIN int
79elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
80{
81Evas_Object *win, *btn, *layout, *tbl_items[6];
82const char *labels[] = {"One", "Two", "Three", "Four", "Five", "Six"};
83int i;
84
85elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj");
86
87win = elm_win_util_standard_add("codegen", "Elementary CodeGen");
88elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
89elm_win_autodel_set(win, EINA_TRUE);
90
91// Adding layout
92layout = codegen_example_layout_add(win, NULL, NULL);
93if (!layout)
94{
95printf("Could not create the layout\n");
96return -1;
97}
98
99evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100elm_win_resize_object_add(win, layout);
101evas_object_show(layout);
102
103codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout);
104
105// Setting title
106const char *title = codegen_example_title_get(layout);
107if (title)
108{
109elm_win_title_set(win, title);
110codegen_example_title_set(layout, title);
111}
112
113btn = _button_create(win, "Enlarge me!");
114codegen_example_custom_set(layout, btn);
115evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
116
117for (i = 0; i < 6; i++)
118{
119tbl_items[i] = _button_create(win, labels[i]);
120if (i < 3)
121{
122if (!codegen_example_table_pack(layout, tbl_items[i], i, i, 1,1))
123fprintf(stderr, "Could not add the button to the table!\n");
124}
125else
126{
127if (!codegen_example_box_append(layout, tbl_items[i]))
128fprintf(stderr, "Could not add the button to the box!\n");
129}
130
131evas_object_show(tbl_items[i]);
132}
133
134evas_object_resize(win, 500, 600);
135evas_object_show(win);
136
137elm_run();
138
139return 0;
140}
141ELM_MAIN()
142