[Bf-blender-cvs] [d2c52d4de2c] master: Cleanup: Add/use function to disable buttons with a disabled hint

Julian Eisel noreply at git.blender.org
Thu Sep 3 17:46:30 CEST 2020


Commit: d2c52d4de2ca20dd2ba0254dd6207a70e9bd0597
Author: Julian Eisel
Date:   Thu Sep 3 17:39:57 2020 +0200
Branches: master
https://developer.blender.org/rBd2c52d4de2ca20dd2ba0254dd6207a70e9bd0597

Cleanup: Add/use function to disable buttons with a disabled hint

We do this in a couple of places, so it's worth having the logic wrapped
into a function.
Also, the only way to set the disabled hint for a button from outside of
`interface/` was through `UI_block_lock_set()`/`UI_block_lock_clear()`,
for which the usage isn't obvious when you just try to disable a single
button.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_layout.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 01e3dd22648..ab5e2fcee6a 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -732,6 +732,8 @@ bool UI_but_flag_is_set(uiBut *but, int flag);
 void UI_but_drawflag_enable(uiBut *but, int flag);
 void UI_but_drawflag_disable(uiBut *but, int flag);
 
+void UI_but_disable(uiBut *but, const char *disabled_hint);
+
 void UI_but_type_set_menu_from_pulldown(uiBut *but);
 
 /* special button case, only draw it when used actively, for outliner etc */
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c8526c16dba..bfa3f3a011c 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4078,12 +4078,6 @@ void ui_def_but_icon_clear(uiBut *but)
   but->drawflag &= ~UI_BUT_ICON_LEFT;
 }
 
-static void ui_def_but_rna__disable(uiBut *but, const char *info)
-{
-  but->flag |= UI_BUT_DISABLED;
-  but->disabled_info = info;
-}
-
 static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p)
 {
   uiBlock *block = uiLayoutGetBlock(layout);
@@ -4502,7 +4496,7 @@ static uiBut *ui_def_but_rna(uiBlock *block,
 
   const char *info;
   if (but->rnapoin.data && !RNA_property_editable_info(&but->rnapoin, prop, &info)) {
-    ui_def_but_rna__disable(but, info);
+    UI_but_disable(but, info);
   }
 
   if (but->flag & UI_BUT_UNDO && (ui_but_is_rna_undo(but) == false)) {
@@ -4550,7 +4544,7 @@ static uiBut *ui_def_but_rna_propname(uiBlock *block,
     but = ui_def_but(
         block, type, retval, propname, x, y, width, height, NULL, min, max, a1, a2, tip);
 
-    ui_def_but_rna__disable(but, "Unknown Property.");
+    UI_but_disable(but, "Unknown Property.");
   }
 
   return but;
@@ -4588,8 +4582,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block,
   but->flag &= ~UI_BUT_UNDO; /* no need for ui_but_is_rna_undo(), we never need undo here */
 
   if (!ot) {
-    but->flag |= UI_BUT_DISABLED;
-    but->disabled_info = "";
+    UI_but_disable(but, "");
   }
 
   return but;
@@ -6034,6 +6027,18 @@ void UI_but_drawflag_disable(uiBut *but, int flag)
   but->drawflag &= ~flag;
 }
 
+void UI_but_disable(uiBut *but, const char *disabled_hint)
+{
+  UI_but_flag_enable(but, UI_BUT_DISABLED);
+
+  /* Only one disabled hint at a time currently. Don't override the previous one here. */
+  if (but->disabled_info && but->disabled_info[0]) {
+    return;
+  }
+
+  but->disabled_info = disabled_hint;
+}
+
 void UI_but_type_set_menu_from_pulldown(uiBut *but)
 {
   BLI_assert(but->type == UI_BTYPE_PULLDOWN);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index e1f3e14eda1..7b4bb067eb8 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -1139,8 +1139,7 @@ static void ui_item_disabled(uiLayout *layout, const char *name)
   w = ui_text_icon_width(layout, name, 0, 0);
 
   but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
-  but->flag |= UI_BUT_DISABLED;
-  but->disabled_info = "";
+  UI_but_disable(but, "");
 }
 
 /**



More information about the Bf-blender-cvs mailing list