Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2022-04-11 03:02:12 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2022-04-12 00:40:48 +0300
commit484a9146479e05946d291e9886cdf3febca6d05d (patch)
tree977dfae2383938826d27cfcf6827031f9c50ff9a /source/blender/editors/interface
parentb3525c3487ca893aac5bb8241ce154f491508224 (diff)
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
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_layout.c35
-rw-r--r--source/blender/editors/interface/interface_query.cc2
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c6
3 files changed, 40 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index ac807f06891..3e8bae6ea6b 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -5681,6 +5681,41 @@ void uiLayoutContextCopy(uiLayout *layout, bContextStore *context)
layout->context = CTX_store_add_all(&block->contexts, context);
}
+void uiLayoutSetTooltipFunc(uiLayout *layout,
+ uiButToolTipFunc func,
+ void *arg,
+ uiCopyArgFunc copy_arg,
+ uiFreeArgFunc free_arg)
+{
+ bool arg_used = false;
+
+ LISTBASE_FOREACH (uiItem *, item, &layout->items) {
+ /* Each button will call free_arg for "its" argument, so we need to
+ * duplicate the allocation for each button after the first. */
+ if (copy_arg != NULL && arg_used) {
+ arg = copy_arg(arg);
+ }
+ arg_used = true;
+
+ if (item->type == ITEM_BUTTON) {
+ uiButtonItem *bitem = (uiButtonItem *)item;
+ if (bitem->but->type == UI_BTYPE_DECORATOR) {
+ continue;
+ }
+ UI_but_func_tooltip_set(bitem->but, func, arg, free_arg);
+ }
+ else {
+ uiLayoutSetTooltipFunc(
+ (uiLayout *)item, func, arg, copy_arg, free_arg);
+ }
+ }
+
+ if (!arg_used) {
+ /* Free the original copy of arg in case the layout is empty. */
+ free_arg(arg);
+ }
+}
+
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but)
{
if (but->opptr) {
diff --git a/source/blender/editors/interface/interface_query.cc b/source/blender/editors/interface/interface_query.cc
index 2767a184619..337b2852d57 100644
--- a/source/blender/editors/interface/interface_query.cc
+++ b/source/blender/editors/interface/interface_query.cc
@@ -61,7 +61,7 @@ bool ui_but_is_toggle(const uiBut *but)
bool ui_but_is_interactive(const uiBut *but, const bool labeledit)
{
/* NOTE: #UI_BTYPE_LABEL is included for highlights, this allows drags. */
- if ((but->type == UI_BTYPE_LABEL) && but->dragpoin == nullptr) {
+ if ((but->type == UI_BTYPE_LABEL) && but->dragpoin == nullptr && but->tip_func == nullptr) {
return false;
}
if (ELEM(but->type, UI_BTYPE_ROUNDBOX, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_LISTBOX)) {
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 29553ff65d1..ca18ec14a54 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -788,8 +788,10 @@ static uiTooltipData *ui_tooltip_data_from_button_or_extra_icon(bContext *C,
}
/* Tip Label (only for buttons not already showing the label).
- * Check prefix instead of comparing because the button may include the shortcut. */
- if (but_label.strinfo && !STRPREFIX(but->drawstr, but_label.strinfo)) {
+ * Check prefix instead of comparing because the button may include the shortcut.
+ * Buttons with dynamic tooltips also don't get their default label here since they
+ * can already provide more accurate and specific tooltip content. */
+ if (but_label.strinfo && !STRPREFIX(but->drawstr, but_label.strinfo) && !but->tip_func) {
uiTooltipField *field = text_field_add(data,
&(uiTooltipFormat){
.style = UI_TIP_STYLE_HEADER,