summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-04-24 20:33:20 +0900
committerJaehyun Cho <jae_hyun.cho@samsung.com>2019-04-24 20:33:21 +0900
commit8c0ab0db425588d6e42a21ee28d8e9d96c32a272 (patch)
treea62f4c34ebe43f9eaa617d191390583dc3f9046a
parent9b87eaee0884f55899a05d271b098b8b3e11c221 (diff)
ui.relative_layout: enhance relation_xxx_set,get apis
Summary: I forgot `efl_pack_layout_request` after relation_xxx is changed. Unnecessary register function in `relation_xxx_get` will return unexpected result. if a object is not child of relative_layout, `relation_xxx_get` should return `target = NULL` and `relative = 0.0` with error message. Test Plan: make check Reviewers: Jaehyun_Cho Reviewed By: Jaehyun_Cho Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8627
-rw-r--r--src/bin/elementary/test_ui_relative_layout.c2
-rw-r--r--src/lib/elementary/efl_ui_relative_layout_private.h20
-rw-r--r--src/tests/elementary/efl_ui_test_relative_layout.c51
3 files changed, 67 insertions, 6 deletions
diff --git a/src/bin/elementary/test_ui_relative_layout.c b/src/bin/elementary/test_ui_relative_layout.c
index f1d58af0cd..0e8bcbccd0 100644
--- a/src/bin/elementary/test_ui_relative_layout.c
+++ b/src/bin/elementary/test_ui_relative_layout.c
@@ -74,7 +74,6 @@ _btn_clicked_to_cb(void *data, const Efl_Event *event)
74 break; 74 break;
75 } 75 }
76 efl_text_set(obj, ((to == layout) ? "parent" : (char *)efl_text_get(to))); 76 efl_text_set(obj, ((to == layout) ? "parent" : (char *)efl_text_get(to)));
77 efl_pack_layout_request(layout);
78} 77}
79 78
80static void 79static void
@@ -102,7 +101,6 @@ _slider_changed_relative_cb(void *data, const Efl_Event *event)
102 efl_ui_relative_layout_relation_bottom_set(layout, btn, NULL, val); 101 efl_ui_relative_layout_relation_bottom_set(layout, btn, NULL, val);
103 break; 102 break;
104 } 103 }
105 efl_pack_layout_request(layout);
106} 104}
107 105
108static void 106static void
diff --git a/src/lib/elementary/efl_ui_relative_layout_private.h b/src/lib/elementary/efl_ui_relative_layout_private.h
index c58f7b0ecc..e0f2abfee0 100644
--- a/src/lib/elementary/efl_ui_relative_layout_private.h
+++ b/src/lib/elementary/efl_ui_relative_layout_private.h
@@ -70,23 +70,35 @@ struct _Efl_Ui_Relative_Layout_Child
70 70
71#define EFL_UI_RELATIVE_LAYOUT_RELATION_SET_GET(direction, DIRECTION) \ 71#define EFL_UI_RELATIVE_LAYOUT_RELATION_SET_GET(direction, DIRECTION) \
72 EOLIAN static void \ 72 EOLIAN static void \
73 _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \ 73 _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \
74 { \ 74 { \
75 Efl_Ui_Relative_Layout_Child *rc; \ 75 Efl_Ui_Relative_Layout_Child *rc; \
76 if (!child) return; \
76 rc = _relative_child_get(pd, child); \ 77 rc = _relative_child_get(pd, child); \
78 if (!rc) return; \
77 if (target) rc->rel[DIRECTION].to = target; \ 79 if (target) rc->rel[DIRECTION].to = target; \
78 if (relative < 0) relative = 0; \ 80 if (relative < 0) relative = 0; \
79 else if (relative > 1) relative = 1; \ 81 else if (relative > 1) relative = 1; \
80 rc->rel[DIRECTION].relative = relative; \ 82 rc->rel[DIRECTION].relative = relative; \
83 efl_pack_layout_request(obj); \
81 } \ 84 } \
82 \ 85 \
83 EOLIAN static void \ 86 EOLIAN static void \
84 _efl_ui_relative_layout_relation_ ## direction ## _get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo **target, double *relative) \ 87 _efl_ui_relative_layout_relation_ ## direction ## _get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo **target, double *relative) \
85 { \ 88 { \
86 Efl_Ui_Relative_Layout_Child *rc; \ 89 Efl_Ui_Relative_Layout_Child *rc; \
87 rc = _relative_child_get(pd, child); \ 90 Eo *rel_to = NULL; \
88 if (target) *target = rc->rel[DIRECTION].to; \ 91 double rel_relative = 0.0; \
89 if (relative) *relative = rc->rel[DIRECTION].relative; \ 92 rc = eina_hash_find(pd->children, &child); \
93 if (rc) \
94 { \
95 rel_to = rc->rel[DIRECTION].to; \
96 rel_relative = rc->rel[DIRECTION].relative; \
97 } \
98 else \
99 ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child)); \
100 if (target) *target = rel_to; \
101 if (relative) *relative = rel_relative; \
90 } 102 }
91 103
92#endif 104#endif
diff --git a/src/tests/elementary/efl_ui_test_relative_layout.c b/src/tests/elementary/efl_ui_test_relative_layout.c
index f769bf47ec..3027bdb082 100644
--- a/src/tests/elementary/efl_ui_test_relative_layout.c
+++ b/src/tests/elementary/efl_ui_test_relative_layout.c
@@ -292,10 +292,61 @@ EFL_START_TEST (efl_ui_relative_layout_layout_update_chain)
292} 292}
293EFL_END_TEST 293EFL_END_TEST
294 294
295EFL_START_TEST (efl_ui_relative_layout_relation_set)
296{
297 Eo *btn;
298 Eo *target = NULL;
299 double relative;
300
301 btn = efl_add(EFL_UI_BUTTON_CLASS, layout);
302
303 // negative test
304 efl_ui_relative_layout_relation_top_get(layout, NULL, &target, &relative);
305 ck_assert_ptr_eq(target, NULL);
306 ck_assert(EINA_DBL_EQ(relative, 0.0));
307
308 efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
309 ck_assert_ptr_eq(target, NULL);
310 ck_assert(EINA_DBL_EQ(relative, 0.0));
311
312 efl_ui_relative_layout_relation_top_set(layout, NULL, NULL, 0.0);
313 ck_assert_ptr_eq(target, NULL);
314 ck_assert(EINA_DBL_EQ(relative, 0.0));
315
316 // default value test
317 efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.0);
318
319 efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
320 ck_assert_ptr_eq(target, layout);
321 ck_assert(EINA_DBL_EQ(relative, 0.0));
322 efl_ui_relative_layout_relation_bottom_get(layout, btn, &target, &relative);
323 ck_assert_ptr_eq(target, layout);
324 ck_assert(EINA_DBL_EQ(relative, 1.0));
325 efl_ui_relative_layout_relation_left_get(layout, btn, &target, &relative);
326 ck_assert_ptr_eq(target, layout);
327 ck_assert(EINA_DBL_EQ(relative, 0.0));
328 efl_ui_relative_layout_relation_right_get(layout, btn, &target, &relative);
329 ck_assert_ptr_eq(target, layout);
330 ck_assert(EINA_DBL_EQ(relative, 1.0));
331
332 // positive test
333 efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.123);
334 efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
335 ck_assert_ptr_eq(target, layout);
336 ck_assert(EINA_DBL_EQ(relative, 0.123));
337
338 efl_ui_relative_layout_relation_top_set(layout, btn, NULL, 0.456);
339 efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
340 ck_assert_ptr_eq(target, layout);
341 ck_assert(EINA_DBL_EQ(relative, 0.456));
342}
343EFL_END_TEST
344
295void efl_ui_test_relative_layout(TCase *tc) 345void efl_ui_test_relative_layout(TCase *tc)
296{ 346{
297 tcase_add_checked_fixture(tc, layout_setup, layout_teardown); 347 tcase_add_checked_fixture(tc, layout_setup, layout_teardown);
298 tcase_add_test(tc, efl_ui_relative_layout_class_check); 348 tcase_add_test(tc, efl_ui_relative_layout_class_check);
299 tcase_add_test(tc, efl_ui_relative_layout_layout_update); 349 tcase_add_test(tc, efl_ui_relative_layout_layout_update);
300 tcase_add_test(tc, efl_ui_relative_layout_layout_update_chain); 350 tcase_add_test(tc, efl_ui_relative_layout_layout_update_chain);
351 tcase_add_test(tc, efl_ui_relative_layout_relation_set);
301} 352}