examples/edje: add example of entry - editable text

Not trivial to be done imo, so it deserves an example.
This commit is contained in:
Bruno Dilly 2016-11-04 14:17:23 -02:00
parent 24f4d14004
commit 96995032ea
4 changed files with 270 additions and 0 deletions

View File

@ -10,6 +10,7 @@
/edje-color-class
/edje-drag
/edje-edit-part-box
/edje-entry
/edje-multisense
/edje-perspective
/edje-signals-messages

View File

@ -35,6 +35,7 @@ embryo_set_state_anim.edc \
embryo_set_text.edc \
embryo_timer.edc \
embryo_tween_anim.edc \
entry.edc \
external_elm_anchorblock.edc \
external_elm_button.edc \
external_elm_check.edc \
@ -138,6 +139,7 @@ edje-codegen-example.c \
edje-color-class.c \
edje-drag.c \
edje-edit-part-box.c \
edje-entry.c \
edje-multisense.c \
edje-perspective.c \
edje-signals-messages.c \
@ -210,6 +212,7 @@ edje-codegen-example \
edje-color-class \
edje-drag\
edje-edit-part-box \
edje-entry \
edje-perspective \
edje-signals-messages \
edje-swallow \

View File

@ -0,0 +1,117 @@
/**
* Edje example for a entry (editable text)
*
* @verbatim
* edje_cc entry.edc && gcc -o edje-entry edje-entry.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 (300)
#define HEIGHT (300)
#define KEY_BG_OBJ "bg_obj"
#define KEY_EDJE_OBJ "edje_obj"
#define GROUPNAME_MAIN "example/main"
#define PARTNAME_TEXT "example/text"
static void
_on_delete(Ecore_Evas *ee EINA_UNUSED)
{
ecore_main_loop_quit();
}
/* here just to keep our example's window size and background image's
* size in synchrony */
static void
_on_canvas_resize(Ecore_Evas *ee)
{
Evas_Object *bg, *edj;
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
bg = ecore_evas_data_get(ee, KEY_BG_OBJ);
evas_object_resize(bg, w, h);
edj = ecore_evas_data_get(ee, KEY_EDJE_OBJ);
evas_object_resize(edj, w, h);
}
static void
_setup_evas_object(Ecore_Evas *ee, Evas_Object *obj, const char *key)
{
evas_object_move(obj, 0, 0);
evas_object_resize(obj, WIDTH, HEIGHT);
evas_object_show(obj);
ecore_evas_data_set(ee, key, obj);
}
int
main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
{
const char *edje_file = PACKAGE_DATA_DIR"/entry.edj";
Evas_Object *bg, *edje_obj;
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_delete_request_set(ee, _on_delete);
ecore_evas_callback_resize_set(ee, _on_canvas_resize);
ecore_evas_title_set(ee, "Edje Entry");
evas = ecore_evas_get(ee);
bg = evas_object_rectangle_add(evas);
evas_object_color_set(bg, 210, 210, 210, 255);
_setup_evas_object(ee, bg, KEY_BG_OBJ);
edje_obj = edje_object_add(evas);
edje_object_file_set(edje_obj, edje_file, GROUPNAME_MAIN);
_setup_evas_object(ee, edje_obj, KEY_EDJE_OBJ);
/* important to focus it or it won't receive key down strokes */
evas_object_focus_set(edje_obj, EINA_TRUE);
edje_object_part_text_set(edje_obj, PARTNAME_TEXT, "Type here : ");
edje_object_part_text_cursor_end_set(edje_obj, PARTNAME_TEXT,
EDJE_CURSOR_MAIN);
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;
}

149
src/examples/edje/entry.edc Normal file
View File

@ -0,0 +1,149 @@
collections {
styles {
style {
name: "entry_style";
// This style wraps lines at word boundaries.
// Check Evas textblock's documentation to see all the options
base: "font="sans" font_size=10 color=#000 wrap="word" left_margin=2 right_margin=2";
}
}
group {
name: "example/main";
min: 12 50;
parts {
part {
name: "background";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
// 3 pixels of margin on left and top
rel1.offset: 3 3;
// 3 pixels of margin on right and bottom... -1 (default) -3 = -4
// Look at documentation about EDC parts positioning
rel2.offset: -4 -4;
}
}
part {
name: "example/text";
type: TEXTBLOCK;
scale: 1;
// It's mandatory to set entry_mode as editable.
entry_mode: EDITABLE;
select_mode: DEFAULT;
cursor_mode: UNDER;
mouse_events: 1;
// It causes a textblock that is editable to allow multiple lines
// for editing.
multiline: 1;
// Set groups used to be used as selection effect and
// cursor.
source: "example/selection";
source4: "example/cursor";
description {
state: "default" 0.0;
min: 12 50;
// Position text relative to background, with a small margin
rel1 {
to: "background";
offset: 2 2;
}
rel2 {
to: "background";
offset: -3 -3;
}
text {
style: "entry_style";
min: 0 1;
align: 0.0 0.0;
}
}
}
}
programs {
program {
name: "focus";
signal: "load";
source: "";
action: FOCUS_SET;
target: "example/text";
}
}
}
group {
name: "example/selection";
parts {
part {
name: "selection";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
color: 180 180 180 255;
}
}
}
}
group {
name: "example/cursor";
min: 1 0;
parts {
part {
name: "cursor";
type: RECT;
mouse_events: 0;
description {
state: "default" 0.0;
min: 2 12;
color: 0 0 0 255;
}
description {
state: "hidden" 0.0;
inherit: "default" 0.0;
color: 0 0 0 0;
}
}
}
// These programs are used to blink the cursor. They're
// started by the "load" signal, emitted when the EDJ file is loaded.
// It's a infinite loop between "default" and "hidden" states of
// the "cursor" part.
programs {
program {
name: "cursor_hide";
signal: "load";
source: "";
action: STATE_SET "hidden" 0.0;
target: "cursor";
transition: SINUSOIDAL 0.2;
after: "cursor_hide_timer";
}
program {
name: "cursor_hide_timer";
in: 0.2 0.0;
after: "cursor_show";
}
program {
name: "cursor_show";
action: STATE_SET "default" 0.0;
target: "cursor";
after: "cursor_show_timer";
}
program {
name: "cursor_show_timer";
in: 0.5 0.0;
after: "cursor_hide";
}
}
}
}