Edje Graphical Design Library

These routines are used for Edje.

\begin{DoxyDate}{Date}
2003 (created)
\end{DoxyDate}
\hypertarget{eina_cxx_main_toc}{}\section{Table of Contents}\label{eina_cxx_main_toc}
\begin{DoxyItemize}
\item \hyperlink{edje_main_edje_main_intro}{Introduction} \item \hyperlink{edje_main_edje_main_work}{So how does this all work?} \item \hyperlink{edje_main_edje_main_compiling}{How to compile} \item \hyperlink{edje_main_edje_main_next_steps}{Next Steps} \item \hyperlink{edje_main_edje_main_intro_example}{Introductory Example}\end{DoxyItemize}
\hypertarget{edje_main_edje_main_intro}{}\section{Introduction}\label{edje_main_edje_main_intro}
Edje is a complex graphical design \& layout library.

It doesn\textquotesingle{}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 G\+UI 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 \char`\"{}programmed\char`\"{} via its file as to hilight 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 \char`\"{}parallel\char`\"{}.

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\textquotesingle{}s history, see the \hyperlink{edje_main_edje_history}{Edje History} section.\hypertarget{edje_main_edje_main_work}{}\subsection{So how does this all work?}\label{edje_main_edje_main_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 \char`\"{}compile\char`\"{} 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 {\bfseries group} name to use. Edje will load such information and create all the required children objects with the specified properties as defined in each {\bfseries part} of the given group. See the example at \hyperlink{edje_main_edje_main_intro_example}{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 \hyperlink{edcref}{Edje Data Collection reference}.\hypertarget{edje_main_edje_history}{}\subsection{Edje History}\label{edje_main_edje_history}
It\textquotesingle{}s a sequel to \char`\"{}\+Ebits\char`\"{} 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\textquotesingle{}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 G\+UI constructor.

Unlike Ebits, Edje separates the layout and behavior logic.\hypertarget{edje_main_edje_main_compiling}{}\section{How to compile}\label{edje_main_edje_main_compiling}
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 {\ttfamily pkg-\/config} script outputs. For example\+:

Compiling C or C++ files into object files\+:

\begin{DoxyVerb}gcc -c -o main.o main.c `pkg-config --cflags edje`
\end{DoxyVerb}


Linking object files into a binary executable\+:

\begin{DoxyVerb}gcc -o my_application main.o `pkg-config --libs edje`
\end{DoxyVerb}


See \hyperlink{pkgconfig}{pkgconfig}\hypertarget{edje_main_edje_main_next_steps}{}\section{Next Steps}\label{edje_main_edje_main_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\textquotesingle{}d recommend you to take a while to learn \hyperlink{group__Ecore}{Ecore}, \hyperlink{group__Evas}{Evas}, \hyperlink{group__Eo}{Eo} and \hyperlink{group__Eina}{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 (\href{http://docs.enlightenment.org/auto/elementary/}{\tt http\+://docs.\+enlightenment.\+org/auto/elementary/}) as they will likely save you tons of work compared to using just Evas directly.

Recommended reading\+: \begin{DoxyItemize}
\item \hyperlink{edcref}{Edje Data Collection reference} \item \hyperlink{group__Edje__General__Group}{Edje General} \item \hyperlink{group__Edje__Object__Group}{Edje Object} \item \hyperlink{group__Edje__External__Group}{Edje External} \item \hyperlink{luaref}{Edje Lua scripting}\end{DoxyItemize}
\hypertarget{edje_main_edje_main_intro_example}{}\section{Introductory Example}\label{edje_main_edje_main_intro_example}
What follows is a list with various commented examples, covering a great part of Edje\textquotesingle{}s A\+PI\+:


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// edje\_cc edje\_example.edc && gcc -o edje\_example edje\_example.c `pkg-config --libs --cflags ecore
       ecore-evas edje`}

\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}
\textcolor{preprocessor}{#include <Evas.h>}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}>}
\textcolor{preprocessor}{#include <\hyperlink{Edje_8h}{Edje.h}>}

\textcolor{preprocessor}{#ifndef PACKAGE\_DATA\_DIR}
\textcolor{preprocessor}{#define PACKAGE\_DATA\_DIR "."}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#define WIDTH 320}
\textcolor{preprocessor}{#define HEIGHT 240}

\textcolor{keyword}{static} \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *create\_my\_group(\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *text)
\{
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje;

   edje = edje\_object\_add(canvas);
   \textcolor{keywordflow}{if} (!edje)
     \{
        \hyperlink{group__Eina__Log__Group_ga5b50827f35399f9ff87f5d9d817c764a}{EINA\_LOG\_CRIT}(\textcolor{stringliteral}{"could not create edje object!"});
        \textcolor{keywordflow}{return} NULL;
     \}

   \textcolor{keywordflow}{if} (!edje\_object\_file\_set(edje, PACKAGE\_DATA\_DIR\textcolor{stringliteral}{"/edje\_example.edj"},
                             \textcolor{stringliteral}{"my\_group"}))
     \{
        \textcolor{keywordtype}{int} err = edje\_object\_load\_error\_get(edje);
        \textcolor{keyword}{const} \textcolor{keywordtype}{char} *errmsg = \hyperlink{group__Edje__Object__File_ga034465c2de4ab495802da20f332c386e}{edje\_load\_error\_str}(err);
        \hyperlink{group__Eina__Log__Group_ga2e33caeeeb6051526c01b7fea4d6c91b}{EINA\_LOG\_ERR}(\textcolor{stringliteral}{"could not load 'my\_group' from edje\_example.edj: %s"},
                     errmsg);

        \hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}(edje);
        \textcolor{keywordflow}{return} NULL;
     \}

   \textcolor{keywordflow}{if} (text)
     \{
        \textcolor{keywordflow}{if} (!edje\_object\_part\_text\_set(edje, \textcolor{stringliteral}{"text"}, text))
          \{
             \hyperlink{group__Eina__Log__Group_ga21c44f66537533db16ee8f475ae2ae70}{EINA\_LOG\_WARN}(\textcolor{stringliteral}{"could not set the text. "}
                           \textcolor{stringliteral}{"Maybe part 'text' does not exist?"});
          \}
     \}

   \hyperlink{group__Evas__Font__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}(edje, 0, 0);
   \hyperlink{group__Evas__Font__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}(edje, WIDTH, HEIGHT);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(edje);
   \textcolor{keywordflow}{return} edje;
\}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} *argv[])
\{
   Ecore\_Evas *window;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *edje;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *text;

   \hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}();
   \hyperlink{group__Edje__General__Group_ga1c9c6594f38023c29fbfb2d0c8c675db}{edje\_init}();

   window = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   \textcolor{keywordflow}{if} (!window)
     \{
        \hyperlink{group__Eina__Log__Group_ga5b50827f35399f9ff87f5d9d817c764a}{EINA\_LOG\_CRIT}(\textcolor{stringliteral}{"could not create window."});
        \textcolor{keywordflow}{return} -1;
     \}
   canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(window);

   text = (argc > 1) ? argv[1] : NULL;

   edje = create\_my\_group(canvas, text);
   \textcolor{keywordflow}{if} (!edje)
     \textcolor{keywordflow}{return} -2;

   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(window);
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}(edje);
   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(window);

   \hyperlink{group__Edje__General__Group_ga01041f6702f2d81bf10c3e41899805cb}{edje\_shutdown}();
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}
\end{DoxyCodeInclude}


The above example requires the following annotated source Edje file\+: 
\begin{DoxyCodeInclude}
1 // compile: edje\_cc edje\_example.edc
2 collections \{
3    group \{
4       name: "my\_group"; // must be the same as in edje\_example.c
5 
6       parts \{
7          part \{
8             name: "background";
9             type: RECT; // plain boring rectangle
10             mouse\_events: 0; // we don't need any mouse event on the background
11 
12             // just one state "default"
13             description \{
14                state: "default" 0.0; // must always exist
15                color: 255 255 255 255; // white
16 
17                // define part coordinates:
18 
19                rel1 \{ // top-left point at (0, 0) [WIDTH * 0 + 0, HEIGHT * 0 + 0]
20                   relative: 0.0 0.0;
21                   offset: 0 0;
22                \}
23                rel2 \{ // bottom-right point at (WIDTH * 1.0 - 1, HEIGHT * 1.0 - 1)
24                   relative: 1.0 1.0;
25                   offset: -1 -1;
26                \}
27             \}
28          \}
29 
30          part \{
31             name: "text";
32             type: TEXT;
33             mouse\_events: 1; // we want to change the color on mouse-over
34 
35             // 2 states, one "default" and another "over" to be used
36             // on mouse over effect
37 
38             description \{
39                state: "default" 0.0;
40                color: 255 0 0 255; // red
41 
42                // define part coordinates:
43 
44                rel1 \{ // top-left at (WIDTH * 0.1 + 5, HEIGHT * 0.2 + 10)
45                   relative: 0.1 0.2;
46                   offset: 5 10;
47                \}
48                rel2 \{ // bottom-right at (WIDTH * 0.9 - 6, HEIGHT * 0.8 - 11)
49                   relative: 0.9 0.8;
50                   offset: -6 -11;
51                \}
52 
53                // define text specific state details
54                text \{
55                   font: "Sans"; // using fontconfig name!
56                   size: 10;
57                   text: "hello world";
58                \}
59             \}
60 
61             description \{
62                state: "over" 0.0;
63                inherit: "default" 0.0; // copy everything from "default" at this point
64 
65                color: 0 255 0 255; // override color, now it is green
66             \}
67          \}
68 
69          // do programs to change color on text mouse in/out (over)
70          programs \{
71             program \{
72                // what triggers this program:
73                signal: "mouse,in";
74                source: "text";
75 
76                // what this program does:
77                action: STATE\_SET "over" 0.0;
78                target: "text";
79 
80                // do the state-set in a nice interpolation animation
81                // using linear time in 0.1 second
82                transition: LINEAR 0.1;
83             \}
84 
85             program \{
86                // what triggers this program:
87                signal: "mouse,out";
88                source: "text";
89 
90                // what this program does:
91                action: STATE\_SET "default" 0.0;
92                target: "text";
93 
94                // do the state-set in a nice interpolation animation
95                // using linear time in 0.1 second
96                transition: LINEAR 0.1;
97             \}
98          \}
99       \}
100    \}
101 \}
\end{DoxyCodeInclude}


More examples can be found at \hyperlink{edje_examples}{Edje Examples}. 