edje/examples: add example for focus actions

Just a regular (non multiseat) focus example for
actions FOCUS_SET and FOCUS_OBJECT
This commit is contained in:
Bruno Dilly 2016-12-14 15:47:20 -02:00
parent 1a60462fad
commit d11a8d3682
4 changed files with 491 additions and 0 deletions

1
edje/.gitignore vendored
View File

@ -12,6 +12,7 @@
/edje-dynamic-multiseat
/edje-edit-part-box
/edje-entry
/edje-focus
/edje-multiseat
/edje-multisense
/edje-perspective

View File

@ -42,6 +42,7 @@ external_elm_button.edc \
external_elm_check.edc \
external_elm_panes.edc \
external_emotion_elm.edc \
focus.edc \
lua_script.edc \
messages_echo.edc \
multiseat.edc \
@ -143,6 +144,7 @@ edje-drag.c \
edje-dynamic-multiseat.c \
edje-edit-part-box.c \
edje-entry.c \
edje-focus.c \
edje-multiseat.c \
edje-multisense.c \
edje-perspective.c \
@ -218,6 +220,7 @@ edje-drag \
edje-dynamic-multiseat \
edje-edit-part-box \
edje-entry \
edje-focus \
edje-multiseat \
edje-perspective \
edje-signals-messages \

157
unsorted/edje/edje-focus.c Normal file
View File

@ -0,0 +1,157 @@
/**
* Edje example demonstrating how to deal with part and objects focus.
*
* @verbatim
* edje_cc focus.edc && gcc -o edje-focus edje-focus.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#else
# define EINA_UNUSED
#endif
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "."
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#define WIDTH 400
#define HEIGHT 400
static const char *GROUPNAME = "example/main";
static const char *EDJE_FILE = PACKAGE_DATA_DIR"/focus.edj";
static void
_on_destroy(Ecore_Evas *ee EINA_UNUSED)
{
ecore_main_loop_quit();
}
static void
_on_canvas_resize(Ecore_Evas *ee)
{
Evas_Object *edje_obj;
int w, h;
edje_obj = ecore_evas_data_get(ee, "edje_obj");
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
evas_object_resize(edje_obj, w, h);
}
static void
_focus_part_in_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
const char *emission EINA_UNUSED, const char *source)
{
printf("Focus set to part %s\n", source);
}
static void
_focus_part_out_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
const char *emission EINA_UNUSED, const char *source)
{
printf("Focus unset to part %s\n", source);
}
static void
_focus_obj_in_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
Efl_Input_Focus *ev = event->info;
Evas_Object *rect = event->object;
/* it always will print the default seat name, since FOCUS_OBJECT
isn't setting a specific seat */
printf("Focus set to object %s (seat %s)\n", evas_object_name_get(rect),
efl_input_device_name_get(efl_input_device_get(ev)));
}
static void
_focus_obj_out_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
Efl_Input_Focus *ev = event->info;
Evas_Object *rect = event->object;
printf("Focus unset to object %s (seat %s)\n", evas_object_name_get(rect),
efl_input_device_name_get(efl_input_device_get(ev)));
}
int
main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
{
Evas_Object *edje_obj, *rect_left, *rect_right;
Ecore_Evas *ee;
Evas *evas;
if (!ecore_evas_init())
return EXIT_FAILURE;
if (!edje_init())
goto shutdown_ecore_evas;
ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
if (!ee) goto shutdown_edje;
ecore_evas_callback_destroy_set(ee, _on_destroy);
ecore_evas_callback_resize_set(ee, _on_canvas_resize);
ecore_evas_title_set(ee, "Edje Focus Example");
evas = ecore_evas_get(ee);
edje_obj = edje_object_add(evas);
if (!edje_object_file_set(edje_obj, EDJE_FILE, GROUPNAME))
printf("failed to set file %s.\n", EDJE_FILE);
evas_object_move(edje_obj, 0, 0);
evas_object_resize(edje_obj, WIDTH, HEIGHT);
evas_object_show(edje_obj);
ecore_evas_data_set(ee, "edje_obj", edje_obj);
edje_object_signal_callback_add(edje_obj, "focus,part,in", "*",
_focus_part_in_cb, NULL);
edje_object_signal_callback_add(edje_obj, "focus,part,out", "*",
_focus_part_out_cb, NULL);
rect_left = evas_object_rectangle_add(evas);
evas_object_name_set(rect_left, "rect left");
evas_object_color_set(rect_left, 200, 200, 100, 255);
edje_object_part_swallow(edje_obj, "button,3", rect_left);
efl_event_callback_add(rect_left, EFL_EVENT_FOCUS_IN,
_focus_obj_in_cb, NULL);
efl_event_callback_add(rect_left, EFL_EVENT_FOCUS_OUT,
_focus_obj_out_cb, NULL);
rect_right = evas_object_rectangle_add(evas);
evas_object_name_set(rect_right, "rect right");
evas_object_color_set(rect_right, 100, 200, 200, 255);
edje_object_part_swallow(edje_obj, "button,4", rect_right);
efl_event_callback_add(rect_right, EFL_EVENT_FOCUS_IN,
_focus_obj_in_cb, NULL);
efl_event_callback_add(rect_right, EFL_EVENT_FOCUS_OUT,
_focus_obj_out_cb, NULL);
printf("Running example on evas engine %s\n",
ecore_evas_engine_name_get(ee));
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;
}

330
unsorted/edje/focus.edc Normal file
View File

@ -0,0 +1,330 @@
collections {
group {
name: "example/main";
min: 400 400;
parts {
part {
name: "bg";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
}
}
part {
name: "title";
type: TEXT;
mouse_events: 0;
description {
state: "default" 0.0;
color: 0 0 0 255;
rel1 {
relative: 0.0 0.0;
offset: 0 0;
to: "bg";
}
rel2 {
relative: 1.0 0.2;
offset: -1 -1;
to: "bg";
}
text {
text: "Focus Example";
size: 16;
font: "sans";
min: 1 1;
}
}
}
part {
name: "buttons";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
rel1.relative: 0.2 0.3;
rel2.relative: 0.8 0.9;
color: 255 255 255 0;
}
}
part {
name: "button_bg,1";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
rel1 {
to: "buttons";
relative: 0.1 0.1;
}
rel2 {
to: "buttons";
relative: 0.45 0.45;
}
color: 200 200 200 255;
}
description {
state: "focused" 0.0;
inherit: "default" 0.0;
color: 190 120 120 255;
}
}
part {
name: "button,1";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
rel1 {
to: "button_bg,1";
offset: 10 10;
}
rel2 {
to: "button_bg,1";
offset: -11 -11;
}
color: 200 200 200 255;
}
}
part {
name: "button_bg,2";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
rel1 {
to: "buttons";
relative: 0.55 0.1;
}
rel2 {
to: "buttons";
relative: 0.9 0.45;
}
color: 200 200 200 255;
}
description {
state: "focused" 0.0;
inherit: "default" 0.0;
color: 190 120 120 255;
}
}
part {
name: "button,2";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
rel1 {
to: "button_bg,2";
offset: 10 10;
}
rel2 {
to: "button_bg,2";
offset: -11 -11;
}
color: 200 200 200 255;
}
}
part {
name: "button_bg,3";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
rel1 {
to: "buttons";
relative: 0.1 0.55;
}
rel2 {
to: "buttons";
relative: 0.45 0.9;
}
color: 200 200 200 255;
}
description {
state: "focused" 0.0;
inherit: "default" 0.0;
color: 190 120 120 255;
}
}
part {
name: "button,3";
type: SWALLOW;
mouse_events: 0;
description {
state: "default" 0.0;
rel1 {
to: "button_bg,3";
offset: 10 10;
}
rel2 {
to: "button_bg,3";
offset: -11 -11;
}
}
}
part {
name: "button_bg,4";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
rel1 {
to: "buttons";
relative: 0.55 0.55;
}
rel2 {
to: "buttons";
relative: 0.9 0.9;
}
color: 200 200 200 255;
}
description {
state: "focused" 0.0;
inherit: "default" 0.0;
color: 190 120 120 255;
}
}
part {
name: "button,4";
type: SWALLOW;
mouse_events: 0;
description {
state: "default" 0.0;
rel1 {
to: "button_bg,4";
offset: 10 10;
}
rel2 {
to: "button_bg,4";
offset: -11 -11;
}
}
}
}
programs {
program {
name: "button,clicked,1";
signal: "mouse,clicked,1";
source: "button_bg,1";
action: FOCUS_SET;
target: "button,1";
after: "unfocus,objects";
}
program {
name: "button,clicked,2";
signal: "mouse,clicked,1";
source: "button_bg,2";
action: FOCUS_SET;
target: "button,2";
after: "unfocus,objects";
}
program {
name: "unfocus,objects";
action: FOCUS_OBJECT;
}
program {
name: "button,clicked,3";
signal: "mouse,clicked,1";
source: "button_bg,3";
action: FOCUS_OBJECT;
target: "button,3";
after: "unset,part";
}
program {
name: "button,clicked,4";
signal: "mouse,clicked,1";
source: "button_bg,4";
action: FOCUS_OBJECT;
target: "button,4";
after: "unset,part";
}
program {
name: "unset,part";
action: FOCUS_SET;
}
program {
name: "button,focused,1";
signal: "focus,part,in";
source: "button,1";
action: STATE_SET "focused" 0.0;
target: "button_bg,1";
}
program {
name: "button,focused,2";
signal: "focus,part,in";
source: "button,2";
action: STATE_SET "focused" 0.0;
target: "button_bg,2";
}
program {
name: "button,focused,3";
signal: "focus,part,in";
source: "button,3";
action: STATE_SET "focused" 0.0;
target: "button_bg,3";
}
program {
name: "button,focused,4";
signal: "focus,part,in";
source: "button,4";
action: STATE_SET "focused" 0.0;
target: "button_bg,4";
}
program {
name: "button,unfocused,1";
signal: "focus,part,out";
source: "button,1";
action: STATE_SET "default" 0.0;
target: "button_bg,1";
}
program {
name: "button,unfocused,2";
signal: "focus,part,out";
source: "button,2";
action: STATE_SET "default" 0.0;
target: "button_bg,2";
}
program {
name: "button,unfocused,3";
signal: "focus,part,out";
source: "button,3";
action: STATE_SET "default" 0.0;
target: "button_bg,3";
}
program {
name: "button,unfocused,4";
signal: "focus,part,out";
source: "button,4";
action: STATE_SET "default" 0.0;
target: "button_bg,4";
}
}
}
}