From fdb27aa211a5a57430883cbec15228a6abd46b7e Mon Sep 17 00:00:00 2001 From: Minkyu Kang Date: Mon, 27 Feb 2017 20:13:06 +0900 Subject: [PATCH] elementary tooltip: adjust arrow if tooltip was moved Summary: If orientation is TOP, BOTTOM, LEFT and RIGHT and tooltip was moved due to located out of screen, adjust location of arrow so that can indicate right position. Signed-off-by: Minkyu Kang Test Plan: elementary_test -to tooltip4 Reviewers: cedric, Hermet, jpeg Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D4554 Change-Id: I40854c2d4c0e8f435b00e5914eb23d491e02154b --- src/bin/test.c | 2 ++ src/bin/test_tooltip.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/els_tooltip.c | 54 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/src/bin/test.c b/src/bin/test.c index 1a9f883..f91bec3 100644 --- a/src/bin/test.c +++ b/src/bin/test.c @@ -207,6 +207,7 @@ void test_anim(void *data, Evas_Object *obj, void *event_info); void test_tooltip(void *data, Evas_Object *obj, void *event_info); void test_tooltip2(void *data, Evas_Object *obj, void *event_info); void test_tooltip3(void *data, Evas_Object *obj, void *event_info); +void test_tooltip4(void *data, Evas_Object *obj, void *event_info); void test_cursor(void *data, Evas_Object *obj, void *event_info); void test_cursor2(void *data, Evas_Object *obj, void *event_info); void test_cursor3(void *data, Evas_Object *obj, void *event_info); @@ -801,6 +802,7 @@ add_tests: ADD_TEST(NULL, "Popups", "Tooltip", test_tooltip); ADD_TEST(NULL, "Popups", "Tooltip 2", test_tooltip2); ADD_TEST(NULL, "Popups", "Tooltip 3", test_tooltip3); + ADD_TEST(NULL, "Popups", "Tooltip 4", test_tooltip4); ADD_TEST(NULL, "Popups", "Popup", test_popup); //------------------------------// diff --git a/src/bin/test_tooltip.c b/src/bin/test_tooltip.c index 2329067..e105b1e 100644 --- a/src/bin/test_tooltip.c +++ b/src/bin/test_tooltip.c @@ -743,3 +743,60 @@ test_tooltip3(void *data EINA_UNUSED, evas_object_resize(win, 300, 300); evas_object_show(win); } + +void +test_tooltip4(void *data EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Evas_Object *win, *bt; + + win = elm_win_util_standard_add("tooltip4", "Tooltip 4"); + elm_win_autodel_set(win, EINA_TRUE); + evas_object_resize(win, 300, 300); + evas_object_show(win); + + bt = elm_button_add(win); + elm_object_tooltip_text_set(bt, "Tooltip!!!!!!!!!!!!!!!!!!"); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_BOTTOM); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 5, 5); + evas_object_show(bt); + + bt = elm_button_add(win); + elm_object_tooltip_text_set(bt, "Tooltip!!!!!!!!!!!!!!!!!!"); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_BOTTOM); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 250, 5); + evas_object_show(bt); + + bt = elm_button_add(win); + elm_object_tooltip_text_set(bt, "Tooltip!!!!!!!!!!!!!!!!!!"); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 25, 265); + evas_object_show(bt); + + bt = elm_button_add(win); + elm_object_tooltip_text_set(bt, "Tooltip!!!!!!!!!!!!!!!!!!"); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 235, 265); + evas_object_show(bt); + + bt = elm_button_add(win); + elm_object_tooltip_content_cb_set(bt, _tt_icon, (void *)123L, + _tt_icon_del); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_RIGHT); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 135, 5); + evas_object_show(bt); + + bt = elm_button_add(win); + elm_object_tooltip_content_cb_set(bt, _tt_icon, (void *)123L, + _tt_icon_del); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_LEFT); + evas_object_resize(bt, 30, 30); + evas_object_move(bt, 135, 255); + evas_object_show(bt); +} diff --git a/src/lib/els_tooltip.c b/src/lib/els_tooltip.c index 46960ba..87397b1 100644 --- a/src/lib/els_tooltip.c +++ b/src/lib/els_tooltip.c @@ -281,6 +281,9 @@ _elm_tooltip_reconfigure_orient(Elm_Tooltip *tt, Evas_Coord tw, Evas_Coord th, Evas_Coord cw, Evas_Coord ch) { Evas_Coord mx, my; + Evas_Coord dx, dy; + Evas_Coord tcw, tch; + Evas_Coord px, py; switch (tt->orient) { @@ -342,11 +345,54 @@ _elm_tooltip_reconfigure_orient(Elm_Tooltip *tt, return; } - if (mx < 0) mx = 0; - else if (mx + tw > cw) mx = cw - tw; + evas_object_geometry_get(tt->content, NULL, NULL, &tcw, &tch); + if (tcw <= 0 || tcw > tw) tcw = tw; + if (tch <= 0 || tch > th) tch = th; - if (my < 0) my = 0; - else if (my + th > ch) my = ch - th; + px = (tw - tcw) / 2; + py = (th - tch) / 2; + + if (mx < 0) + { + dx = -mx; + mx = -(px / 2); + if (tt->rel_pos.x == 0.5) + { + tt->rel_pos.x = 0.5 - dx / (double)tcw; + if (tt->rel_pos.x < 0.0) tt->rel_pos.x = 0.0; + } + } + else if (mx + tw > cw) + { + dx = mx + tw - cw; + mx = cw - tw + px / 2; + if (tt->rel_pos.x == 0.5) + { + tt->rel_pos.x = 0.5 + dx / (double)tcw; + if (tt->rel_pos.x > 1.0) tt->rel_pos.x = 1.0; + } + } + + if (my < 0) + { + dy = -my; + my = -(py / 2); + if (tt->rel_pos.y == 0.5) + { + tt->rel_pos.y = 0.5 - dy / (double)tch; + if (tt->rel_pos.y < 0.0) tt->rel_pos.y = 0.0; + } + } + else if (my + th > ch) + { + dy = my + th - ch; + my = ch - th + py / 2; + if (tt->rel_pos.y == 0.5) + { + tt->rel_pos.y = 0.5 + dy / (double)tch; + if (tt->rel_pos.y > 1.0) tt->rel_pos.y = 1.0; + } + } evas_object_move(tt->tooltip, mx, my); evas_object_show(tt->tooltip); -- 2.7.4