aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorDaniel Hirt <hirt.danny@gmail.com>2018-11-06 16:52:53 +0200
committerDaniel Hirt <hirt.danny@gmail.com>2018-11-06 18:33:56 +0200
commitface90632e7796c146b18e31a93c164cbda43122 (patch)
tree9f562a695f47b8ffd639a9a71e4baed1bd757bc0 /src/examples
parentEfl text style: remove 'underline2_type' property (diff)
downloadefl-face90632e7796c146b18e31a93c164cbda43122.tar.gz
Canvas layout: support more Efl.Text.* with efl_part
This adds many Efl.Text.* that are useful for manipulating the underlying TEXTBLOCK object's propeties using efl_part. This has been implemented as part of the "user-defined" properties of the layout part, so that the changes on the part persist across load of different groups. Note that text styles have precedence over the TEXTBLOCK (Canvas.Text) object's properties. if an edc provides a style, the properties it manipulates as part of the "base:" string would not be affected by this API. In general, this helps reducing the amount of styles for objects (or modes of the same objects) that share the same setup, but are different in some properties (e.g. ellipsis, wrap etc). @feature Canvas layout: add text part "expand" property This adds "expansion modes", which are essentially the same as min/max hints in the edje part's 'description.text' fields. The user can then customize his widget to different modes without being forced to create a new edje group in the theme. Note that there is an added check in case one of the min/max text flags are provided from the theme. In such case, all flags from this new API will be ignored. This fortifies misuse where the flags are set both in theme and the API. @feature
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/elementary.mk9
-rw-r--r--src/examples/elementary/efl_canvas_layout_text.c158
-rw-r--r--src/examples/elementary/efl_canvas_layout_text.edc48
3 files changed, 212 insertions, 3 deletions
diff --git a/src/examples/elementary.mk b/src/examples/elementary.mk
index 0d0fa0052b..e928d9d89e 100644
--- a/src/examples/elementary.mk
+++ b/src/examples/elementary.mk
@@ -122,7 +122,8 @@ elementary/efl_thread_6.c \
elementary/efl_ui_list_example_1.c \
elementary/efl_ui_list_view_example_1.c \
elementary/efl_ui_list_view_example_2.c \
-elementary/efl_ui_list_view_example_3.c
+elementary/efl_ui_list_view_example_3.c \
+elementary/efl_canvas_layout_text.c
ELM_SRCS += \
elementary/bg_cxx_example_01.cc \
@@ -154,7 +155,8 @@ elementary/theme_example.edc \
elementary/layout_example.edc \
elementary/codegen_example.edc \
elementary/efl_ui_list_view_example.edc \
-elementary/prefs_example_03.edc
+elementary/prefs_example_03.edc \
+elementary/efl_canvas_layout_text.edc
ELM_EPCS = \
elementary/prefs_example_01.epc \
@@ -336,7 +338,8 @@ elementary/efl_thread_6 \
elementary/efl_ui_list_example_1 \
elementary/efl_ui_list_view_example_1 \
elementary/efl_ui_list_view_example_2 \
-elementary/efl_ui_list_view_example_3
+elementary/efl_ui_list_view_example_3 \
+elementary/efl_canvas_layout_text
#benchmark3d
#sphere-hunter
diff --git a/src/examples/elementary/efl_canvas_layout_text.c b/src/examples/elementary/efl_canvas_layout_text.c
new file mode 100644
index 0000000000..8e89403d19
--- /dev/null
+++ b/src/examples/elementary/efl_canvas_layout_text.c
@@ -0,0 +1,158 @@
+// gcc -o efl_canvas_layout_text efl_canvas_layout_text.c `pkg-config --cflags --libs elementary`
+// edje_cc efl_canvas_layout.edc
+// ./efl_canvas_layout_text
+
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#else
+# define EFL_BETA_API_SUPPORT 1
+# define EFL_EO_API_SUPPORT 1
+#endif
+
+#include <Efl.h>
+#include <Elementary.h>
+#include <string.h>
+
+static void
+_on_win_delete(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+ efl_exit(0);
+}
+
+static const char* groups[] = { "test", "test2" };
+static size_t group_itr = 0;
+
+static double ellipsis[] = { -1.0, 1.0 };
+static size_t ellipsis_itr = 0;
+
+static struct
+{
+ Efl_Text_Format_Wrap wrap;
+ const char *desc;
+} wraps[] =
+{
+ { EFL_TEXT_FORMAT_WRAP_NONE, "none" },
+ { EFL_TEXT_FORMAT_WRAP_WORD, "word" },
+ { EFL_TEXT_FORMAT_WRAP_CHAR, "char" },
+ { EFL_TEXT_FORMAT_WRAP_MIXED, "mixed" }
+};
+
+static struct
+{
+ Efl_Text_Format_Wrap wrap;
+ const char *desc;
+} group[] =
+{
+ { EFL_TEXT_FORMAT_WRAP_NONE, "none" },
+ { EFL_TEXT_FORMAT_WRAP_WORD, "word" },
+ { EFL_TEXT_FORMAT_WRAP_CHAR, "char" },
+ { EFL_TEXT_FORMAT_WRAP_MIXED, "mixed" }
+};
+static struct
+{
+ Efl_Canvas_Layout_Part_Text_Expand expand;
+ const char *desc;
+} expands[] =
+{
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_NONE, "none" },
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MIN_X, "min_x" },
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MIN_Y, "min_y" },
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MAX_X, "max_x" },
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MAX_Y, "max_y" },
+ { EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MIN_X | EFL_CANVAS_LAYOUT_PART_TEXT_EXPAND_MIN_Y , "min_x AND min_y"}
+};
+
+static size_t wrap_itr = 0;
+static size_t expand_itr = 0;
+
+static void
+_help(void)
+{
+ printf("Press 'w' to cycle wrap modes.\n"
+ "Press 's' to cycle expand hints and print min_size result.\n"
+ "Press 'g' to cycle group examples.\n"
+ "Press 'e' to cycle ellipsis modes.\n"
+ "Press 'h' to display this help.\n");
+}
+
+static const char *edjefile = "efl_canvas_layout_text.edj";
+
+static void
+_on_key_down(void *data, const Efl_Event *event)
+{
+ Efl_Input_Key *ev = event->info;
+ Eo *layout = data;
+ const char *key = efl_input_key_name_get(ev);
+
+ if (!strcmp(key, "g"))
+ {
+ // edje group
+ group_itr = (group_itr + 1) % 2;
+ efl_file_set(layout, edjefile, groups[group_itr]);
+ printf("Changed layout group to: %s\n", groups[group_itr]);
+ }
+ else if (!strcmp(key, "w"))
+ {
+ // wrap mode
+ wrap_itr = (wrap_itr + 1) % 4;
+ efl_text_wrap_set(efl_part(layout, "text"), wraps[wrap_itr].wrap);
+ printf("Changed wrap to %s\n", wraps[wrap_itr].desc);
+ }
+ else if (!strcmp(key, "e"))
+ {
+ // ellipsis value
+ ellipsis_itr = (ellipsis_itr + 1) % 2;
+ efl_text_ellipsis_set(efl_part(layout, "text"), ellipsis[ellipsis_itr]);
+ printf("Changed ellipsis to %f\n", ellipsis[ellipsis_itr]);
+ }
+ else if (!strcmp(key, "s"))
+ {
+ Eina_Size2D sz;
+ // expand mode
+ expand_itr = (expand_itr + 1) % 6;
+ efl_canvas_layout_part_text_expand_set(efl_part(layout, "text"),
+ expands[expand_itr].expand);
+ printf("Changed expand mode to: %s\n", expands[expand_itr].desc);
+
+ sz = efl_layout_calc_size_min(layout, EINA_SIZE2D(10, 10));
+ printf("new expand_min: %dx%d\n", sz.w, sz.h);
+ }
+ else if (!strcmp(key, "h"))
+ {
+ _help();
+ }
+}
+
+EAPI_MAIN void
+efl_main(void *data EINA_UNUSED,
+ const Efl_Event *ev)
+{
+
+ Eo *layout;
+ Eo *win;
+
+ win = efl_add(EFL_UI_WIN_CLASS, NULL,
+ efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
+ efl_text_set(efl_added, "Efl Canvas_Layout"),
+ efl_ui_win_autodel_set(efl_added, EINA_TRUE),
+ efl_event_callback_add(efl_added, EFL_UI_WIN_EVENT_DELETE_REQUEST, _on_win_delete, NULL));
+
+
+ layout = efl_add(EFL_CANVAS_LAYOUT_CLASS, win);
+ efl_file_set(layout, edjefile, groups[group_itr]);
+
+ efl_content_set(win, layout);
+ efl_gfx_entity_size_set(win, EINA_SIZE2D(110, 100));
+
+ efl_text_markup_set(efl_part(layout, "text"), "This is an example text. This is a layout text part.");
+ efl_text_wrap_set(efl_part(layout, "text"), wraps[wrap_itr].wrap);
+ efl_text_normal_color_set(efl_part(layout, "text"), 255, 255, 0, 255);
+ efl_text_font_set(efl_part(layout, "text"), "Serif", 12);
+
+ efl_canvas_layout_part_text_expand_set(efl_part(layout, "text"),
+ expands[expand_itr].expand);
+
+ efl_event_callback_add(win, EFL_EVENT_KEY_DOWN, _on_key_down, layout);
+
+}
+EFL_MAIN()
diff --git a/src/examples/elementary/efl_canvas_layout_text.edc b/src/examples/elementary/efl_canvas_layout_text.edc
new file mode 100644
index 0000000000..401ad0c255
--- /dev/null
+++ b/src/examples/elementary/efl_canvas_layout_text.edc
@@ -0,0 +1,48 @@
+efl_version: 1 21;
+collections {
+ styles {
+ style { name: "tbstyle";
+ base: "";
+ }
+ }
+ group { name: "test";
+ parts {
+ textblock { "text"; nomouse;
+ desc { "default";
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ text {
+ style: "tbstyle";
+ font: FN; size: 10;
+ align: 0.5 0.5;
+ }
+ visible: 1;
+ }
+ }
+ }
+ }
+ group { name: "test2";
+ parts {
+ rect { "rect"; nomouse; repeat; precise;
+ desc { "default";
+ color: 255 0 0 255;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.5 1;
+ }
+ }
+ textblock { "text"; nomouse;
+ desc { "default";
+ rel1.relative: 0.5 0.0;
+ rel2.relative: 1.0 1.0;
+ //fixed: 1 1;
+ text {
+ style: "tbstyle";
+ font: FN; size: 10;
+ align: 0.5 0.5;
+ }
+ visible: 1;
+ }
+ }
+ }
+ }
+}