From f33084555fa5ccded6e5ec6179b49dc83c0cee8c Mon Sep 17 00:00:00 2001 From: "Jonas M. Gastal" Date: Wed, 21 Mar 2012 14:21:14 +0000 Subject: [PATCH] Move main page example from comments to files. SVN revision: 69541 --- legacy/edje/src/examples/edje_example.c | 81 +++++++++ legacy/edje/src/examples/edje_example.edc | 101 +++++++++++ legacy/edje/src/lib/Edje.h | 196 +--------------------- 3 files changed, 187 insertions(+), 191 deletions(-) create mode 100644 legacy/edje/src/examples/edje_example.c create mode 100644 legacy/edje/src/examples/edje_example.edc diff --git a/legacy/edje/src/examples/edje_example.c b/legacy/edje/src/examples/edje_example.c new file mode 100644 index 0000000000..103e867f12 --- /dev/null +++ b/legacy/edje/src/examples/edje_example.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +#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, "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; +} diff --git a/legacy/edje/src/examples/edje_example.edc b/legacy/edje/src/examples/edje_example.edc new file mode 100644 index 0000000000..0b15791f39 --- /dev/null +++ b/legacy/edje/src/examples/edje_example.edc @@ -0,0 +1,101 @@ +// 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; + } + } + } + } +} diff --git a/legacy/edje/src/lib/Edje.h b/legacy/edje/src/lib/Edje.h index 1f8014e0a5..64c8866b06 100644 --- a/legacy/edje/src/lib/Edje.h +++ b/legacy/edje/src/lib/Edje.h @@ -19,7 +19,7 @@ Please see the @ref authors page for contact details. Edje is a complex graphical design & layout library. -It doesn't pretend to do containing and regular layout like a widget +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 @@ -110,197 +110,11 @@ The application using Edje will then create an object in its Evas canvas and set the bundle file to use, specifying the @b group name to use. Edje will load such information and create all the required children objects with the specified properties as defined in each @b -part of the given group. See the following annotated example: +part of the given group. See the following example: +@include edje_example.c -@code - -#include -#include -#include -#include -#include - -#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, "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; - - eina_init(); - evas_init(); - ecore_init(); - 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); - - return 0; -} -@endcode - -It requires the following source Edje file: -@code -// 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; - } - } - } - } -} -@endcode +The above example requires the following annotated source Edje file: +@include edje_example.edc One should save these files as edje_example.c and edje_example.edc then: