From: Enlightenment S. <no-...@en...> - 2010-09-11 00:52:40
|
Log: Welcome Tooltips. Tooltips are set using elm_object_tooltip_content_cb_set(), that returns the desired Evas_Object to use as contents, or using the helper function elm_object_tooltip_text_set() that uses that underneath. The behavior is controlled part on elm_config, theme and user application. In elm_config one defines the tooltip timeout. The theme defines the padding around cursor x/y and window border x/y, as well as the look and feel. Last but not least, the user application may want to change the tooltip style with elm_object_tooltip_style_set(). Have fun! This code was initially written by Tiago Falcao and Fabiano Fidencio, I did some API review and changed some bits. TODO: elm widget item support, like with toolbar items. Author: barbieri Date: 2010-09-10 17:52:33 -0700 (Fri, 10 Sep 2010) New Revision: 52150 Added: trunk/TMP/st/elementary/src/bin/test_tooltip.c trunk/TMP/st/elementary/src/lib/els_tooltip.c Modified: trunk/TMP/st/elementary/config/default/base.src trunk/TMP/st/elementary/config/illume/base.src trunk/TMP/st/elementary/config/standard/base.src trunk/TMP/st/elementary/data/themes/default.edc trunk/TMP/st/elementary/src/bin/Makefile.am trunk/TMP/st/elementary/src/bin/test.c trunk/TMP/st/elementary/src/lib/Elementary.h.in trunk/TMP/st/elementary/src/lib/Makefile.am trunk/TMP/st/elementary/src/lib/elm_config.c trunk/TMP/st/elementary/src/lib/elm_priv.h trunk/TMP/st/elementary/src/lib/elm_widget.c Modified: trunk/TMP/st/elementary/config/default/base.src =================================================================== --- trunk/TMP/st/elementary/config/default/base.src 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/config/default/base.src 2010-09-11 00:52:33 UTC (rev 52150) @@ -20,4 +20,5 @@ value "fps" double: 60.0; value "theme" string: "default"; value "modules" string: ""; + value "tooltip_delay" double: 1.0; } Modified: trunk/TMP/st/elementary/config/illume/base.src =================================================================== --- trunk/TMP/st/elementary/config/illume/base.src 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/config/illume/base.src 2010-09-11 00:52:33 UTC (rev 52150) @@ -20,4 +20,5 @@ value "fps" double: 60.0; value "theme" string: "default"; value "modules" string: ""; + value "tooltip_delay" double: 1.0; } Modified: trunk/TMP/st/elementary/config/standard/base.src =================================================================== --- trunk/TMP/st/elementary/config/standard/base.src 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/config/standard/base.src 2010-09-11 00:52:33 UTC (rev 52150) @@ -20,4 +20,5 @@ value "fps" double: 60.0; value "theme" string: "default"; value "modules" string: ""; + value "tooltip_delay" double: 1.0; } Modified: trunk/TMP/st/elementary/data/themes/default.edc =================================================================== --- trunk/TMP/st/elementary/data/themes/default.edc 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/data/themes/default.edc 2010-09-11 00:52:33 UTC (rev 52150) @@ -4425,6 +4425,90 @@ } /////////////////////////////////////////////////////////////////////////////// + group { name: "elm/tooltip/base/default"; + //this group is a design similar to the inwin group + data { + item: "pad_x" "5"; + item: "pad_y" "5"; + item: "pad_border_x" "10"; + item: "pad_border_y" "10"; + } + images { + image: "shad_circ.png" COMP; + image: "bt_dis_base.png" COMP; + image: "bt_dis_hilight.png" COMP; + } + parts { + part { name: "base"; + type: RECT; + mouse_events: 0; + repeat_events: 1; + description { state: "default" 0.0; + color: 0 0 0 64; + rel1.offset: 10 10; + rel2.offset: -10 -10; + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + } + part { name: "shad"; + mouse_events: 0; + description { state: "default" 0.0; + image.normal: "shad_circ.png"; + rel1.to: "elm.swallow.content"; + rel1.offset: -64 -64; + rel2.to: "elm.swallow.content"; + rel2.offset: 63 63; + fill.smooth: 0; + } + } + part { name: "pop"; + mouse_events: 1; + description { state: "default" 0.0; + rel1.to: "elm.swallow.content"; + rel1.offset: -5 -5; + rel2.to: "elm.swallow.content"; + rel2.offset: 4 4; + image { + normal: "bt_dis_base.png"; + border: 4 4 4 4; + } + image.middle: SOLID; + } + } + part { name: "popover"; + mouse_events: 0; + description { state: "default" 0.0; + rel1.to: "pop"; + rel2.to: "pop"; + rel2.relative: 1.0 0.5; + image { + normal: "bt_dis_hilight.png"; + border: 4 4 4 0; + } + } + } + part { name: "elm.swallow.content"; + type: SWALLOW; + description { state: "default" 0.0; + rel1.to: "base"; + rel2.to: "base"; + } + } + } + } + group { name: "elm/tooltip/base/transparent"; + parts { + part { name: "elm.swallow.content"; + type: SWALLOW; + mouse_events: 0; + scale: 1; + description { state: "default" 0.0; } + } + } + } + +/////////////////////////////////////////////////////////////////////////////// group { name: "elm/hover/base/default"; images { image: "shad_circ.png" COMP; Modified: trunk/TMP/st/elementary/src/bin/Makefile.am =================================================================== --- trunk/TMP/st/elementary/src/bin/Makefile.am 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/bin/Makefile.am 2010-09-11 00:52:33 UTC (rev 52150) @@ -81,7 +81,8 @@ test_launcher.c \ test_anim.c \ test_calendar.c \ -test_drag.c +test_drag.c \ +test_tooltip.c elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la @ELEMENTARY_EWEATHER_LIBS@ elementary_test_LDFLAGS = Modified: trunk/TMP/st/elementary/src/bin/test.c =================================================================== --- trunk/TMP/st/elementary/src/bin/test.c 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/bin/test.c 2010-09-11 00:52:33 UTC (rev 52150) @@ -80,6 +80,7 @@ void test_launcher2(void *data, Evas_Object *obj, void *event_info); void test_launcher3(void *data, Evas_Object *obj, void *event_info); void test_anim(void *data, Evas_Object *obj, void *event_info); +void test_tooltip(void *data, Evas_Object *obj, void *event_info); void test_drag_source(void *data, Evas_Object *obj, void *event_info); void test_drag_dest(void *data, Evas_Object *obj, void *event_info); @@ -288,6 +289,7 @@ ADD_TEST("Animation", test_anim); ADD_TEST("Calendar", test_calendar); ADD_TEST("Calendar 2", test_calendar2); + ADD_TEST("Tooltip", test_tooltip); #undef ADD_TEST if (autorun) Modified: trunk/TMP/st/elementary/src/lib/Elementary.h.in =================================================================== --- trunk/TMP/st/elementary/src/lib/Elementary.h.in 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/lib/Elementary.h.in 2010-09-11 00:52:33 UTC (rev 52150) @@ -224,6 +224,7 @@ ELM_CLOCK_ALL = (1 << 6) - 1 } Elm_Clock_Digedit; + #ifndef ELM_LIB_QUICKLAUNCH #define ELM_MAIN() int main(int argc, char **argv) {elm_init(argc, argv); return elm_main(argc, argv);} #else @@ -978,6 +979,24 @@ * "clicked" - when the user clicks on a toolbar item and becomes selected */ + typedef Evas_Object *(*Elm_Tooltip_Content_Cb) (void *data, Evas_Object *obj); + + /* available styles: + * default + * transparent (no background or shadow, just show the provided content) + */ + EAPI double elm_tooltip_delay_get(void); + EAPI Eina_Bool elm_tooltip_delay_set(double delay); + EAPI void elm_object_tooltip_show(Evas_Object *obj); + EAPI void elm_object_tooltip_hide(Evas_Object *obj); + EAPI void elm_object_tooltip_text_set(Evas_Object *obj, const char *text); + EAPI void elm_object_tooltip_content_cb_set(Evas_Object *obj, Elm_Tooltip_Content_Cb func, const void *data, Evas_Smart_Cb del_cb); + EAPI void elm_object_tooltip_unset(Evas_Object *obj); + + EAPI void elm_object_tooltip_style_set(Evas_Object *obj, const char *style); + EAPI const char *elm_object_tooltip_style_get(const Evas_Object *obj); + + typedef struct _Elm_Menu_Item Elm_Menu_Item; EAPI Evas_Object *elm_menu_add(Evas_Object *parent); EAPI void elm_menu_parent_set(Evas_Object *obj, Evas_Object *parent); Modified: trunk/TMP/st/elementary/src/lib/Makefile.am =================================================================== --- trunk/TMP/st/elementary/src/lib/Makefile.am 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/lib/Makefile.am 2010-09-11 00:52:33 UTC (rev 52150) @@ -88,6 +88,7 @@ elc_notepad.c \ elc_scrolled_entry.c \ \ +els_tooltip.c \ els_pan.c \ els_pan.h \ els_scroller.c \ Modified: trunk/TMP/st/elementary/src/lib/elm_config.c =================================================================== --- trunk/TMP/st/elementary/src/lib/elm_config.c 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/lib/elm_config.c 2010-09-11 00:52:33 UTC (rev 52150) @@ -224,6 +224,7 @@ EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "fps", fps, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "theme", theme, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "modules", modules, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "tooltip_delay", tooltip_delay, EET_T_DOUBLE); } static void @@ -404,6 +405,7 @@ _elm_config->fps = 60.0; _elm_config->theme = eina_stringshare_add("default"); _elm_config->modules = NULL; + _elm_config->tooltip_delay = 1.0; } static void @@ -588,6 +590,14 @@ s = getenv("ELM_MODULES"); if (s) eina_stringshare_replace(&_elm_config->modules, s); + + s = getenv("ELM_TOOLTIP_DELAY"); + if (s) + { + double delay = atof(s); + if (delay >= 0.0) + _elm_config->tooltip_delay = delay; + } } void Modified: trunk/TMP/st/elementary/src/lib/elm_priv.h =================================================================== --- trunk/TMP/st/elementary/src/lib/elm_priv.h 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/lib/elm_priv.h 2010-09-11 00:52:33 UTC (rev 52150) @@ -91,6 +91,7 @@ double fps; const char *theme; const char *modules; + double tooltip_delay; }; typedef struct _Elm_Module Elm_Module; @@ -217,6 +218,10 @@ EAPI Eina_Bool elm_widget_is(const Evas_Object *obj); EAPI Evas_Object *elm_widget_parent_widget_get(const Evas_Object *obj); +typedef struct _Elm_Tooltip Elm_Tooltip; +void elm_widget_tooltip_set(Evas_Object *obj, Elm_Tooltip *tt); +void elm_tooltip_theme(Elm_Tooltip *tt); + EAPI Eina_List *_elm_stringlist_get(const char *str); EAPI void _elm_stringlist_free(Eina_List *list); Modified: trunk/TMP/st/elementary/src/lib/elm_widget.c =================================================================== --- trunk/TMP/st/elementary/src/lib/elm_widget.c 2010-09-10 23:00:26 UTC (rev 52149) +++ trunk/TMP/st/elementary/src/lib/elm_widget.c 2010-09-11 00:52:33 UTC (rev 52150) @@ -21,6 +21,7 @@ Eina_List *subobjs; Evas_Object *resize_obj; Evas_Object *hover_obj; + Elm_Tooltip *tooltip; void (*del_func) (Evas_Object *obj); void (*del_pre_func) (Evas_Object *obj); void (*focus_func) (Evas_Object *obj); @@ -203,6 +204,7 @@ elm_widget_theme(child); if (sd->resize_obj) elm_widget_theme(sd->resize_obj); if (sd->hover_obj) elm_widget_theme(sd->hover_obj); + if (sd->tooltip) elm_tooltip_theme(sd->tooltip); if (sd->theme_func) sd->theme_func(obj); } @@ -1017,6 +1019,12 @@ return ""; } +void +elm_widget_tooltip_set(Evas_Object *obj, Elm_Tooltip *tt) +{ + API_ENTRY return; + sd->tooltip = tt; +} |