summaryrefslogtreecommitdiff
path: root/src/bin/elementary
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2019-11-27 13:04:31 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2019-11-27 13:04:32 +0900
commitc7f37fe61852ea45dce071e0f80f98adcce08981 (patch)
tree964906c510dd0af5310157ab0ebbcc4c29d42543 /src/bin/elementary
parentf10c91cda9795a43e6984814b7394383cf9da812 (diff)
Efl.Text.Attribute_Factory
Summary: Implementation of new Efl.Text.Attribute_Factory class which replace the annotation interface. Currently, we have two public methods: ``` void efl_text_attribute_factory_attribute_insert(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end, const char *format) unsigned int efl_text_attribute_factory_attribute_clear(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end); ``` Other methods will be internal methods, for the time being, we will redesign internal methods Reviewers: woohyun, tasn, segfaultxavi, bu5hm4n, zmike Subscribers: zmike, q66, cedric, segfaultxavi, bu5hm4n, a.srour, #committers, #reviewers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10646
Diffstat (limited to 'src/bin/elementary')
-rw-r--r--src/bin/elementary/test.c2
-rw-r--r--src/bin/elementary/test_efl_ui_text.c162
2 files changed, 2 insertions, 162 deletions
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index a78850a..1d91bf5 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -366,7 +366,6 @@ void test_code_diff_inline(void *data, Evas_Object *obj, void *event_info);
366void test_efl_ui_text(void *data, Evas_Object *obj, void *event_info); 366void test_efl_ui_text(void *data, Evas_Object *obj, void *event_info);
367void test_efl_ui_text_inputfield(void *data, Evas_Object *obj, void *event_info); 367void test_efl_ui_text_inputfield(void *data, Evas_Object *obj, void *event_info);
368void test_efl_ui_text_label(void *data, Evas_Object *obj, void *event_info); 368void test_efl_ui_text_label(void *data, Evas_Object *obj, void *event_info);
369void test_ui_text_item_factory(void *data, Evas_Object *obj, void *event_info);
370void test_evas_mask(void *data, Edje_Object *obj, void *event_info); 369void test_evas_mask(void *data, Edje_Object *obj, void *event_info);
371void test_gfx_filters(void *data, Evas_Object *obj, void *event_info); 370void test_gfx_filters(void *data, Evas_Object *obj, void *event_info);
372void test_evas_snapshot(void *data, Evas_Object *obj, void *event_info); 371void test_evas_snapshot(void *data, Evas_Object *obj, void *event_info);
@@ -941,7 +940,6 @@ add_tests:
941 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text", test_efl_ui_text); 940 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text", test_efl_ui_text);
942 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text Input Field", test_efl_ui_text_inputfield); 941 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text Input Field", test_efl_ui_text_inputfield);
943 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text Label", test_efl_ui_text_label); 942 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Text Label", test_efl_ui_text_label);
944 ADD_TEST_EO(NULL, "Entries", "Ui.Text Item Factory", test_ui_text_item_factory);
945 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Tags", test_ui_tags); 943 ADD_TEST_EO(NULL, "Entries", "Efl.Ui.Tags", test_ui_tags);
946 944
947 //------------------------------// 945 //------------------------------//
diff --git a/src/bin/elementary/test_efl_ui_text.c b/src/bin/elementary/test_efl_ui_text.c
index d56fddb..e060067 100644
--- a/src/bin/elementary/test_efl_ui_text.c
+++ b/src/bin/elementary/test_efl_ui_text.c
@@ -5,6 +5,7 @@
5#include <Efl_Ui.h> 5#include <Efl_Ui.h>
6#include <Elementary.h> 6#include <Elementary.h>
7#include "elm_priv.h" //FIXME remove this once efl.ui.text doesn't need elm_general.h 7#include "elm_priv.h" //FIXME remove this once efl.ui.text doesn't need elm_general.h
8
8static void 9static void
9_apply_style(Eo *obj, size_t start_pos, size_t end_pos, const char *style) 10_apply_style(Eo *obj, size_t start_pos, size_t end_pos, const char *style)
10{ 11{
@@ -16,7 +17,7 @@ _apply_style(Eo *obj, size_t start_pos, size_t end_pos, const char *style)
16 efl_text_cursor_position_set(start, start_pos); 17 efl_text_cursor_position_set(start, start_pos);
17 efl_text_cursor_position_set(end, end_pos); 18 efl_text_cursor_position_set(end, end_pos);
18 19
19 efl_text_annotation_insert(obj, efl_text_cursor_handle_get(start), efl_text_cursor_handle_get(end), style); 20 efl_text_attribute_factory_attribute_insert(start, end, style);
20 21
21 efl_del(start); 22 efl_del(start);
22 efl_del(end); 23 efl_del(end);
@@ -235,162 +236,3 @@ test_efl_ui_text_inputfield(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED
235 efl_gfx_entity_size_set(win, EINA_SIZE2D(300, 200)); 236 efl_gfx_entity_size_set(win, EINA_SIZE2D(300, 200));
236 237
237} 238}
238
239#define IMAGES_SZ 5
240
241static const char *images[IMAGES_SZ] = {
242 "sky", "logo", "dog", "eet_rock", "eet_plant" };
243
244static void
245_on_factory_bt_image_clicked(void *data, const Efl_Event *event EINA_UNUSED)
246{
247 Evas_Object *en = data;
248 static int image_idx = 0;
249
250 image_idx = (image_idx + 1) % IMAGES_SZ;
251
252 efl_text_cursor_item_insert(en, efl_text_cursor_handle_get(efl_text_interactive_main_cursor_get(en)),
253 images[image_idx], "size=32x32");
254 printf("Inserted image: key = %s\n", images[image_idx]);
255}
256
257static void
258_on_factory_bt_emoticon_clicked(void *data, const Efl_Event *event EINA_UNUSED)
259{
260 Evas_Object *en = data;
261 efl_text_cursor_item_insert(en, efl_text_cursor_handle_get(efl_text_interactive_main_cursor_get(en)),
262 "emoticon/evil-laugh", "size=32x32");
263}
264
265static struct
266{
267 const char *name;
268 Eo *item_factory;
269} factories[3];
270
271static void
272_on_factory_bt_factory_clicked(void *data, const Efl_Event *event EINA_UNUSED)
273{
274 Evas_Object *en = data;
275 static int item_factory_idx = 0;
276
277 item_factory_idx = (item_factory_idx + 1) % 3;
278 efl_ui_text_item_factory_set(en, factories[item_factory_idx].item_factory);
279 printf("Factory set to: %s\n", factories[item_factory_idx].name);
280}
281
282#define FACTORY_NONE 0
283#define FACTORY_IMAGE 1
284#define FACTORY_EMOTICON 2
285
286void
287test_ui_text_item_factory(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
288{
289 Evas_Object *win, *bx, *bx2, *bt, *en;
290 Efl_Text_Cursor *main_cur, *cur;
291 char buf[128];
292 Eina_File *f;
293
294 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
295 efl_text_set(efl_added, "Efl Ui Text Item Factory"),
296 efl_ui_win_autodel_set(efl_added, EINA_TRUE));
297
298 bx = efl_add(EFL_UI_BOX_CLASS, win);
299 efl_content_set(win, bx);
300
301 en = efl_add(EFL_UI_TEXT_CLASS, bx,
302 efl_text_multiline_set(efl_added, EINA_TRUE));
303
304 factories[FACTORY_NONE].name = "None (Fallback)";
305 factories[FACTORY_NONE].item_factory = NULL;
306
307 factories[FACTORY_IMAGE].name = "Image Factory";
308 factories[FACTORY_IMAGE].item_factory =
309 efl_add(EFL_UI_TEXT_FACTORY_IMAGES_CLASS, en);
310
311 factories[FACTORY_EMOTICON].name = "Emoticon Factory";
312 factories[FACTORY_EMOTICON].item_factory =
313 efl_add(EFL_UI_TEXT_FACTORY_EMOTICONS_CLASS, en);
314
315 // Test assigning file path source
316 snprintf(buf, sizeof(buf), "%s/images/sky_01.jpg", elm_app_data_dir_get());
317 efl_ui_text_factory_images_matches_add(factories[FACTORY_IMAGE].item_factory,
318 images[0], buf, NULL);
319 snprintf(buf, sizeof(buf), "%s/images/logo.png", elm_app_data_dir_get());
320 efl_ui_text_factory_images_matches_add(factories[FACTORY_IMAGE].item_factory,
321 images[1], buf, NULL);
322 snprintf(buf, sizeof(buf), "%s/images/mystrale.jpg", elm_app_data_dir_get());
323 efl_ui_text_factory_images_matches_add(factories[FACTORY_IMAGE].item_factory,
324 images[2], buf, NULL);
325
326 // Open EET source w/ key
327 snprintf(buf, sizeof(buf), "%s/images/image_items.eet", elm_app_data_dir_get());
328 f = eina_file_open(buf, EINA_FALSE);
329 if (f)
330 {
331 efl_ui_text_factory_images_matches_mmap_add(
332 factories[FACTORY_IMAGE].item_factory,
333 "eet_rock", f, "rock");
334 efl_ui_text_factory_images_matches_mmap_add(
335 factories[FACTORY_IMAGE].item_factory,
336 "eet_plant", f, "plant");
337 eina_file_close(f);
338 }
339 else
340 {
341 printf("Error loading test file. Please review test.");
342 }
343
344
345 printf("Added Efl.Ui.Text object\n");
346 efl_text_set(en, "Hello world! Goodbye world! This is a test text for the"
347 " new UI Text widget.\xE2\x80\xA9This is the next paragraph.\nThis"
348 " is the next line.\nThis is Yet another line! Line and paragraph"
349 " separators are actually different!");
350 efl_text_font_set(en, "Sans", 14);
351 efl_text_normal_color_set(en, 255, 255, 255, 255);
352
353 main_cur = efl_text_interactive_main_cursor_get(en);
354 cur = efl_ui_text_cursor_create(en);
355
356 efl_text_cursor_position_set(cur, 2);
357 efl_text_cursor_item_insert(en, efl_text_cursor_handle_get(cur), "emoticon/happy", "size=32x32");
358 efl_text_cursor_position_set(cur, 50);
359
360 snprintf(buf, sizeof(buf), "file://%s/images/sky_01.jpg", elm_app_data_dir_get());
361 efl_text_cursor_item_insert(en, efl_text_cursor_handle_get(cur), buf, "size=32x32");
362 efl_text_cursor_position_set(main_cur, 5);
363
364 efl_text_interactive_editable_set(en, EINA_TRUE);
365 efl_ui_text_scrollable_set(en, EINA_TRUE);
366 efl_pack(bx, en);
367 elm_object_focus_set(en, EINA_TRUE);
368
369 bx2 = efl_add(EFL_UI_BOX_CLASS, bx);
370 efl_gfx_hint_weight_set(bx2, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
371 efl_ui_layout_orientation_set(bx2, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL);
372
373 bt = efl_add(EFL_UI_BUTTON_CLASS, bx2);
374 efl_text_set(bt, "Image");
375 efl_event_callback_add(bt, EFL_INPUT_EVENT_CLICKED, _on_factory_bt_image_clicked, en);
376 efl_gfx_hint_weight_set(bt, EFL_GFX_HINT_EXPAND, 0.0);
377 efl_pack(bx2, bt);
378 elm_object_focus_allow_set(bt, EINA_FALSE);
379
380 bt = efl_add(EFL_UI_BUTTON_CLASS, bx2);
381 efl_text_set(bt, "Emoticon");
382 efl_event_callback_add(bt, EFL_INPUT_EVENT_CLICKED, _on_factory_bt_emoticon_clicked, en);
383 efl_gfx_hint_weight_set(bt, EFL_GFX_HINT_EXPAND, 0.0);
384 efl_pack(bx2, bt);
385 elm_object_focus_allow_set(bt, EINA_FALSE);
386
387 bt = efl_add(EFL_UI_BUTTON_CLASS, bx2);
388 efl_text_set(bt, "Factory");
389 efl_event_callback_add(bt, EFL_INPUT_EVENT_CLICKED, _on_factory_bt_factory_clicked, en);
390 efl_gfx_hint_weight_set(bt, EFL_GFX_HINT_EXPAND, 0.0);
391 efl_pack(bx2, bt);
392 elm_object_focus_allow_set(bt, EINA_FALSE);
393
394 efl_pack(bx, bx2);
395 efl_gfx_entity_size_set(win, EINA_SIZE2D(480, 320));
396}