[Bf-blender-cvs] [d219d0efa13] property-search-ui: Property Search: Fix graying out tabs with no results

Hans Goudey noreply at git.blender.org
Wed Jul 22 21:14:04 CEST 2020


Commit: d219d0efa13cc35c888df6f6bfe71035d1426cc4
Author: Hans Goudey
Date:   Wed Jul 22 15:14:06 2020 -0400
Branches: property-search-ui
https://developer.blender.org/rBd219d0efa13cc35c888df6f6bfe71035d1426cc4

Property Search: Fix graying out tabs with no results

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

M	release/scripts/startup/bl_ui/space_properties.py
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/release/scripts/startup/bl_ui/space_properties.py b/release/scripts/startup/bl_ui/space_properties.py
index 311892cab15..35a4e608785 100644
--- a/release/scripts/startup/bl_ui/space_properties.py
+++ b/release/scripts/startup/bl_ui/space_properties.py
@@ -53,7 +53,8 @@ class PROPERTIES_PT_navigation_bar(Panel):
         layout.scale_x = 1.4
         layout.scale_y = 1.4
         if (view.filter_text):
-            layout.prop_tabs_enum(view, "context_search_filter_active", icon_only=True)
+            layout.prop_tabs_enum(view, "context", data_highlight=view, 
+                property_highlight="context_search_filter_active", icon_only=True)
         else:
             layout.prop_tabs_enum(view, "context", icon_only=True)
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 945be665d82..903caab2f22 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2420,6 +2420,8 @@ void uiItemTabsEnumR_prop(uiLayout *layout,
                           struct bContext *C,
                           struct PointerRNA *ptr,
                           PropertyRNA *prop,
+                          struct PointerRNA *ptr_highlight,
+                          PropertyRNA *prop_highlight,
                           bool icon_only);
 
 /* UI Operators */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 9e6b42d0858..b83294a86ec 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -920,6 +920,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)
@@ -928,8 +930,26 @@ 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, NULL);
   BLI_assert(last != block->buttons.last);
+
+  const bool use_custom_highlight = (prop_highlight != NULL);
+
+  int custom_highlight_flag = 0; /* Max of 32 tabs. */
+  if (use_custom_highlight) {
+    BLI_assert(prop_highlight != NULL);
+    BLI_assert(RNA_property_flag(prop_highlight) & PROP_ENUM_FLAG);
+    custom_highlight_flag = RNA_property_enum_get(ptr_highlight, prop_highlight);
+  }
+
+  int i = 0;
   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)));
+
+    if (use_custom_highlight) {
+      if (!(custom_highlight_flag & (1 << i))) {
+        tab->flag |= UI_BUT_INACTIVE;
+      }
+    }
+    i++;
   }
 }
 
@@ -3564,13 +3584,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);
 }
 
 /** \} */
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 74aad9c125e..56b693f9e2b 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -350,7 +350,7 @@ static void property_search_other_tabs(const bContext *C,
     }
     printf("tab value: %d, unfiltered: %s\n",
            context_tabs_array[i],
-           (sbuts->context_search_filter_active & (1 << i)) ? "true" : "else");
+           (sbuts->context_search_filter_active & (1 << i)) ? "true" : "false");
   }
 
   BKE_area_region_free(CTX_wm_area(C_copy)->type, region_copy);
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 8dfa54b95da..d5530e76296 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -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_ENUM) {
+      RNA_warning("property is not an enum: %s.%s",
+                  RNA_struct_identifier(ptr_highlight->type),
+                  propname_highlight);
+      return;
+    }
+    if (!(RNA_property_flag(prop_highlight) & PROP_ENUM_FLAG)) {
+      RNA_warning("property must be a bitfield enum: %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,
@@ -920,6 +949,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");



More information about the Bf-blender-cvs mailing list