Edje

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

Edje

Edje Graphical Design Library.

These routines are used for Edje.

Date
  2003 (created)

# Table of Contents

- Introduction
- So how does this all work?
- How to compile
- Next Steps
- Introductory Example

# Introduction

Edje is a complex graphical design & layout library.

It doesn't intend to do containing and regular layout like a widget set, but it is the base for such components. Based on the requirements of Enlightenment 0.17, Edje should serve all the purposes of creating visual elements (borders of windows, buttons, scrollbars, etc.) and allow the designer the ability to animate, layout and control the look and feel of any program using Edje as its basic GUI constructor. This library allows for multiple collections of Layouts in one file, sharing the same image and font database and thus allowing a whole theme to be conveniently packaged into 1 file and shipped around.

Edje separates the layout and behavior logic. Edje files ship with an image and font database, used by all the parts in all the collections to source graphical data. It has a directory of logical part names pointing to the part collection entry ID in the file (thus allowing for multiple logical names to point to the same part collection, allowing for the sharing of data between display elements). Each part collection consists of a list of visual parts, as well as a list of programs. A program is a conditionally run program that if a particular event occurs (a button is pressed, a mouse enters or leaves a part) will trigger an action that may affect other parts. In this way a part collection can be "programmed" via its file as to highlight buttons when the mouse passes over them or show hidden parts when a button is clicked somewhere etc. The actions performed in changing from one state to another are also allowed to transition over a period of time, allowing animation. Programs and animations can be run in "parallel".

This separation and simplistic event driven style of programming can produce almost any look and feel one could want for basic visual elements. Anything more complex is likely the domain of an application or widget set that may use Edje as a convenient way of being able to configure parts of the display.

For details of Edje's history, see the Edje History section.

## So how does this all work?

Edje internally holds a geometry state machine and state graph of what is visible, not, where, at what size, with what colors etc. This is described to Edje from an Edje .edj file containing this information. These files can be produced by using edje_cc to take a text file (a .edc file) and "compile" an output .edj file that contains this information, images and any other data needed.

The application using Edje will then create an object in its Evas canvas and set the bundle file to use, specifying the group name to use. Edje will load such information and create all the required children objects with the specified properties as defined in each part of the given group. See the example at Introductory Example.

Although simple, this example illustrates that animations and state changes can be done from the Edje file itself without any requirement in the C application.

Before digging into changing or creating your own Edje source (edc) files, read the Edje Data Collection reference.

## Edje History

It's a sequel to "Ebits" which has serviced the needs of Enlightenment development for early version 0.17. The original design parameters under which Ebits came about were a lot more restricted than the resulting use of them, thus Edje was born.

Edje is a more complex layout engine compared to Ebits. It doesn't pretend to do containing and regular layout like a widget set. It still inherits the more simplistic layout ideas behind Ebits, but it now does them a lot more cleanly, allowing for easy expansion, and the ability to cover much more ground than Ebits ever could. For the purposes of Enlightenment 0.17, Edje was conceived to serve all the purposes of creating visual elements (borders of windows, buttons, scrollbars, etc.) and allow the designer the ability to animate, layout and control the look and feel of any program using Edje as its basic GUI constructor.

Unlike Ebits, Edje separates the layout and behavior logic.

# How to compile

Edje is a library your application links to. The procedure for this is very simple. You simply have to compile your application with the appropriate compiler flags that the `pkg-config` script outputs. For example:

Compiling C or C++ files into object files:

    gcc -c -o main.o main.c `pkg-config --cflags edje`

Linking object files into a binary executable:

    gcc -o my_application main.o `pkg-config --libs edje`

See pkgconfig

# Next Steps

After you understood what Edje is and installed it in your system you should proceed understanding the programming interface for all objects, then see the specific for the most used elements. We'd recommend you to take a while to learn Ecore, Evas, Eo and Eina as they are the building blocks for Edje. There is a widget set built on top of Edje providing high level elements such as buttons, lists and selectors called Elementary (http://docs.enlightenment.org/auto/elementary/) as they will likely save you tons of work compared to using just Evas directly.

Recommended reading:

- Edje Data Collection reference
- Edje General
- Edje Object
- Edje External
- Edje Lua scripting

# Introductory Example

What follows is a list with various commented examples, covering a great part of Edje's API:

//Compile with:
// edje_cc edje_example.edc && gcc -o edje_example edje_example.c `pkg-config --libs --cflags eina ecore evas ecore-evas edje`
#include <Eina.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "."
#endif
#define WIDTH 320
#define HEIGHT 240
static Evas_Object *create_my_group(Evas *canvas, const char *text)
{
Evas_Object *edje;
edje = edje_object_add(canvas);
if (!edje)
{
EINA_LOG_CRIT("could not create edje object!");
return NULL;
}
if (!edje_object_file_set(edje, PACKAGE_DATA_DIR"/edje_example.edj",
"my_group"))
{
int err = edje_object_load_error_get(edje);
const char *errmsg = edje_load_error_str(err);
EINA_LOG_ERR("could not load 'my_group' from edje_example.edj: %s",
errmsg);
evas_object_del(edje);
return NULL;
}
if (text)
{
if (!edje_object_part_text_set(edje, "text", text))
{
EINA_LOG_WARN("could not set the text. "
"Maybe part 'text' does not exist?");
}
}
evas_object_move(edje, 0, 0);
evas_object_resize(edje, WIDTH, HEIGHT);
evas_object_show(edje);
return edje;
}
int main(int argc, char *argv[])
{
Ecore_Evas *window;
Evas *canvas;
Evas_Object *edje;
const char *text;
ecore_evas_init();
edje_init();
window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
if (!window)
{
EINA_LOG_CRIT("could not create window.");
return -1;
}
canvas = ecore_evas_get(window);
text = (argc > 1) ? argv[1] : NULL;
edje = create_my_group(canvas, text);
if (!edje)
return -2;
ecore_evas_show(window);
ecore_main_loop_begin();
evas_object_del(edje);
ecore_evas_free(window);
edje_shutdown();
ecore_evas_shutdown();
return 0;
}
Ecore_Evas.h
Evas wrapper functions.
Edje.h
Edje Graphical Design Library.
Eina.h
Eina Utility library.
ecore_evas_init
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:602
ecore_evas_show
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1480
ecore_evas_get
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1300
ecore_evas_new
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition: ecore_evas.c:1039
ecore_evas_shutdown
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:666
ecore_evas_free
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1083
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
edje_shutdown
int edje_shutdown(void)
Shuts down the Edje library.
Definition: edje_main.c:262
edje_init
int edje_init(void)
Initializes the Edje library.
Definition: edje_main.c:35
edje_object_load_error_get
Edje_Load_Error edje_object_load_error_get(const Eo *obj)
Gets the (last) file loading error for a given Edje object.
Definition: edje_legacy.c:15
edje_object_add
Evas_Object * edje_object_add(Evas *evas)
Instantiates a new Edje object.
Definition: edje_smart.c:22
edje_load_error_str
const char * edje_load_error_str(Edje_Load_Error error)
Converts the given Edje file load error code into a string describing it in English.
Definition: edje_load.c:108
edje_object_file_set
Eina_Bool edje_object_file_set(Evas_Object *obj, const char *file, const char *group)
Sets the EDJ file (and group within it) to load an Edje object's contents from.
Definition: edje_smart.c:467
edje_object_part_text_set
Eina_Bool edje_object_part_text_set(const Evas_Object *obj, const char *part, const char *text)
Sets a given text to an Edje object TEXT or TEXTBLOCK parts.
Definition: edje_util.c:6723
EINA_LOG_WARN
#define EINA_LOG_WARN(fmt,...)
Logs a message with level WARN on the default domain with the specified format.
Definition: eina_log.h:392
EINA_LOG_ERR
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition: eina_log.h:376
EINA_LOG_CRIT
#define EINA_LOG_CRIT(fmt,...)
Logs a message with level CRITICAL on the default domain with the specified format.
Definition: eina_log.h:365
Evas
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_del
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition: evas_object_main.c:928
evas_object_move
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236

The above example requires the following annotated source Edje file:

// compile: edje_cc edje_example.edc
collections {
group {
name: "my_group"; // must be the same as in edje_example.c
parts {
part {
name: "background";
type: RECT; // plain boring rectangle
mouse_events: 0; // we don't need any mouse event on the background
// just one state "default"
description {
state: "default" 0.0; // must always exist
color: 255 255 255 255; // white
// define part coordinates:
rel1 { // top-left point at (0, 0) [WIDTH * 0 + 0, HEIGHT * 0 + 0]
relative: 0.0 0.0;
offset: 0 0;
}
rel2 { // bottom-right point at (WIDTH * 1.0 - 1, HEIGHT * 1.0 - 1)
relative: 1.0 1.0;
offset: -1 -1;
}
}
}
part {
name: "text";
type: TEXT;
mouse_events: 1; // we want to change the color on mouse-over
// 2 states, one "default" and another "over" to be used
// on mouse over effect
description {
state: "default" 0.0;
color: 255 0 0 255; // red
// define part coordinates:
rel1 { // top-left at (WIDTH * 0.1 + 5, HEIGHT * 0.2 + 10)
relative: 0.1 0.2;
offset: 5 10;
}
rel2 { // bottom-right at (WIDTH * 0.9 - 6, HEIGHT * 0.8 - 11)
relative: 0.9 0.8;
offset: -6 -11;
}
// define text specific state details
text {
font: "Sans"; // using fontconfig name!
size: 10;
text: "hello world";
}
}
description {
state: "over" 0.0;
inherit: "default" 0.0; // copy everything from "default" at this point
color: 0 255 0 255; // override color, now it is green
}
}
// do programs to change color on text mouse in/out (over)
programs {
program {
// what triggers this program:
signal: "mouse,in";
source: "text";
// what this program does:
action: STATE_SET "over" 0.0;
target: "text";
// do the state-set in a nice interpolation animation
// using linear time in 0.1 second
transition: LINEAR 0.1;
}
program {
// what triggers this program:
signal: "mouse,out";
source: "text";
// what this program does:
action: STATE_SET "default" 0.0;
target: "text";
// do the state-set in a nice interpolation animation
// using linear time in 0.1 second
transition: LINEAR 0.1;
}
}
}
}
}

More examples can be found at Edje Examples.