summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-04-24 20:23:52 +0900
committerJaehyun Cho <jae_hyun.cho@samsung.com>2019-04-24 20:23:52 +0900
commit336500469ae2b2d2d4655cf5361d13612b8874b3 (patch)
tree1e17e26d16c40a8db441951e4e7bbd6bfa0393ef
parentb57fd8eb47db56c45cab593a96aedd22bb92a1aa (diff)
ui.relative_layout: add internal clipper
Summary: If there is no clipper of container, color_set and clipper_set api won't work. Test Plan: 1. elementary_test -to 'efl.ui.relative_layout' 2. Click button1 3. check that buttons color are changed. Reviewers: Jaehyun_Cho Reviewed By: Jaehyun_Cho Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8625
-rw-r--r--src/bin/elementary/test_ui_relative_layout.c16
-rw-r--r--src/lib/elementary/efl_ui_relative_layout.c117
-rw-r--r--src/lib/elementary/efl_ui_relative_layout_private.h2
3 files changed, 87 insertions, 48 deletions
diff --git a/src/bin/elementary/test_ui_relative_layout.c b/src/bin/elementary/test_ui_relative_layout.c
index e6481ec97e..dbb1647eee 100644
--- a/src/bin/elementary/test_ui_relative_layout.c
+++ b/src/bin/elementary/test_ui_relative_layout.c
@@ -16,6 +16,21 @@ typedef enum {
16} Options; 16} Options;
17 17
18static void 18static void
19_btn_color_clicked_cb(void *data, const Efl_Event *event EINA_UNUSED)
20{
21 Eo *layout = data;
22
23 static Eina_Bool changed = EINA_TRUE;
24
25 if (changed)
26 efl_gfx_color_set(layout, 0, 88, 204, 255);
27 else
28 efl_gfx_color_set(layout, 255, 255, 255, 255);
29
30 changed = !changed;
31}
32
33static void
19_btn_clicked_to_cb(void *data, const Efl_Event *event) 34_btn_clicked_to_cb(void *data, const Efl_Event *event)
20{ 35{
21 Eo *to, *btn, *obj = event->object; 36 Eo *to, *btn, *obj = event->object;
@@ -297,6 +312,7 @@ test_ui_relative_layout(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, vo
297 btn1 = efl_add(EFL_UI_BUTTON_CLASS, layout, 312 btn1 = efl_add(EFL_UI_BUTTON_CLASS, layout,
298 efl_text_set(efl_added, "button1"), 313 efl_text_set(efl_added, "button1"),
299 efl_gfx_hint_align_set(efl_added, 0.0, 0.0), 314 efl_gfx_hint_align_set(efl_added, 0.0, 0.0),
315 efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, _btn_color_clicked_cb, layout),
300 efl_ui_relative_layout_relation_right_set(layout, efl_added, layout, 0.0), 316 efl_ui_relative_layout_relation_right_set(layout, efl_added, layout, 0.0),
301 efl_ui_relative_layout_relation_bottom_set(layout, efl_added, layout, 0.0)); 317 efl_ui_relative_layout_relation_bottom_set(layout, efl_added, layout, 0.0));
302 318
diff --git a/src/lib/elementary/efl_ui_relative_layout.c b/src/lib/elementary/efl_ui_relative_layout.c
index 66bedb87ef..17bf97d8b5 100644
--- a/src/lib/elementary/efl_ui_relative_layout.c
+++ b/src/lib/elementary/efl_ui_relative_layout.c
@@ -29,6 +29,9 @@ _efl_ui_relative_layout_register(Efl_Ui_Relative_Layout_Data *pd, Eo *child)
29{ 29{
30 Efl_Ui_Relative_Layout_Child *rc; 30 Efl_Ui_Relative_Layout_Child *rc;
31 31
32 if (!efl_ui_widget_sub_object_add(pd->obj, child))
33 return NULL;
34
32 rc = calloc(1, sizeof(Efl_Ui_Relative_Layout_Child)); 35 rc = calloc(1, sizeof(Efl_Ui_Relative_Layout_Child));
33 if (!rc) return NULL; 36 if (!rc) return NULL;
34 37
@@ -43,19 +46,10 @@ _efl_ui_relative_layout_register(Efl_Ui_Relative_Layout_Data *pd, Eo *child)
43 rc->rel[BOTTOM].to = rc->layout; 46 rc->rel[BOTTOM].to = rc->layout;
44 rc->rel[BOTTOM].relative = 1.0; 47 rc->rel[BOTTOM].relative = 1.0;
45 48
46 if (pd->obj == child) 49 efl_key_data_set(child, "_elm_leaveme", pd->obj);
47 { 50 efl_canvas_object_clipper_set(child, pd->clipper);
48 rc->calc.state[0] = RELATIVE_CALC_DONE; 51 efl_canvas_group_member_add(pd->obj, child);
49 rc->calc.state[1] = RELATIVE_CALC_DONE; 52 efl_canvas_group_change(pd->obj);
50 rc->calc.chain_state[0] = RELATIVE_CALC_DONE;
51 rc->calc.chain_state[1] = RELATIVE_CALC_DONE;
52 }
53 else
54 {
55 efl_ui_widget_sub_object_add(pd->obj, child);
56 efl_canvas_group_member_add(pd->obj, child);
57 efl_canvas_group_change(pd->obj);
58 }
59 53
60 eina_hash_add(pd->children, &child, rc); 54 eina_hash_add(pd->children, &child, rc);
61 55
@@ -75,13 +69,19 @@ _relative_child_get(Efl_Ui_Relative_Layout_Data *pd, Eo *child)
75} 69}
76 70
77static Efl_Ui_Relative_Layout_Child * 71static Efl_Ui_Relative_Layout_Child *
78_relative_child_find(const Eina_Hash *children, Eo *target) 72_relative_child_find(Efl_Ui_Relative_Layout_Data *pd, Eo *target)
79{ 73{
80 Efl_Ui_Relative_Layout_Child *child; 74 Efl_Ui_Relative_Layout_Child *child;
81 75
82 child = eina_hash_find(children, &target); 76 if (pd->obj == target)
77 return pd->base;
78
79 child = eina_hash_find(pd->children, &target);
83 if (!child) 80 if (!child)
84 ERR("target(%p(%s)) is not registered", target, efl_class_name_get(target)); 81 {
82 ERR("target(%p(%s)) is not registered", target, efl_class_name_get(target));
83 child = pd->base;
84 }
85 85
86 return child; 86 return child;
87} 87}
@@ -353,9 +353,6 @@ _hash_child_calc_foreach_cb(const Eina_Hash *hash EINA_UNUSED, const void *key E
353 Efl_Ui_Relative_Layout_Child *child = data; 353 Efl_Ui_Relative_Layout_Child *child = data;
354 Eina_Rect want; 354 Eina_Rect want;
355 355
356 if (child->obj == child->layout)
357 return EINA_TRUE;
358
359 _child_calc(child, 0); 356 _child_calc(child, 0);
360 _child_calc(child, 1); 357 _child_calc(child, 1);
361 358
@@ -370,35 +367,18 @@ _hash_child_calc_foreach_cb(const Eina_Hash *hash EINA_UNUSED, const void *key E
370 367
371 368
372static Eina_Bool 369static Eina_Bool
373_hash_child_init_foreach_cb(const Eina_Hash *hash, const void *key EINA_UNUSED, 370_hash_child_init_foreach_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
374 void *data, void *fdata EINA_UNUSED) 371 void *data, void *fdata)
375{ 372{
376 Eina_Size2D max, min, aspect; 373 Eina_Size2D max, min, aspect;
377 Efl_Ui_Relative_Layout_Child *child = data; 374 Efl_Ui_Relative_Layout_Child *child = data;
378 Efl_Ui_Relative_Layout_Calc *calc = &(child->calc); 375 Efl_Ui_Relative_Layout_Calc *calc = &(child->calc);
376 Efl_Ui_Relative_Layout_Data *pd = fdata;
379 377
380 calc->to[LEFT] = _relative_child_find(hash, child->rel[LEFT].to); 378 calc->to[LEFT] = _relative_child_find(pd, child->rel[LEFT].to);
381 if (!calc->to[LEFT]) calc->to[LEFT] = eina_hash_find(hash, &child->layout); 379 calc->to[RIGHT] = _relative_child_find(pd, child->rel[RIGHT].to);
382 calc->to[RIGHT] = _relative_child_find(hash, child->rel[RIGHT].to); 380 calc->to[TOP] = _relative_child_find(pd, child->rel[TOP].to);
383 if (!calc->to[RIGHT]) calc->to[RIGHT] = eina_hash_find(hash, &child->layout); 381 calc->to[BOTTOM] = _relative_child_find(pd, child->rel[BOTTOM].to);
384 calc->to[TOP] = _relative_child_find(hash, child->rel[TOP].to);
385 if (!calc->to[TOP]) calc->to[TOP] = eina_hash_find(hash, &child->layout);
386 calc->to[BOTTOM] = _relative_child_find(hash, child->rel[BOTTOM].to);
387 if (!calc->to[BOTTOM]) calc->to[BOTTOM] = eina_hash_find(hash, &child->layout);
388
389 if (child->obj == child->layout)
390 {
391 Eina_Rect want = efl_gfx_entity_geometry_get(child->obj);
392 calc->want[0].position = want.x;
393 calc->want[0].length = want.w;
394 calc->want[1].position = want.y;
395 calc->want[1].length = want.h;
396 calc->state[0] = RELATIVE_CALC_DONE;
397 calc->state[1] = RELATIVE_CALC_DONE;
398 calc->chain_state[0] = RELATIVE_CALC_DONE;
399 calc->chain_state[1] = RELATIVE_CALC_DONE;
400 return EINA_TRUE;
401 }
402 382
403 calc->state[0] = RELATIVE_CALC_NONE; 383 calc->state[0] = RELATIVE_CALC_NONE;
404 calc->state[1] = RELATIVE_CALC_NONE; 384 calc->state[1] = RELATIVE_CALC_NONE;
@@ -454,7 +434,13 @@ _efl_ui_relative_layout_hints_changed_cb(void *data EINA_UNUSED, const Efl_Event
454EOLIAN static void 434EOLIAN static void
455_efl_ui_relative_layout_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Relative_Layout_Data *pd) 435_efl_ui_relative_layout_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Relative_Layout_Data *pd)
456{ 436{
457 eina_hash_foreach(pd->children, _hash_child_init_foreach_cb, NULL); 437 Eina_Rect want = efl_gfx_entity_geometry_get(obj);
438 pd->base->calc.want[0].position = want.x;
439 pd->base->calc.want[0].length = want.w;
440 pd->base->calc.want[1].position = want.y;
441 pd->base->calc.want[1].length = want.h;
442
443 eina_hash_foreach(pd->children, _hash_child_init_foreach_cb, pd);
458 eina_hash_foreach(pd->children, _hash_child_calc_foreach_cb, NULL); 444 eina_hash_foreach(pd->children, _hash_child_calc_foreach_cb, NULL);
459 445
460 efl_event_callback_call(obj, EFL_PACK_EVENT_LAYOUT_UPDATED, NULL); 446 efl_event_callback_call(obj, EFL_PACK_EVENT_LAYOUT_UPDATED, NULL);
@@ -489,6 +475,12 @@ _efl_ui_relative_layout_efl_gfx_entity_position_set(Eo *obj, Efl_Ui_Relative_Lay
489EOLIAN static void 475EOLIAN static void
490_efl_ui_relative_layout_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Relative_Layout_Data *pd EINA_UNUSED) 476_efl_ui_relative_layout_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Relative_Layout_Data *pd EINA_UNUSED)
491{ 477{
478 pd->clipper = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj);
479 evas_object_static_clip_set(pd->clipper, EINA_TRUE);
480 efl_gfx_entity_geometry_set(pd->clipper, EINA_RECT(-49999, -49999, 99999, 99999));
481 efl_canvas_group_member_add(obj, pd->clipper);
482 efl_ui_widget_sub_object_add(obj, pd->clipper);
483
492 efl_event_callback_add(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, 484 efl_event_callback_add(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED,
493 _efl_ui_relative_layout_hints_changed_cb, NULL); 485 _efl_ui_relative_layout_hints_changed_cb, NULL);
494 efl_canvas_group_add(efl_super(obj, MY_CLASS)); 486 efl_canvas_group_add(efl_super(obj, MY_CLASS));
@@ -506,7 +498,24 @@ _efl_ui_relative_layout_efl_object_constructor(Eo *obj, Efl_Ui_Relative_Layout_D
506 498
507 pd->obj = obj; 499 pd->obj = obj;
508 pd->children = eina_hash_pointer_new(_hash_free_cb); 500 pd->children = eina_hash_pointer_new(_hash_free_cb);
509 _efl_ui_relative_layout_register(pd, obj); 501
502 pd->base = calloc(1, sizeof(Efl_Ui_Relative_Layout_Child));
503 if (!pd->base) return NULL;
504
505 pd->base->obj = obj;
506 pd->base->layout = obj;
507 pd->base->rel[LEFT].to = obj;
508 pd->base->rel[LEFT].relative = 0.0;
509 pd->base->rel[RIGHT].to = obj;
510 pd->base->rel[RIGHT].relative = 1.0;
511 pd->base->rel[TOP].to = obj;
512 pd->base->rel[TOP].relative = 0.0;
513 pd->base->rel[BOTTOM].to = obj;
514 pd->base->rel[BOTTOM].relative = 1.0;
515 pd->base->calc.state[0] = RELATIVE_CALC_DONE;
516 pd->base->calc.state[1] = RELATIVE_CALC_DONE;
517 pd->base->calc.chain_state[0] = RELATIVE_CALC_DONE;
518 pd->base->calc.chain_state[1] = RELATIVE_CALC_DONE;
510 519
511 return obj; 520 return obj;
512} 521}
@@ -517,6 +526,7 @@ _efl_ui_relative_layout_efl_object_destructor(Eo *obj, Efl_Ui_Relative_Layout_Da
517 efl_event_callback_del(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, 526 efl_event_callback_del(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED,
518 _efl_ui_relative_layout_hints_changed_cb, NULL); 527 _efl_ui_relative_layout_hints_changed_cb, NULL);
519 eina_hash_free(pd->children); 528 eina_hash_free(pd->children);
529 if (pd->base) free(pd->base);
520 efl_destructor(efl_super(obj, MY_CLASS)); 530 efl_destructor(efl_super(obj, MY_CLASS));
521} 531}
522 532
@@ -524,14 +534,25 @@ EOLIAN static void
524_efl_ui_relative_layout_unregister(Eo *obj, Efl_Ui_Relative_Layout_Data *pd, Efl_Object *child) 534_efl_ui_relative_layout_unregister(Eo *obj, Efl_Ui_Relative_Layout_Data *pd, Efl_Object *child)
525{ 535{
526 _elm_widget_sub_object_redirect_to_top(obj, child); 536 _elm_widget_sub_object_redirect_to_top(obj, child);
527 if (!eina_hash_del_by_key(pd->children, &child)) 537 if (eina_hash_del_by_key(pd->children, &child))
528 ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child)); 538 {
539 efl_canvas_group_member_remove(obj, child);
540 efl_canvas_object_clipper_set(child, NULL);
541 efl_key_data_set(child, "_elm_leaveme", NULL);
542
543 efl_pack_layout_request(obj);
544 }
545 else
546 {
547 ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child));
548 }
529} 549}
530 550
531EOLIAN static void 551EOLIAN static void
532_efl_ui_relative_layout_unregister_all(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd) 552_efl_ui_relative_layout_unregister_all(Eo *obj, Efl_Ui_Relative_Layout_Data *pd)
533{ 553{
534 eina_hash_foreach(pd->children, _hash_free_foreach_cb, NULL); 554 eina_hash_foreach(pd->children, _hash_free_foreach_cb, NULL);
555 efl_pack_layout_request(obj);
535} 556}
536 557
537EOLIAN static Eina_Iterator * 558EOLIAN static Eina_Iterator *
diff --git a/src/lib/elementary/efl_ui_relative_layout_private.h b/src/lib/elementary/efl_ui_relative_layout_private.h
index b7410efc49..c58f7b0ecc 100644
--- a/src/lib/elementary/efl_ui_relative_layout_private.h
+++ b/src/lib/elementary/efl_ui_relative_layout_private.h
@@ -49,7 +49,9 @@ struct _Efl_Ui_Relative_Layout_Calc
49struct _Efl_Ui_Relative_Layout_Data 49struct _Efl_Ui_Relative_Layout_Data
50{ 50{
51 Eo *obj; 51 Eo *obj;
52 Eo *clipper;
52 Eina_Hash *children; 53 Eina_Hash *children;
54 Efl_Ui_Relative_Layout_Child *base;
53}; 55};
54 56
55struct _Efl_Ui_Relative_Layout_Relation 57struct _Efl_Ui_Relative_Layout_Relation