From 484a9146479e05946d291e9886cdf3febca6d05d Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Mon, 11 Apr 2022 02:02:12 +0200 Subject: UI: Add support for showing socket descriptions in tooltips Currently, hovering over a socket itself shows no tooltip at all, while hovering over its value field shows "Default value", which is not helpful. This patch therefore implements socket tooltips following the proposal at https://blender.community/c/rightclickselect/2Qgbbc/. A lot of the basic functionality was already implemented for Geometry Nodes, where hovering over the socket itself shows introspection info. This patch extends this by: - Supporting dynamic tooltips on labels, which is important for good tooltip coverage in a socket's region of the node. - Adding a function to setting a dynamic tooltip for an entire uiLayout, which avoids needing to set it manually for a wide variety of socket types. - Hiding the property label field in a tooltip when dynamic tooltip is also provided. If really needed, this label can be restored through the dynamic tooltip, but in all current cases the label is actually pointless anyways since the dynamic tooltip gives more accurate and specific information. - Adding dynamic tooltips to a socket's UI layout row if it has a description configured, both in the Node Editor as well as in the Material Properties. Note that the patch does not add any actual tooltip content yet, just the infrastructure to show them. By default, sockets without a description still show the old "Default value" tooltip. For an example of how to add socket descriptions, check the Cylinder node in the Geometry Nodes. Differential Revision: https://developer.blender.org/D9967 --- source/blender/editors/include/UI_interface.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender/editors/include/UI_interface.h') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index c14cce28052..3f58aab3e53 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -595,6 +595,7 @@ typedef void (*uiMenuHandleFunc)(struct bContext *C, void *arg, int event); */ typedef bool (*uiMenuStepFunc)(struct bContext *C, int direction, void *arg1); +typedef void *(*uiCopyArgFunc)(const void *arg); typedef void (*uiFreeArgFunc)(void *arg); /* interface_query.c */ @@ -2065,6 +2066,24 @@ void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv); void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr); struct bContextStore *uiLayoutGetContextStore(uiLayout *layout); void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context); + +/** + * Set tooltip function for all buttons in the layout. + * func, arg and free_arg are passed on to UI_but_func_tooltip_set, so their meaning is the same. + * + * \param func: The callback function that gets called to get tooltip content + * \param arg: An optional opaque pointer that gets passed to func + * \param free_arg: An optional callback for freeing arg (can be set to e.g. MEM_freeN) + * \param copy_arg: An optional callback for duplicating arg in case UI_but_func_tooltip_set + * is being called on multiple buttons (can be set to e.g. MEM_dupallocN). If set to NULL, arg will + * be passed as-is to all buttons. + */ +void uiLayoutSetTooltipFunc(uiLayout *layout, + uiButToolTipFunc func, + void *arg, + uiCopyArgFunc copy_arg, + uiFreeArgFunc free_arg); + /** * This is a bit of a hack but best keep it in one place at least. */ -- cgit v1.2.3