UI: Add highlight arguments to tab buttons
This adds arguments to `uiLayout.prop_tabs_enum` and the C equivalent (`uiItemTabsEnumR_prop`) to gray out tabs based on a boolean array. For property search in multiple tabs, we need a way to show which tabs have a search result, but we still need to show which tab is active. Differential Revision: https://developer.blender.org/D8858
This commit is contained in:
parent
9fe5817588
commit
96dd299055
Notes:
blender-bot
2023-02-14 00:13:36 +01:00
Referenced by issue #77824, Properties Search Implementation
|
@ -2429,6 +2429,8 @@ void uiItemTabsEnumR_prop(uiLayout *layout,
|
|||
struct bContext *C,
|
||||
struct PointerRNA *ptr,
|
||||
PropertyRNA *prop,
|
||||
struct PointerRNA *ptr_highlight,
|
||||
PropertyRNA *prop_highlight,
|
||||
bool icon_only);
|
||||
|
||||
/* Only for testing, inspecting layouts. */
|
||||
|
|
|
@ -886,6 +886,8 @@ static void ui_item_enum_expand_tabs(uiLayout *layout,
|
|||
uiBlock *block,
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA *prop,
|
||||
PointerRNA *ptr_highlight,
|
||||
PropertyRNA *prop_highlight,
|
||||
const char *uiname,
|
||||
const int h,
|
||||
const bool icon_only)
|
||||
|
@ -894,9 +896,24 @@ static void ui_item_enum_expand_tabs(uiLayout *layout,
|
|||
|
||||
ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_TAB, icon_only);
|
||||
BLI_assert(last != block->buttons.last);
|
||||
|
||||
for (uiBut *tab = last ? last->next : block->buttons.first; tab; tab = tab->next) {
|
||||
UI_but_drawflag_enable(tab, ui_but_align_opposite_to_area_align_get(CTX_wm_region(C)));
|
||||
}
|
||||
|
||||
const bool use_custom_highlight = (prop_highlight != NULL);
|
||||
|
||||
if (use_custom_highlight) {
|
||||
const int highlight_array_len = RNA_property_array_length(ptr_highlight, prop_highlight);
|
||||
bool *highlight_array = alloca(sizeof(bool) * highlight_array_len);
|
||||
RNA_property_boolean_get_array(ptr_highlight, prop_highlight, highlight_array);
|
||||
int i = 0;
|
||||
for (uiBut *tab_but = last ? last->next : block->buttons.first;
|
||||
(tab_but != NULL) && (i < highlight_array_len);
|
||||
tab_but = tab_but->next, i++) {
|
||||
SET_FLAG_FROM_TEST(tab_but->flag, !highlight_array[i], UI_BUT_INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* callback for keymap item change button */
|
||||
|
@ -3474,13 +3491,19 @@ void uiItemMenuEnumR(
|
|||
uiItemMenuEnumR_prop(layout, ptr, prop, name, icon);
|
||||
}
|
||||
|
||||
void uiItemTabsEnumR_prop(
|
||||
uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool icon_only)
|
||||
void uiItemTabsEnumR_prop(uiLayout *layout,
|
||||
bContext *C,
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA *prop,
|
||||
PointerRNA *ptr_highlight,
|
||||
PropertyRNA *prop_highlight,
|
||||
bool icon_only)
|
||||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
|
||||
UI_block_layout_set_current(block, layout);
|
||||
ui_item_enum_expand_tabs(layout, C, block, ptr, prop, NULL, UI_UNIT_Y, icon_only);
|
||||
ui_item_enum_expand_tabs(
|
||||
layout, C, block, ptr, prop, ptr_highlight, prop_highlight, NULL, UI_UNIT_Y, icon_only);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -216,8 +216,13 @@ static void rna_uiItemMenuEnumR(uiLayout *layout,
|
|||
uiItemMenuEnumR_prop(layout, ptr, prop, name, icon);
|
||||
}
|
||||
|
||||
static void rna_uiItemTabsEnumR(
|
||||
uiLayout *layout, bContext *C, struct PointerRNA *ptr, const char *propname, bool icon_only)
|
||||
static void rna_uiItemTabsEnumR(uiLayout *layout,
|
||||
bContext *C,
|
||||
struct PointerRNA *ptr,
|
||||
const char *propname,
|
||||
struct PointerRNA *ptr_highlight,
|
||||
const char *propname_highlight,
|
||||
bool icon_only)
|
||||
{
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
||||
|
||||
|
@ -230,7 +235,31 @@ static void rna_uiItemTabsEnumR(
|
|||
return;
|
||||
}
|
||||
|
||||
uiItemTabsEnumR_prop(layout, C, ptr, prop, icon_only);
|
||||
/* Get the highlight property used to gray out some of the tabs. */
|
||||
PropertyRNA *prop_highlight = NULL;
|
||||
if (!RNA_pointer_is_null(ptr_highlight)) {
|
||||
prop_highlight = RNA_struct_find_property(ptr_highlight, propname_highlight);
|
||||
if (!prop_highlight) {
|
||||
RNA_warning("property not found: %s.%s",
|
||||
RNA_struct_identifier(ptr_highlight->type),
|
||||
propname_highlight);
|
||||
return;
|
||||
}
|
||||
if (RNA_property_type(prop_highlight) != PROP_BOOLEAN) {
|
||||
RNA_warning("property is not a boolean: %s.%s",
|
||||
RNA_struct_identifier(ptr_highlight->type),
|
||||
propname_highlight);
|
||||
return;
|
||||
}
|
||||
if (!RNA_property_array_check(prop_highlight)) {
|
||||
RNA_warning("property is not an array: %s.%s",
|
||||
RNA_struct_identifier(ptr_highlight->type),
|
||||
propname_highlight);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uiItemTabsEnumR_prop(layout, C, ptr, prop, ptr_highlight, prop_highlight, icon_only);
|
||||
}
|
||||
|
||||
static void rna_uiItemEnumR_string(uiLayout *layout,
|
||||
|
@ -929,6 +958,11 @@ void RNA_api_ui_layout(StructRNA *srna)
|
|||
func = RNA_def_function(srna, "prop_tabs_enum", "rna_uiItemTabsEnumR");
|
||||
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
|
||||
api_ui_item_rna_common(func);
|
||||
parm = RNA_def_pointer(
|
||||
func, "data_highlight", "AnyType", "", "Data from which to take highlight property");
|
||||
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
|
||||
parm = RNA_def_string(
|
||||
func, "property_highlight", NULL, 0, "", "Identifier of highlight property in data");
|
||||
RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in tabs, no text");
|
||||
|
||||
func = RNA_def_function(srna, "prop_enum", "rna_uiItemEnumR_string");
|
||||
|
|
Loading…
Reference in New Issue