efl

Форк
0
/
codegen_example.c 
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

28
static Eina_Bool _btn_large = EINA_FALSE;
29

30
static void
31
_swallow_btn_cb(void *data, Evas_Object *btn, void *event_info EINA_UNUSED)
32
{
33
   Evas_Object *layout = data;
34

35
   if (_btn_large == EINA_FALSE)
36
     {
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");
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

51
static void
52
_size_changed_cb(void *data EINA_UNUSED, Evas_Object *layout,
53
                 const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
54
{
55
   Evas_Object *edje;
56
   Evas_Coord w, h;
57

58
   elm_layout_sizing_eval(layout);
59
   edje = elm_layout_edje_get(layout);
60
   edje_object_size_min_calc(edje, &w, &h);
61
   printf("Minimum size for this theme: %dx%d\n", w, h);
62
}
63

64
static Evas_Object *
65
_button_create(Evas_Object *parent, const char *label)
66
{
67
   Evas_Object *btn;
68
   btn = elm_button_add(parent);
69
   if (!btn) return NULL;
70

71
   elm_object_text_set(btn, label);
72
   evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73
   evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
74

75
   return btn;
76
}
77

78
EAPI_MAIN int
79
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
80
{
81
   Evas_Object *win, *btn, *layout, *tbl_items[6];
82
   const char *labels[] = {"One", "Two", "Three", "Four", "Five", "Six"};
83
   int i;
84

85
   elm_app_info_set(elm_main, "elementary", "examples/codegen_example.edj");
86

87
   win = elm_win_util_standard_add("codegen", "Elementary CodeGen");
88
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
89
   elm_win_autodel_set(win, EINA_TRUE);
90

91
   // Adding layout
92
   layout = codegen_example_layout_add(win, NULL, NULL);
93
   if (!layout)
94
     {
95
        printf("Could not create the layout\n");
96
        return -1;
97
     }
98

99
   evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100
   elm_win_resize_object_add(win, layout);
101
   evas_object_show(layout);
102

103
   codegen_example_size_changed_callback_add(layout, _size_changed_cb, layout);
104

105
   // Setting title
106
   const char *title = codegen_example_title_get(layout);
107
   if (title)
108
     {
109
        elm_win_title_set(win, title);
110
        codegen_example_title_set(layout, title);
111
     }
112

113
   btn = _button_create(win, "Enlarge me!");
114
   codegen_example_custom_set(layout, btn);
115
   evas_object_smart_callback_add(btn, "clicked", _swallow_btn_cb, layout);
116

117
   for (i = 0; i < 6; i++)
118
     {
119
        tbl_items[i] = _button_create(win, labels[i]);
120
        if (i < 3)
121
          {
122
             if (!codegen_example_table_pack(layout, tbl_items[i], i, i, 1,1))
123
               fprintf(stderr, "Could not add the button to the table!\n");
124
          }
125
        else
126
          {
127
             if (!codegen_example_box_append(layout, tbl_items[i]))
128
               fprintf(stderr, "Could not add the button to the box!\n");
129
          }
130

131
        evas_object_show(tbl_items[i]);
132
     }
133

134
   evas_object_resize(win, 500, 600);
135
   evas_object_show(win);
136

137
   elm_run();
138

139
   return 0;
140
}
141
ELM_MAIN()
142

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.