2 * Simple Edje example illustrating table functions.
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
8 * edje_cc table.edc && gcc -o edje-table edje-table.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
19 #include <Ecore_Evas.h>
26 _on_delete(Ecore_Evas *ee __UNUSED__)
28 ecore_main_loop_quit();
31 /* Try to get the number of columns and rows of the table
34 _columns_rows_print(Evas_Object *edje_obj)
38 if (edje_object_part_table_col_row_size_get(edje_obj, "table_part", &cols,
40 fprintf(stdout, "Number of columns: %d\nNumber of rows: %d\n", cols, rows);
42 fprintf(stderr, "Cannot get the number of columns and rows\n");
45 /* here just to keep our example's window size and table items
46 * size in synchrony. */
48 _on_canvas_resize(Ecore_Evas *ee)
51 Evas_Object *edje_obj;
57 bg = ecore_evas_data_get(ee, "background");
58 edje_obj = ecore_evas_data_get(ee, "edje_obj");
59 rects = ecore_evas_data_get(ee, "rects");
60 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
62 evas_object_resize(bg, w, h);
63 evas_object_resize(edje_obj, w, h);
65 for (i = 0; i < 4; i++)
66 evas_object_size_hint_min_set(rects[i], w/2, h/2);
69 /* Mouse button 1 = remove the clicked item
70 * any other button = remove all items. */
72 _on_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
74 Evas_Event_Mouse_Down *ev;
75 Evas_Object *edje_obj;
77 ev = (Evas_Event_Mouse_Down *)event_info;
78 edje_obj = (Evas_Object *)data;
81 edje_object_part_table_clear(edje_obj, "table_part", EINA_TRUE);
82 else if (!edje_object_part_table_unpack(edje_obj, "table_part", obj))
83 fprintf(stderr, "Cannot remove the selected rectangle\n");
86 _columns_rows_print(edje_obj);
90 _rects_create(Evas *evas, Evas_Object **rects, Evas_Object *edje_obj)
94 for (i = 0; i < 4; i++)
96 rects[i] = evas_object_rectangle_add(evas);
97 evas_object_size_hint_min_set(rects[i], 200, 200);
98 evas_object_size_hint_weight_set(rects[i], 1.0, 1.0);
99 evas_object_show(rects[i]);
100 evas_object_event_callback_add(rects[i], EVAS_CALLBACK_MOUSE_DOWN,
101 _on_mouse_down, edje_obj);
106 main(int argc __UNUSED__, char *argv[])
108 char edje_file_path[PATH_MAX];
109 const char *edje_file = "table.edj";
113 Evas_Object *edje_obj;
114 Evas_Object *rects[4];
117 if (!ecore_evas_init())
121 goto shutdown_ecore_evas;
123 pfx = eina_prefix_new(argv[0], main,
134 /* this will give you a window with an Evas canvas under the first
135 * engine available */
136 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
140 ecore_evas_callback_delete_request_set(ee, _on_delete);
141 ecore_evas_callback_resize_set(ee, _on_canvas_resize);
142 ecore_evas_title_set(ee, "Edje Table Example");
144 evas = ecore_evas_get(ee);
146 bg = evas_object_rectangle_add(evas);
147 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
148 evas_object_move(bg, 0, 0); /* at canvas' origin */
149 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
150 evas_object_show(bg);
151 ecore_evas_data_set(ee, "background", bg);
153 edje_obj = edje_object_add(evas);
155 snprintf(edje_file_path, sizeof(edje_file_path),
156 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
157 edje_object_file_set(edje_obj, edje_file_path, "example_table");
158 evas_object_move(edje_obj, 0, 0); /* at canvas' origin */
159 evas_object_resize(edje_obj, WIDTH, HEIGHT);
160 evas_object_show(edje_obj);
161 ecore_evas_data_set(ee, "edje_obj", edje_obj);
163 _rects_create(evas, rects, edje_obj);
164 ecore_evas_data_set(ee, "rects", rects);
166 /* Colouring the rectangles */
167 evas_object_color_set(rects[0], 255, 0, 0, 255);
168 evas_object_color_set(rects[1], 0, 255, 0, 255);
169 evas_object_color_set(rects[2], 0, 0, 255, 255);
170 evas_object_color_set(rects[3], 128, 128, 128, 255);
172 /* Packing the rectangles into the table */
173 if (!edje_object_part_table_pack(edje_obj, "table_part", rects[0],
175 fprintf(stderr, "Cannot add the rectangle 1 to table\n");
177 if (!edje_object_part_table_pack(edje_obj, "table_part", rects[1],
179 fprintf(stderr, "Cannot add the rectangle 2 to table\n");
181 if (!edje_object_part_table_pack(edje_obj, "table_part", rects[2],
183 fprintf(stderr, "Cannot add the rectangle 3 to table\n");
185 if (!edje_object_part_table_pack(edje_obj, "table_part", rects[3],
187 fprintf(stderr, "Cannot add the rectangle 4 to table\n");
189 _columns_rows_print(edje_obj);
193 ecore_main_loop_begin();
195 eina_prefix_free(pfx);
197 ecore_evas_shutdown();
203 eina_prefix_free(pfx);
207 ecore_evas_shutdown();