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 17:17:29 +0300
committerJulian Eisel <julian@blender.org>2021-10-08 17:31:16 +0300
commitff57ce86170d2e440d2e0566bf3c4a74bb745b32 (patch)
tree9f134c05c3d3fc77a9fe3b6a089c6b84b33f264e /source/blender/editors/interface/interface.c
parent38c4888f0999ee5361dc76d2b9a7cd45e8ae2896 (diff)
UI: Support showing superimposed icons as disabled (with disabled hint)
If the operator poll of a superimposed icon returned `false`, the superimposed icon would just draw normally and fail silently. Instead it will now be drawn grayed out, plus the tooltip of the icon can show the usual "disabled hint" (a hint explaining why the button is disabled).
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 68595e49871..07bb9040da8 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1701,6 +1701,7 @@ static PointerRNA *ui_but_extra_operator_icon_add_ptr(uiBut *but,
extra_op_icon->optype_params->optype);
extra_op_icon->optype_params->opcontext = opcontext;
extra_op_icon->highlighted = false;
+ extra_op_icon->disabled = false;
BLI_addtail(&but->extra_op_icons, extra_op_icon);
@@ -1905,18 +1906,19 @@ static void ui_but_validate(const uiBut *but)
/**
* Check if the operator \a ot poll is successful with the context given by \a but (optionally).
* \param but: The button that might store context. Can be NULL for convenience (e.g. if there is
- * no button to take context from, but we still want to poll the operator).
+ * no button to take context from, but we still want to poll the operator).
*/
-bool ui_but_context_poll_operator(bContext *C, wmOperatorType *ot, const uiBut *but)
+bool ui_but_context_poll_operator_ex(bContext *C,
+ const uiBut *but,
+ const wmOperatorCallParams *optype_params)
{
bool result;
- int opcontext = but ? but->opcontext : WM_OP_INVOKE_DEFAULT;
if (but && but->context) {
CTX_store_set(C, but->context);
}
- result = WM_operator_poll_context(C, ot, opcontext);
+ result = WM_operator_poll_context(C, optype_params->optype, optype_params->opcontext);
if (but && but->context) {
CTX_store_set(C, NULL);
@@ -1925,6 +1927,13 @@ bool ui_but_context_poll_operator(bContext *C, wmOperatorType *ot, const uiBut *
return result;
}
+bool ui_but_context_poll_operator(bContext *C, wmOperatorType *ot, const uiBut *but)
+{
+ const int opcontext = but ? but->opcontext : WM_OP_INVOKE_DEFAULT;
+ return ui_but_context_poll_operator_ex(
+ C, but, &(wmOperatorCallParams){.optype = ot, .opcontext = opcontext});
+}
+
void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_xy[2])
{
wmWindow *window = CTX_wm_window(C);
@@ -1955,6 +1964,12 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
}
}
+ LISTBASE_FOREACH (uiButExtraOpIcon *, op_icon, &but->extra_op_icons) {
+ if (!ui_but_context_poll_operator_ex((bContext *)C, but, op_icon->optype_params)) {
+ op_icon->disabled = true;
+ }
+ }
+
const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
depsgraph, (scene) ? scene->r.cfra : 0.0f);
ui_but_anim_flag(but, &anim_eval_context);