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)
downloadefl-8c0ab0db425588d6e42a21ee28d8e9d96c32a272.tar.gz
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)
break;
}
efl_text_set(obj, ((to == layout) ? "parent" : (char *)efl_text_get(to)));
- efl_pack_layout_request(layout);
}
static void
@@ -102,7 +101,6 @@ _slider_changed_relative_cb(void *data, const Efl_Event *event)
efl_ui_relative_layout_relation_bottom_set(layout, btn, NULL, val);
break;
}
- efl_pack_layout_request(layout);
}
static 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
#define EFL_UI_RELATIVE_LAYOUT_RELATION_SET_GET(direction, DIRECTION) \
EOLIAN static void \
- _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \
+ _efl_ui_relative_layout_relation_ ## direction ## _set(Eo *obj, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo *target, double relative) \
{ \
Efl_Ui_Relative_Layout_Child *rc; \
+ if (!child) return; \
rc = _relative_child_get(pd, child); \
+ if (!rc) return; \
if (target) rc->rel[DIRECTION].to = target; \
if (relative < 0) relative = 0; \
else if (relative > 1) relative = 1; \
rc->rel[DIRECTION].relative = relative; \
+ efl_pack_layout_request(obj); \
} \
\
EOLIAN static void \
_efl_ui_relative_layout_relation_ ## direction ## _get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Layout_Data *pd, Eo *child, Eo **target, double *relative) \
{ \
Efl_Ui_Relative_Layout_Child *rc; \
- rc = _relative_child_get(pd, child); \
- if (target) *target = rc->rel[DIRECTION].to; \
- if (relative) *relative = rc->rel[DIRECTION].relative; \
+ Eo *rel_to = NULL; \
+ double rel_relative = 0.0; \
+ rc = eina_hash_find(pd->children, &child); \
+ if (rc) \
+ { \
+ rel_to = rc->rel[DIRECTION].to; \
+ rel_relative = rc->rel[DIRECTION].relative; \
+ } \
+ else \
+ ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child)); \
+ if (target) *target = rel_to; \
+ if (relative) *relative = rel_relative; \
}
#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)
}
EFL_END_TEST
+EFL_START_TEST (efl_ui_relative_layout_relation_set)
+{
+ Eo *btn;
+ Eo *target = NULL;
+ double relative;
+
+ btn = efl_add(EFL_UI_BUTTON_CLASS, layout);
+
+ // negative test
+ efl_ui_relative_layout_relation_top_get(layout, NULL, &target, &relative);
+ ck_assert_ptr_eq(target, NULL);
+ ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+ efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, NULL);
+ ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+ efl_ui_relative_layout_relation_top_set(layout, NULL, NULL, 0.0);
+ ck_assert_ptr_eq(target, NULL);
+ ck_assert(EINA_DBL_EQ(relative, 0.0));
+
+ // default value test
+ efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.0);
+
+ efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 0.0));
+ efl_ui_relative_layout_relation_bottom_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 1.0));
+ efl_ui_relative_layout_relation_left_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 0.0));
+ efl_ui_relative_layout_relation_right_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 1.0));
+
+ // positive test
+ efl_ui_relative_layout_relation_top_set(layout, btn, layout, 0.123);
+ efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 0.123));
+
+ efl_ui_relative_layout_relation_top_set(layout, btn, NULL, 0.456);
+ efl_ui_relative_layout_relation_top_get(layout, btn, &target, &relative);
+ ck_assert_ptr_eq(target, layout);
+ ck_assert(EINA_DBL_EQ(relative, 0.456));
+}
+EFL_END_TEST
+
void efl_ui_test_relative_layout(TCase *tc)
{
tcase_add_checked_fixture(tc, layout_setup, layout_teardown);
tcase_add_test(tc, efl_ui_relative_layout_class_check);
tcase_add_test(tc, efl_ui_relative_layout_layout_update);
tcase_add_test(tc, efl_ui_relative_layout_layout_update_chain);
+ tcase_add_test(tc, efl_ui_relative_layout_relation_set);
}