From 35e1e6a988974c759d5cdf0b125e14f2a522d50c Mon Sep 17 00:00:00 2001 From: abhi Date: Thu, 28 Nov 2013 00:27:13 +0900 Subject: [PATCH] tooltip: Adding elm_object_tooltip_orient_set API Summary: Eight fixed orientations provided to orient tooltip around event area Test Plan: elementary_test -to tooltip, elm_object_tooltip_orient_set Reviewers: seoz, singh.amitesh, Anusha Reviewed By: seoz CC: Anusha Differential Revision: https://phab.enlightenment.org/D326 --- legacy/elementary/ChangeLog | 4 + legacy/elementary/NEWS | 2 + legacy/elementary/src/bin/test_tooltip.c | 93 ++++++++++++++++++++++++ legacy/elementary/src/lib/elm_tooltip.h | 52 +++++++++++++ legacy/elementary/src/lib/els_tooltip.c | 85 +++++++++++++++++++++- 5 files changed, 234 insertions(+), 2 deletions(-) diff --git a/legacy/elementary/ChangeLog b/legacy/elementary/ChangeLog index 6703d47732..3bd6bf0ed0 100644 --- a/legacy/elementary/ChangeLog +++ b/legacy/elementary/ChangeLog @@ -1760,3 +1760,7 @@ 2013-11-28 Daniel Juyung Seo (SeoZ) * spinner: fix mouse wheel support. + +2013-12-01 Abhinandan Aryadipta (aryarockstar) + + * tooltip: Added elm_object_tooltip_orient_set() and elm_object_tooltip_orient_get(). diff --git a/legacy/elementary/NEWS b/legacy/elementary/NEWS index 6d973a5882..3fd7969ed2 100644 --- a/legacy/elementary/NEWS +++ b/legacy/elementary/NEWS @@ -3,6 +3,8 @@ Changes since Elementary 1.8.0: Additions: + * Add elm_object_tooltip_orient_set() and elm_object_tooltip_orient_get(). + Improvements: Fixes: diff --git a/legacy/elementary/src/bin/test_tooltip.c b/legacy/elementary/src/bin/test_tooltip.c index 241f04f783..70de973d2e 100644 --- a/legacy/elementary/src/bin/test_tooltip.c +++ b/legacy/elementary/src/bin/test_tooltip.c @@ -200,6 +200,91 @@ _tt_text_replace(void *data EINA_UNUSED, elm_object_tooltip_text_set(obj, buf); } +static void +_tt_orient_text_replace(void *data EINA_UNUSED, + Evas_Object *obj, + void *event_info EINA_UNUSED) +{ + static Elm_Tooltip_Orient orient; + + orient = elm_object_tooltip_orient_get(obj); + orient++; + if (orient >= ELM_TOOLTIP_ORIENT_LAST) + orient = ELM_TOOLTIP_ORIENT_TOP_LEFT; + switch(orient) + { + case ELM_TOOLTIP_ORIENT_TOP_LEFT: + { + elm_object_tooltip_text_set(obj, "Top Left"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP_LEFT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP_LEFT\n"); + break; + } + case ELM_TOOLTIP_ORIENT_TOP: + { + elm_object_tooltip_text_set(obj, "Top"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP\n"); + break; + } + case ELM_TOOLTIP_ORIENT_TOP_RIGHT: + { + elm_object_tooltip_text_set(obj, "Top Right"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_TOP_RIGHT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_TOP_RIGHT\n"); + break; + } + case ELM_TOOLTIP_ORIENT_LEFT: + { + elm_object_tooltip_text_set(obj, "Left"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_LEFT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_LEFT\n"); + break; + } + case ELM_TOOLTIP_ORIENT_CENTER: + { + elm_object_tooltip_text_set(obj, "Center"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_CENTER); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_CENTER\n"); + break; + } + case ELM_TOOLTIP_ORIENT_RIGHT: + { + elm_object_tooltip_text_set(obj, "Right"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_RIGHT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_RIGHT\n"); + break; + } + case ELM_TOOLTIP_ORIENT_BOTTOM_LEFT: + { + elm_object_tooltip_text_set(obj, "Bottom Left"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_BOTTOM_LEFT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_BOTTOM_LEFT\n"); + break; + } + case ELM_TOOLTIP_ORIENT_BOTTOM: + { + elm_object_tooltip_text_set(obj, "Bottom"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_BOTTOM); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_BOTTOM\n"); + break; + } + case ELM_TOOLTIP_ORIENT_BOTTOM_RIGHT: + { + elm_object_tooltip_text_set(obj, "Bottom Right"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_BOTTOM_RIGHT); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_BOTTOM_RIGHT\n"); + break; + } + default: + { + elm_object_tooltip_text_set(obj, "No Orientation"); + elm_object_tooltip_orient_set(obj, ELM_TOOLTIP_ORIENT_NONE); + printf("elm_object_tooltip_orient_get :: Orientation: ELM_TOOLTIP_ORIENT_NONE\n"); + } + }; +} + static void _tt_timer_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, @@ -404,6 +489,14 @@ test_tooltip(void *data EINA_UNUSED, elm_box_pack_end(bx, bt); evas_object_show(bt); + bt = elm_button_add(win); + elm_object_text_set(bt, "Orient Tooltip, click to change"); + elm_object_tooltip_text_set(bt, "Top Left"); + elm_object_tooltip_orient_set(bt, ELM_TOOLTIP_ORIENT_TOP_LEFT); + evas_object_smart_callback_add(bt, "clicked", _tt_orient_text_replace, NULL); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + bt = elm_button_add(win); elm_object_text_set(bt, "Simple text tooltip, click to change"); elm_object_tooltip_text_set(bt, "Initial"); diff --git a/legacy/elementary/src/lib/elm_tooltip.h b/legacy/elementary/src/lib/elm_tooltip.h index 3daf1c7ea5..21bbfcd466 100644 --- a/legacy/elementary/src/lib/elm_tooltip.h +++ b/legacy/elementary/src/lib/elm_tooltip.h @@ -9,6 +9,58 @@ * @{ */ +/** + * @brief Possible orient values for tooltip. + * + * These values should be used in conjunction to elm_object_tooltip_orient_set() to + * set the position around which the tooltip should appear(relative to its parent) + * + * @ingroup Tooltips + */ +typedef enum +{ + ELM_TOOLTIP_ORIENT_NONE = 0, /**< Default value, Tooltip moves with mouse pointer */ + ELM_TOOLTIP_ORIENT_TOP_LEFT, /**< Tooltip should appear at the top left of parent */ + ELM_TOOLTIP_ORIENT_TOP, /**< Tooltip should appear at the top of parent */ + ELM_TOOLTIP_ORIENT_TOP_RIGHT, /**< Tooltip should appear at the top right of parent */ + ELM_TOOLTIP_ORIENT_LEFT, /**< Tooltip should appear at the left of parent */ + ELM_TOOLTIP_ORIENT_CENTER, /**< Tooltip should appear at the center of parent */ + ELM_TOOLTIP_ORIENT_RIGHT, /**< Tooltip should appear at the right of parent */ + ELM_TOOLTIP_ORIENT_BOTTOM_LEFT, /**< Tooltip should appear at the bottom left of parent */ + ELM_TOOLTIP_ORIENT_BOTTOM, /**< Tooltip should appear at the bottom of parent */ + ELM_TOOLTIP_ORIENT_BOTTOM_RIGHT, /**< Tooltip should appear at the bottom right of parent */ + ELM_TOOLTIP_ORIENT_LAST /**< Sentinel value, @b don't use */ + } Elm_Tooltip_Orient; + +/** + * @def elm_object_tooltip_orient_set + * @since 1.9 + * + * @brief Sets the orientation of the tooltip around the owner region + * + * Sets the position in which tooltip will appear around its owner. By default, + * #ELM_TOOLTIP_ORIENT_NONE is set. + * + * @param[in] obj owner widget. + * @param[in] orient orientation. + * + * @ingroup Tooltips + * @see @ref Elm_Tooltip_Orient for possible values. + */ +EAPI void elm_object_tooltip_orient_set(Evas_Object *obj, Elm_Tooltip_Orient orient); + +/** + * @brief Returns the orientation of Tooltip + * + * @param obj The owner object + * @return The orientation of the tooltip + * + * @ingroup Tooltips + * @see elm_object_tooltip_orient_set() + * @ref Elm_Tooltip_Orient for possible values. + */ +EAPI Elm_Tooltip_Orient elm_object_tooltip_orient_get(const Evas_Object *obj); + /** * Called back when a widget's tooltip is activated and needs content. * @param data user-data given to elm_object_tooltip_content_cb_set() diff --git a/legacy/elementary/src/lib/els_tooltip.c b/legacy/elementary/src/lib/els_tooltip.c index 9f5dd58d70..63cbb57f09 100644 --- a/legacy/elementary/src/lib/els_tooltip.c +++ b/legacy/elementary/src/lib/els_tooltip.c @@ -56,6 +56,7 @@ struct _Elm_Tooltip { double x, y; } rel_pos; + Elm_Tooltip_Orient orient; /** orientation for tooltip */ double hide_timeout; /* from theme */ Eina_Bool visible_lock:1; Eina_Bool changed_style:1; @@ -155,8 +156,12 @@ _elm_tooltip_show(Elm_Tooltip *tt) (tt->eventarea, EVAS_CALLBACK_MOVE, _elm_tooltip_obj_move_cb, tt); evas_object_event_callback_add (tt->eventarea, EVAS_CALLBACK_RESIZE, _elm_tooltip_obj_resize_cb, tt); - evas_object_event_callback_add - (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_move_cb, tt); + //No movement of tooltip upon mouse move if orientation set + if ((tt->orient <= ELM_TOOLTIP_ORIENT_NONE) || (tt->orient >= ELM_TOOLTIP_ORIENT_LAST)) + { + evas_object_event_callback_add + (tt->eventarea, EVAS_CALLBACK_MOUSE_MOVE, (Evas_Object_Event_Cb)_elm_tooltip_obj_mouse_move_cb, tt); + } tt->changed_style = EINA_TRUE; _elm_tooltip_reconfigure_job_start(tt); @@ -520,6 +525,60 @@ _elm_tooltip_reconfigure(Elm_Tooltip *tt) msg = alloca(sizeof(Edje_Message_Float_Set) + sizeof(double)); msg->count = 2; + //Orient calculations if orient set + switch(tt->orient) + { + case ELM_TOOLTIP_ORIENT_TOP_LEFT: + evas_object_move(tt->tooltip, ox - tw, oy - th); + rel_x = 1.1; + rel_y = 1.1; + break; + case ELM_TOOLTIP_ORIENT_TOP: + evas_object_move(tt->tooltip, ox + ((ow - tw) / 2), oy - th); + rel_x = 0.5; + rel_y = 1.1; + break; + case ELM_TOOLTIP_ORIENT_TOP_RIGHT: + evas_object_move(tt->tooltip, ox + ow, oy - th); + rel_x = -1.1; + rel_y = 1.1; + break; + case ELM_TOOLTIP_ORIENT_LEFT: + evas_object_move(tt->tooltip, ox - tw, oy + ((oh - th) / 2)); + rel_x = 1.1; + rel_y = 0.5; + break; + case ELM_TOOLTIP_ORIENT_CENTER: + evas_object_move(tt->tooltip, ox + ((ow - tw) / 2), oy + ((oh - th) / 2)); + rel_x = 0.5; + rel_y = 0.5; + break; + case ELM_TOOLTIP_ORIENT_RIGHT: + evas_object_move(tt->tooltip, ox + ow, oy + ((oh - th) / 2)); + rel_x = -1.1; + rel_y = 0.5; + break; + case ELM_TOOLTIP_ORIENT_BOTTOM_LEFT: + evas_object_move(tt->tooltip, ox - tw, oy + oh); + rel_x = 1.1; + rel_y = -1.1; + break; + case ELM_TOOLTIP_ORIENT_BOTTOM: + evas_object_move(tt->tooltip, ox + ((ow - tw) / 2), oy + oh); + rel_x = 0.5; + rel_y = -1.1; + break; + case ELM_TOOLTIP_ORIENT_BOTTOM_RIGHT: + evas_object_move(tt->tooltip, ox + ow, oy + oh); + rel_x = -1.1; + rel_y = -1.1; + break; + default: + { /*Do Nothing!!*/ + } + }; + evas_object_show(tt->tooltip); + msg->val[0] = rel_x; msg->val[1] = rel_y; tt->rel_pos.x = rel_x; @@ -665,6 +724,28 @@ _elm_tooltip_data_clean(Elm_Tooltip *tt) tt->del_cb = NULL; } +EAPI void +elm_object_tooltip_orient_set(Evas_Object *obj, Elm_Tooltip_Orient orient) +{ + ELM_TOOLTIP_GET_OR_RETURN(tt, obj); + + if ((orient > ELM_TOOLTIP_ORIENT_NONE) && (orient < ELM_TOOLTIP_ORIENT_LAST)) + tt->orient = orient; + else + tt->orient = ELM_TOOLTIP_ORIENT_NONE; +} + +EAPI Elm_Tooltip_Orient +elm_object_tooltip_orient_get(const Evas_Object *obj) +{ + ELM_TOOLTIP_GET_OR_RETURN(tt, obj, ELM_TOOLTIP_ORIENT_NONE); + + Elm_Tooltip_Orient orient = ELM_TOOLTIP_ORIENT_NONE; + + orient = tt->orient; + return orient; +} + /** * Notify tooltip should recalculate its theme. * @internal