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.
This commit is contained in:
Julian Eisel 2020-09-03 17:39:57 +02:00
parent d8a80e5949
commit d2c52d4de2
3 changed files with 18 additions and 12 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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, "");
}
/**