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:
authorJulian Eisel <julian@blender.org>2021-10-08 15:17:03 +0300
committerJulian Eisel <julian@blender.org>2021-10-08 15:18:10 +0300
commit2aca08fc1cb6448b593afde7b00ba34ce590551b (patch)
tree89ef0a3b3940608d206e988c4829c4086b0b0221 /source/blender/editors/interface/interface.c
parent86643a4e73fc23055cf346213b0569200bee795d (diff)
UI: Support tooltips for superimposed icons
In a couple of places in the UI, we show superimposed icons on buttons to execute an operation (called "Extra Icons" internally). Hovering them would show the tooltip of the underlying button, which is misleading and confusing. There are cases where it's not obvious what an icon does, so a tooltip would be quite useful here. It's likely we are going to use superimposed icons in more places in the future, e.g. see D11890. The extra icon basically acts as an override for the button in the tooltip code. Differential Revision: https://developer.blender.org/D11894 Reviewed by: Campbell Barton
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c84
1 files changed, 77 insertions, 7 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 92391a703ef..68595e49871 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1224,16 +1224,21 @@ void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_str
* \{ */
static bool ui_but_event_operator_string_from_operator(const bContext *C,
- uiBut *but,
+ wmOperatorCallParams *op_call_params,
char *buf,
const size_t buf_len)
{
- BLI_assert(but->optype != NULL);
+ BLI_assert(op_call_params->optype != NULL);
bool found = false;
- IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
-
- if (WM_key_event_operator_string(
- C, but->optype->idname, but->opcontext, prop, true, buf, buf_len)) {
+ IDProperty *prop = (op_call_params->opptr) ? op_call_params->opptr->data : NULL;
+
+ if (WM_key_event_operator_string(C,
+ op_call_params->optype->idname,
+ op_call_params->opcontext,
+ prop,
+ true,
+ buf,
+ buf_len)) {
found = true;
}
return found;
@@ -1318,7 +1323,12 @@ static bool ui_but_event_operator_string(const bContext *C,
bool found = false;
if (but->optype != NULL) {
- found = ui_but_event_operator_string_from_operator(C, but, buf, buf_len);
+ found = ui_but_event_operator_string_from_operator(
+ C,
+ &(wmOperatorCallParams){
+ .optype = but->optype, .opptr = but->opptr, .opcontext = but->opcontext},
+ buf,
+ buf_len);
}
else if (UI_but_menutype_get(but) != NULL) {
found = ui_but_event_operator_string_from_menu(C, but, buf, buf_len);
@@ -1330,6 +1340,20 @@ static bool ui_but_event_operator_string(const bContext *C,
return found;
}
+static bool ui_but_extra_icon_event_operator_string(const bContext *C,
+ uiButExtraOpIcon *extra_icon,
+ char *buf,
+ const size_t buf_len)
+{
+ wmOperatorType *extra_icon_optype = UI_but_extra_operator_icon_optype_get(extra_icon);
+
+ if (extra_icon_optype) {
+ return ui_but_event_operator_string_from_operator(C, extra_icon->optype_params, buf, buf_len);
+ }
+
+ return false;
+}
+
static bool ui_but_event_property_operator_string(const bContext *C,
uiBut *but,
char *buf,
@@ -1713,6 +1737,16 @@ PointerRNA *UI_but_extra_operator_icon_add(uiBut *but,
return NULL;
}
+wmOperatorType *UI_but_extra_operator_icon_optype_get(uiButExtraOpIcon *extra_icon)
+{
+ return extra_icon ? extra_icon->optype_params->optype : NULL;
+}
+
+PointerRNA *UI_but_extra_operator_icon_opptr_get(uiButExtraOpIcon *extra_icon)
+{
+ return extra_icon->optype_params->opptr;
+}
+
static bool ui_but_icon_extra_is_visible_text_clear(const uiBut *but)
{
BLI_assert(but->type == UI_BTYPE_TEXT);
@@ -7262,6 +7296,42 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
}
}
+void UI_but_extra_icon_string_info_get(struct bContext *C, uiButExtraOpIcon *extra_icon, ...)
+{
+ va_list args;
+ uiStringInfo *si;
+
+ wmOperatorType *optype = UI_but_extra_operator_icon_optype_get(extra_icon);
+ PointerRNA *opptr = UI_but_extra_operator_icon_opptr_get(extra_icon);
+
+ va_start(args, extra_icon);
+ while ((si = (uiStringInfo *)va_arg(args, void *))) {
+ char *tmp = NULL;
+
+ switch (si->type) {
+ case BUT_GET_LABEL:
+ tmp = BLI_strdup(WM_operatortype_name(optype, opptr));
+ break;
+ case BUT_GET_TIP:
+ tmp = WM_operatortype_description(C, optype, opptr);
+ break;
+ case BUT_GET_OP_KEYMAP: {
+ char buf[128];
+ if (ui_but_extra_icon_event_operator_string(C, extra_icon, buf, sizeof(buf))) {
+ tmp = BLI_strdup(buf);
+ }
+ }
+ /* Other types not supported. The caller should expect that outcome, no need to message or
+ * assert here. */
+ default:
+ break;
+ }
+
+ si->strinfo = tmp;
+ }
+ va_end(args);
+}
+
/* Program Init/Exit */
void UI_init(void)