edje: Edje_Edit - add examples for it's API using for BOX part and items
Summary: Some little example about how and when edje_edit functions can be applied. In this example there is a box part with items in edj, and by using edje_edit program actually changes edj file directly. (adding items, changing layouts of box, changing params of items, etc). It is pushed as a reference for people who would like to do there own Edje editor. Normal application should not use that API. Reviewers: Hermet, raster, seoz, cedric Reviewed By: cedric Subscribers: cedric, reutskiy.v.v Differential Revision: https://phab.enlightenment.org/D1969 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
14e65920ff
commit
bd2304cf3b
|
@ -43,7 +43,8 @@ sigtest.edc \
|
|||
swallow.edc \
|
||||
table.edc \
|
||||
text.edc \
|
||||
toggle_using_filter.edc
|
||||
toggle_using_filter.edc \
|
||||
box_example.edc
|
||||
|
||||
DIST_EDCS = $(EDCS)
|
||||
|
||||
|
@ -99,7 +100,8 @@ animations2.c \
|
|||
edje-basic2.c \
|
||||
signals2.c \
|
||||
edje-swallow2.c \
|
||||
edje-multisense.c
|
||||
edje-multisense.c \
|
||||
edje-edit-part-box.c
|
||||
|
||||
EXTRA_DIST = $(DIST_EDCS) $(DATA_FILES)
|
||||
|
||||
|
@ -167,7 +169,8 @@ sigtest \
|
|||
animations2 \
|
||||
edje-basic2 \
|
||||
signals2 \
|
||||
edje-swallow2
|
||||
edje-swallow2 \
|
||||
edje-edit-part-box
|
||||
|
||||
if ENABLE_MULTISENSE
|
||||
EXTRA_PROGRAMS += edje-multisense
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
collections {
|
||||
images {
|
||||
image: "bubble-blue.png" COMP;
|
||||
}
|
||||
group { name: "red_group";
|
||||
parts {
|
||||
part { name: "red";
|
||||
type: RECT;
|
||||
description { state: "default" 0.0;
|
||||
color: 255 0 0 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
group { name: "blue_group";
|
||||
parts {
|
||||
part { name: "blue";
|
||||
type: RECT;
|
||||
description { state: "default" 0.0;
|
||||
color: 0 0 255 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
group { name: "green_group";
|
||||
parts {
|
||||
part { name: "green";
|
||||
type: RECT;
|
||||
description { state: "default" 0.0;
|
||||
color: 0 255 0 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
group { name: "complex_group";
|
||||
parts {
|
||||
part { name: "green";
|
||||
type: RECT;
|
||||
description { state: "default" 0.0;
|
||||
color: 255 0 255 255;
|
||||
}
|
||||
}
|
||||
part {
|
||||
type: IMAGE;
|
||||
name: "bg";
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
image {
|
||||
normal: "bubble-blue.png";
|
||||
}
|
||||
rel1.relative: 0.25 0.25;
|
||||
rel2.relative: 0.75 0.75;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "box_group";
|
||||
parts {
|
||||
part { name: "bg";
|
||||
type: RECT;
|
||||
description { state: "default" 0.0;
|
||||
visible: 1;
|
||||
color: 0 0 0 255;
|
||||
}
|
||||
}
|
||||
part { name: "green";
|
||||
type: BOX;
|
||||
box {
|
||||
items {
|
||||
item {
|
||||
type: GROUP;
|
||||
name: "x1";
|
||||
source: "red_group";
|
||||
min: 100 100;
|
||||
max: 200 200;
|
||||
align: 0 0;
|
||||
weight: 20 10;
|
||||
}
|
||||
item {
|
||||
type: GROUP;
|
||||
name: "x2";
|
||||
source: "blue_group";
|
||||
min: 200 200;
|
||||
max: 800 800;
|
||||
}
|
||||
item {
|
||||
type: GROUP;
|
||||
name: "x3";
|
||||
source: "green_group";
|
||||
min: 20 20;
|
||||
max: 100 100;
|
||||
align: 0.3 0.7;
|
||||
weight: 5 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
description { state: "default" 0.0;
|
||||
visible: 1;
|
||||
color: 255 255 255 255;
|
||||
box {
|
||||
layout: "horizontal";
|
||||
padding: 5 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,379 @@
|
|||
/**
|
||||
* Simple Edje Edit example illustrating BOX part's and it's items editing.
|
||||
*
|
||||
* This example is intended for people who want to write an Edje editor. There
|
||||
* is no other application that should use it, EVER ! If you don't plan to write
|
||||
* an Edje editor please move away from this file.
|
||||
*
|
||||
* See stdout/stderr for output.
|
||||
*
|
||||
* @verbatim
|
||||
* edje_cc box_example.edc && gcc -o edje-edit-part-box edje-edit-part-box.c `pkg-config --libs --cflags evas ecore ecore-evas edje eina`
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#else
|
||||
# define EINA_UNUSED
|
||||
#endif
|
||||
|
||||
#ifndef PACKAGE_DATA_DIR
|
||||
#define PACKAGE_DATA_DIR "."
|
||||
#endif
|
||||
|
||||
#define EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Evas.h>
|
||||
#include <Edje_Edit.h>
|
||||
#include <Edje.h>
|
||||
|
||||
#define WIDTH (500)
|
||||
#define HEIGHT (300)
|
||||
|
||||
static const char commands[] = \
|
||||
"commands are:\n"
|
||||
"\tl - change box layout\n"
|
||||
"\tL - change box alternative layout\n"
|
||||
"\ti - append one/remove item\n"
|
||||
"\tg - change source of middle item\n"
|
||||
"\tM - change max of middle item\n"
|
||||
"\tm - change min of middle item\n"
|
||||
"\ts - change spread (w and h) of middle item\n"
|
||||
"\tb - change paddings of middle item\n"
|
||||
"\tw - change weight of middle item\n"
|
||||
"\tn - change align of middle item\n"
|
||||
"\tp - print resulted source code of edj file (after changing with edje edit)\n"
|
||||
"\th - print help\n"
|
||||
"\tEsc - exit\n";
|
||||
|
||||
static int group_number = 0;
|
||||
static const char *groups[] =
|
||||
{
|
||||
"blue_group", "red_group", "green_group", "complex_group"
|
||||
};
|
||||
|
||||
static int layout_number = 0;
|
||||
static int alt_layout_number = 0;
|
||||
static char *layouts[] =
|
||||
{
|
||||
"horizontal", "vertical", "horizontal_homogeneous", "vertical_homogeneous",
|
||||
"horizontal_max", "vertical_max", "horizontal_flow", "vertical_flow", "stack",
|
||||
NULL
|
||||
};
|
||||
|
||||
static void
|
||||
_on_delete(Ecore_Evas *ee EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_on_bg_key_down(void *data EINA_UNUSED,
|
||||
Evas *e EINA_UNUSED,
|
||||
Evas_Object *o,
|
||||
void *event_info)
|
||||
{
|
||||
const char *edje_file = PACKAGE_DATA_DIR"/box_example.edj";
|
||||
Evas_Event_Key_Down *ev;
|
||||
Evas_Object *edje_edit_obj = o;
|
||||
|
||||
ev = (Evas_Event_Key_Down *)event_info;
|
||||
|
||||
if (!strcmp(ev->key, "h"))
|
||||
{
|
||||
fprintf(stdout, commands);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "p"))
|
||||
{
|
||||
fprintf(stdout, "SOURCE CODE:\n%s \n", edje_edit_source_generate(edje_edit_obj));
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "n"))
|
||||
{
|
||||
double align_x = edje_edit_part_item_align_x_get(edje_edit_obj, "green", "x2");
|
||||
double align_y = edje_edit_part_item_align_y_get(edje_edit_obj, "green", "x2");
|
||||
|
||||
align_x += 0.1; align_y += 0.2;
|
||||
if (align_x >= 1.0) align_x = 0.0;
|
||||
if (align_y >= 1.0) align_y = 0.0;
|
||||
|
||||
fprintf(stdout, "Changing align to x[%f] y[%f] \n", align_x, align_y);
|
||||
|
||||
if (!edje_edit_part_item_align_x_set(edje_edit_obj, "green", "x2", align_x))
|
||||
fprintf(stderr, "Couldn't set align x for item x2, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_align_y_set(edje_edit_obj, "green", "x2", align_y))
|
||||
fprintf(stderr, "Couldn't set align y for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "w"))
|
||||
{
|
||||
double weight_x = edje_edit_part_item_weight_x_get(edje_edit_obj, "green", "x2");
|
||||
double weight_y = edje_edit_part_item_weight_y_get(edje_edit_obj, "green", "x2");
|
||||
|
||||
weight_x += 5.0; weight_y += 10.0;
|
||||
if (weight_x >= 30.0) weight_x = 0.0;
|
||||
if (weight_y >= 30.0) weight_y = 0.0;
|
||||
|
||||
fprintf(stdout, "Changing weight to x[%f] y[%f] \n", weight_x, weight_y);
|
||||
|
||||
if (!edje_edit_part_item_weight_x_set(edje_edit_obj, "green", "x2", weight_x))
|
||||
fprintf(stderr, "Couldn't set weight x for item x2, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_weight_y_set(edje_edit_obj, "green", "x2", weight_y))
|
||||
fprintf(stderr, "Couldn't set weight y for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "b"))
|
||||
{
|
||||
Evas_Coord l, r, t, b;
|
||||
edje_edit_part_item_padding_get(edje_edit_obj, "green", "x2", &l, &r, &t, &b);
|
||||
|
||||
l += 1; r += 2; t += 4; b += 8;
|
||||
if (l >= 32) l = 0;
|
||||
if (r >= 32) r = 0;
|
||||
if (t >= 32) t = 0;
|
||||
if (b >= 32) b = 0;
|
||||
|
||||
fprintf(stdout, "Changing paddings. left[%d], right[%d], top[%d], bottom[%d]\n", l, r, t, b);
|
||||
|
||||
if (!edje_edit_part_item_padding_set(edje_edit_obj, "green", "x2", l, r, t, b))
|
||||
fprintf(stderr, "Couldn't set paddings for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "s"))
|
||||
{
|
||||
/* numbder of spread item is (spread_w * spread_h) */
|
||||
int spread_w = edje_edit_part_item_spread_w_get(edje_edit_obj, "green", "x2");
|
||||
int spread_h = edje_edit_part_item_spread_h_get(edje_edit_obj, "green", "x2");
|
||||
|
||||
spread_w++;
|
||||
if (spread_w >= 5)
|
||||
{
|
||||
spread_w = 1;
|
||||
spread_h++;
|
||||
if (spread_h >= 5)
|
||||
spread_h = 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Changing spread to w[%d] h[%d] \n", spread_w, spread_h);
|
||||
|
||||
if (!edje_edit_part_item_spread_w_set(edje_edit_obj, "green", "x2", spread_w))
|
||||
fprintf(stderr, "Couldn't set spread w for item x2, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_spread_h_set(edje_edit_obj, "green", "x2", spread_h))
|
||||
fprintf(stderr, "Couldn't set spread h for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "m"))
|
||||
{
|
||||
int min_w = edje_edit_part_item_min_w_get(edje_edit_obj, "green", "x2");
|
||||
int min_h = edje_edit_part_item_min_h_get(edje_edit_obj, "green", "x2");
|
||||
|
||||
min_w += 100; min_h += 100;
|
||||
if (min_w >= 500) min_w = 200;
|
||||
if (min_h >= 500) min_h = 200;
|
||||
|
||||
fprintf(stdout, "Changing min to w[%d] h[%d] \n", min_w, min_h);
|
||||
|
||||
if (!edje_edit_part_item_min_w_set(edje_edit_obj, "green", "x2", min_w))
|
||||
fprintf(stderr, "Couldn't set min w for item x2, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_min_h_set(edje_edit_obj, "green", "x2", min_h))
|
||||
fprintf(stderr, "Couldn't set min h for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "M"))
|
||||
{
|
||||
int max_w = edje_edit_part_item_max_w_get(edje_edit_obj, "green", "x2");
|
||||
int max_h = edje_edit_part_item_max_h_get(edje_edit_obj, "green", "x2");
|
||||
|
||||
max_w -= 100; max_h -= 100;
|
||||
if (max_w <= 0) max_w = 800;
|
||||
if (max_h <= 0) max_h = 800;
|
||||
|
||||
fprintf(stdout, "Changing max to w[%d] h[%d] \n", max_w, max_h);
|
||||
|
||||
if (!edje_edit_part_item_max_w_set(edje_edit_obj, "green", "x2", max_w))
|
||||
fprintf(stderr, "Couldn't set max w for item x2, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_max_h_set(edje_edit_obj, "green", "x2", max_h))
|
||||
fprintf(stderr, "Couldn't set max h for item x2, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "g"))
|
||||
{
|
||||
Eina_Stringshare *source = edje_edit_part_item_source_get(edje_edit_obj, "green", "x2");
|
||||
const char *new_source = NULL;
|
||||
|
||||
group_number++;
|
||||
if (group_number > 3)
|
||||
group_number = 0;
|
||||
new_source = groups[group_number];
|
||||
|
||||
fprintf(stdout, "Changing item's source from [%s] to [%s] \n", source, new_source);
|
||||
|
||||
if (!edje_edit_part_item_source_set(edje_edit_obj, "green", "x2", new_source))
|
||||
fprintf(stderr, "Couldn't change item's source, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
eina_stringshare_del(source);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "i"))
|
||||
{
|
||||
if (!edje_edit_part_item_append(edje_edit_obj, "green", "x_new", "complex_group"))
|
||||
{
|
||||
edje_edit_part_item_del(edje_edit_obj, "green", "x_new");
|
||||
fprintf(stdout, "Successfully removed new item!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!edje_edit_part_item_min_w_set(edje_edit_obj, "green", "x_new", 200))
|
||||
fprintf(stderr, "Couldn't set min w for item x_new, something is absolutely wrong!!!\n");
|
||||
if (!edje_edit_part_item_min_h_set(edje_edit_obj, "green", "x_new", 200))
|
||||
fprintf(stderr, "Couldn't set min h for item x_new, something is absolutely wrong!!!\n");
|
||||
fprintf(stdout, "Successfully added new item!\n");
|
||||
}
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "l"))
|
||||
{
|
||||
Eina_Stringshare *layout = edje_edit_state_box_layout_get(edje_edit_obj, "green", "default", 0.0);
|
||||
char *new_layout = NULL;
|
||||
|
||||
layout_number++;
|
||||
if (layout_number > 9)
|
||||
layout_number = 0;
|
||||
new_layout = layouts[layout_number];
|
||||
|
||||
fprintf(stdout, "Changing box's layout from [%s] to [%s] \n", layout, new_layout);
|
||||
|
||||
if (!edje_edit_state_box_layout_set(edje_edit_obj, "green", "default", 0.0, new_layout))
|
||||
fprintf(stderr, "Couldn't change layout, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
eina_stringshare_del(layout);
|
||||
return;
|
||||
}
|
||||
if (!strcmp(ev->key, "L"))
|
||||
{
|
||||
Eina_Stringshare *layout = edje_edit_state_box_alt_layout_get(edje_edit_obj, "green", "default", 0.0);
|
||||
char *new_layout = NULL;
|
||||
|
||||
alt_layout_number++;
|
||||
if (alt_layout_number > 9)
|
||||
alt_layout_number = 0;
|
||||
new_layout = layouts[alt_layout_number];
|
||||
|
||||
fprintf(stdout, "Changing box's alternative layout from [%s] to [%s] \n", layout, new_layout);
|
||||
|
||||
if (!edje_edit_state_box_alt_layout_set(edje_edit_obj, "green", "default", 0.0, new_layout))
|
||||
fprintf(stderr, "Couldn't change alternative layout, something is absolutely wrong!!!\n");
|
||||
|
||||
edje_edit_save_all(edje_edit_obj);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
eina_stringshare_del(layout);
|
||||
return;
|
||||
}
|
||||
else if (!strcmp(ev->key, "Escape"))
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
|
||||
{
|
||||
const char *edje_file = PACKAGE_DATA_DIR"/box_example.edj";
|
||||
Ecore_Evas *ee;
|
||||
Evas *evas;
|
||||
Evas_Object *edje_edit_obj;
|
||||
|
||||
if (!ecore_evas_init())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!edje_init())
|
||||
goto shutdown_ecore_evas;
|
||||
|
||||
/* this will give you a window with an Evas canvas under the first
|
||||
* engine available */
|
||||
ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
|
||||
if (!ee) goto shutdown_edje;
|
||||
|
||||
ecore_evas_callback_delete_request_set(ee, _on_delete);
|
||||
|
||||
ecore_evas_title_set(ee, "Edje Edit Example: BOX part");
|
||||
|
||||
evas = ecore_evas_get(ee);
|
||||
|
||||
/* loading edje edit object here */
|
||||
edje_edit_obj = edje_edit_object_add(evas);
|
||||
if (!edje_object_file_set(edje_edit_obj, edje_file, "box_group"))
|
||||
fprintf(stdout, "Couldn't load edje edit object! \n");
|
||||
|
||||
evas_object_resize(edje_edit_obj, WIDTH, HEIGHT);
|
||||
evas_object_show(edje_edit_obj);
|
||||
|
||||
ecore_evas_data_set(ee, "background", edje_edit_obj);
|
||||
ecore_evas_object_associate(ee, edje_edit_obj, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
|
||||
evas_object_focus_set(edje_edit_obj, EINA_TRUE);
|
||||
evas_object_event_callback_add(edje_edit_obj, EVAS_CALLBACK_KEY_DOWN, _on_bg_key_down, ee);
|
||||
|
||||
fprintf(stdout, commands);
|
||||
|
||||
ecore_evas_show(ee);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_evas_free(ee);
|
||||
ecore_evas_shutdown();
|
||||
edje_shutdown();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
shutdown_edje:
|
||||
edje_shutdown();
|
||||
shutdown_ecore_evas:
|
||||
ecore_evas_shutdown();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
Loading…
Reference in New Issue