In this example, we illustrate how to organize your objects on a table, using the edje_object_part_table functions.
To be easier to understand the objects in this example will be four simple rects, when the user click over one item with the left button its is removed from the table, if any other button was used all items are removed. For each action is printed a message with the current number of rows and columns.
We started creating an EDC file with one part of the type TABLE called "table_part", that is the part which we will refer to access the table:
collections {
group {
name: "example_table";
min: 50 50;
parts {
part {
name: "table_part";
type: TABLE;
description {
min: 50 50;
state: "default" 0.0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
}
}
}
}
}
On the other hand, in the C file we first create the rectangles and added a callback for mouse down, as you can see bellow:
{
int i;
for (i = 0; i < 4; i++)
{
_on_mouse_down, edje_obj);
}
}
With the objects created we have to pack them into the table, to do this, we just have to use the function edje_object_part_table_pack().
0, 0, 1, 2))
fprintf(stderr, "Cannot add the rectangle 1 to table\n");
0, 1, 1, 1))
fprintf(stderr, "Cannot add the rectangle 2 to table\n");
1, 0, 1, 1))
fprintf(stderr, "Cannot add the rectangle 3 to table\n");
1, 1, 1, 1))
fprintf(stderr, "Cannot add the rectangle 4 to table\n");
The other bit of code that is relevant to us now is our event handler for when the user click over the rectangle. Here we use the function edje_object_part_table_unpack() to remove the item from the table or edje_object_part_table_clear() to remove all items, it depends on which mouse button the user uses.
{
fprintf(stderr, "Cannot remove the selected rectangle\n");
_columns_rows_print(edje_obj);
}
Finally, the last important thing in this example is about how to know how many columns and rows are there in the table, It should be noted that this function don't tell you how many items are there in the table, just the number of the columns and rows of the table.
The example's window should look like this picture:
The full source code follows:
#ifdef HAVE_CONFIG_H
# include "config.h"
#else
# define EINA_UNUSED
#endif
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "."
#endif
#include <Ecore.h>
#define WIDTH (400)
#define HEIGHT (400)
static void
{
}
static void
{
int cols, rows;
&rows))
printf("Number of columns: %d\nNumber of rows: %d\n", cols, rows);
else
fprintf(stderr, "Cannot get the number of columns and rows\n");
}
static void
_on_canvas_resize(Ecore_Evas *ee)
{
int i;
int w;
int h;
for (i = 0; i < 4; i++)
}
static void
{
fprintf(stderr, "Cannot remove the selected rectangle\n");
_columns_rows_print(edje_obj);
}
static void
{
int i;
for (i = 0; i < 4; i++)
{
_on_mouse_down, edje_obj);
}
}
int
{
const char *edje_file = PACKAGE_DATA_DIR"/table.edj";
Ecore_Evas *ee;
return EXIT_FAILURE;
goto shutdown_ecore_evas;
if (!ee) goto shutdown_edje;
_rects_create(evas, rects, edje_obj);
0, 0, 1, 2))
fprintf(stderr, "Cannot add the rectangle 1 to table\n");
0, 1, 1, 1))
fprintf(stderr, "Cannot add the rectangle 2 to table\n");
1, 0, 1, 1))
fprintf(stderr, "Cannot add the rectangle 3 to table\n");
1, 1, 1, 1))
fprintf(stderr, "Cannot add the rectangle 4 to table\n");
_columns_rows_print(edje_obj);
return EXIT_SUCCESS;
shutdown_edje:
shutdown_ecore_evas:
return EXIT_FAILURE;
}
To compile use this command:
* gcc -o edje-table edje-table.c -DPACKAGE_BIN_DIR=\"/Where/enlightenment/is/installed/bin\" -DPACKAGE_LIB_DIR=\"/Where/enlightenment/is/installed/lib\"
* -DPACKAGE_DATA_DIR=\"/Where/enlightenment/is/installed/share\"
* `pkg-config --cflags --libs evas ecore ecore-evas edje`
*
* edje_cc table.edc
*