[Bf-blender-cvs] [277e03c6bd5] property-search-ui-v2: UI: Keep track of button's relationship with label buttons

Hans Goudey noreply at git.blender.org
Wed Sep 9 18:25:39 CEST 2020


Commit: 277e03c6bd53490045fd5c41cc694d2d43b0bbc1
Author: Hans Goudey
Date:   Wed Sep 2 09:31:17 2020 -0500
Branches: property-search-ui-v2
https://developer.blender.org/rB277e03c6bd53490045fd5c41cc694d2d43b0bbc1

UI: Keep track of button's relationship with label buttons

This is needed for property search where we want to highlight a button's label if it matches the search
filter. Otherwise the button itself is highlighted but it has no idea what label to highlight.

This is especially important because of the use of property split layouts where the label is almost
always outside of the button in a separate column.

The additional logic in the layout code isn't ideal, but I think this is generally a good thing to keep track of.
For example, another use for this could be adding a highlight to a buttons label on mouseover.

Differential Revision: https://developer.blender.org/D8783

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_graph/graph_buttons.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 367f7965026..a60fdd4de24 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2353,7 +2353,10 @@ uiPropertySplitWrapper uiItemPropertySplitWrapperCreate(uiLayout *parent_layout)
 void uiItemL(uiLayout *layout, const char *name, int icon); /* label */
 void uiItemL_ex(
     uiLayout *layout, const char *name, int icon, const bool highlight, const bool redalert);
-uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon);
+uiBut *uiItemL_respect_property_split(uiLayout *layout,
+                                      const char *text,
+                                      int icon,
+                                      uiLayout **r_layout);
 /* label icon for dragging */
 void uiItemLDrag(uiLayout *layout, struct PointerRNA *ptr, const char *name, int icon);
 /* menu */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 87be3745f87..77a12d19847 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -272,6 +272,14 @@ struct uiBut {
   uiButPushedStateFunc pushed_state_func;
   void *pushed_state_arg;
 
+  /**
+   * Used for property search, so that a button's label and decorator can be filtered and
+   * unfiltered along with it. Due to the sometimes arbitrary nature of which button to choose
+   * for these values, they aren't always filled.
+   */
+  uiBut *label_but;
+  uiBut *decorator_but;
+
   /* pointer back */
   uiBlock *block;
 };
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 50355d350ac..a424a674d3e 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -219,6 +219,8 @@ typedef struct uiLayoutItemRoot {
 
 /** \} */
 
+static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon);
+
 /* -------------------------------------------------------------------- */
 /** \name Item
  * \{ */
@@ -494,7 +496,8 @@ static void ui_item_array(uiLayout *layout,
                           int toggle,
                           bool icon_only,
                           bool compact,
-                          bool show_text)
+                          bool show_text,
+                          uiBut *label_but)
 {
   const uiStyle *style = layout->root->style;
   uiBut *but;
@@ -656,7 +659,10 @@ static void ui_item_array(uiLayout *layout,
 
     /* special case, boolean array in a menu, this could be used in a more generic way too */
     if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA) && !expand && ELEM(len, 3, 4)) {
-      uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, 0, 0, w, UI_UNIT_Y);
+      but = uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, 0, 0, w, UI_UNIT_Y);
+      if (label_but != NULL) {
+        but->label_but = label_but;
+      }
     }
     else {
       bool *boolarr = NULL;
@@ -704,6 +710,13 @@ static void ui_item_array(uiLayout *layout,
         if ((a == 0) && (subtype == PROP_AXISANGLE)) {
           UI_but_unit_type_set(but, PROP_UNIT_ROTATION);
         }
+
+        /* Set the label button for the array item. */
+        if (label_but != NULL) {
+          but->label_but = label_but;
+          label_but = label_but->next;
+          BLI_assert(label_but != NULL);
+        }
       }
 
       if (boolarr) {
@@ -746,7 +759,8 @@ static void ui_item_enum_expand_elem_exec(uiLayout *layout,
                                           const eButType but_type,
                                           const bool icon_only,
                                           const EnumPropertyItem *item,
-                                          const bool is_first)
+                                          const bool is_first,
+                                          uiBut *label_but)
 {
   const char *name = (!uiname || uiname[0]) ? item->name : "";
   const int icon = item->icon;
@@ -785,6 +799,10 @@ static void ui_item_enum_expand_elem_exec(uiLayout *layout,
   if (but_type == UI_BTYPE_TAB) {
     but->flag |= UI_BUT_DRAG_LOCK;
   }
+
+  if (label_but != NULL) {
+    but->label_but = label_but;
+  }
 }
 
 static void ui_item_enum_expand_exec(uiLayout *layout,
@@ -794,7 +812,8 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
                                      const char *uiname,
                                      const int h,
                                      const eButType but_type,
-                                     const bool icon_only)
+                                     const bool icon_only,
+                                     uiBut *label_but)
 {
   /* XXX: The way this function currently handles uiname parameter
    * is insane and inconsistent with general UI API:
@@ -870,7 +889,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
     }
 
     ui_item_enum_expand_elem_exec(
-        layout, block, ptr, prop, uiname, h, but_type, icon_only, item, is_first);
+        layout, block, ptr, prop, uiname, h, but_type, icon_only, item, is_first, label_but);
   }
 
   UI_block_layout_set_current(block, layout);
@@ -885,9 +904,11 @@ static void ui_item_enum_expand(uiLayout *layout,
                                 PropertyRNA *prop,
                                 const char *uiname,
                                 const int h,
-                                const bool icon_only)
+                                const bool icon_only,
+                                uiBut *label_but)
 {
-  ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_ROW, icon_only);
+  ui_item_enum_expand_exec(
+      layout, block, ptr, prop, uiname, h, UI_BTYPE_ROW, icon_only, label_but);
 }
 static void ui_item_enum_expand_tabs(uiLayout *layout,
                                      bContext *C,
@@ -900,7 +921,7 @@ static void ui_item_enum_expand_tabs(uiLayout *layout,
 {
   uiBut *last = block->buttons.last;
 
-  ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_TAB, icon_only);
+  ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_TAB, icon_only, NULL);
   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)));
@@ -939,10 +960,12 @@ static uiBut *ui_item_with_label(uiLayout *layout,
 {
   uiLayout *sub = layout;
   uiBut *but = NULL;
+  uiBut *label_but = NULL;
   PropertyType type;
   PropertySubType subtype;
   int prop_but_width = w_hint;
 #ifdef UI_PROP_DECORATE
+  uiBut *decorator_but = NULL;
   uiLayout *layout_prop_decorate = NULL;
   const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
   const bool use_prop_decorate = use_prop_sep && (layout->item.flag & UI_ITEM_PROP_DECORATE) &&
@@ -963,7 +986,7 @@ static uiBut *ui_item_with_label(uiLayout *layout,
 #ifdef UI_PROP_DECORATE
   if (name[0]) {
     if (use_prop_sep) {
-      layout_prop_decorate = uiItemL_respect_property_split(layout, name, 0);
+      label_but = uiItemL_respect_property_split(layout, name, 0, &layout_prop_decorate);
     }
     else
 #endif
@@ -979,7 +1002,8 @@ static uiBut *ui_item_with_label(uiLayout *layout,
       else {
         w_label = w_hint / 3;
       }
-      uiDefBut(block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
+      label_but = uiDefBut(
+          block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
     }
   }
 
@@ -1057,10 +1081,15 @@ static uiBut *ui_item_with_label(uiLayout *layout,
 #ifdef UI_PROP_DECORATE
   /* Only for alignment. */
   if (use_prop_decorate) { /* Note that sep flag may have been unset meanwhile. */
-    uiItemL(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1);
+    decorator_but = uiItemL_(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1);
   }
 #endif /* UI_PROP_DECORATE */
 
+  /* Set the button's label and decorator even if they are NULL. They can be changed
+   * further with the return value of this function anyway. */
+  but->label_but = label_but;
+  but->decorator_but = decorator_but;
+
   UI_block_layout_set_current(block, layout);
   return but;
 }
@@ -1900,28 +1929,34 @@ static uiLayout *ui_layout_heading_find(uiLayout *cur_layout)
   return NULL;
 }
 
-static void ui_layout_heading_label_add(uiLayout *layout,
-                                        uiLayout *heading_layout,
-                                        bool right_align,
-                                        bool respect_prop_split)
+/**
+ * \return The label button added.
+ */
+static uiBut *ui_layout_heading_label_add(uiLayout *layout,
+                                          uiLayout *heading_layout,
+                                          bool right_align,
+                                          bool respect_prop_split)
 {
   const int prev_alignment = layout->alignment;
+  uiBut *label_but = NULL;
 
   if (right_align) {
     uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_RIGHT);
   }
 
   if (respect_prop_split) {
-    uiItemL_respect_property_split(layout, heading_layout->heading, ICON_NONE);
+    label_but = uiItemL_respect_property_split(layout, heading_layout->heading, ICON_NONE, NULL);
   }
   else {
-    uiItemL(layout, heading_layout->heading, ICON_NONE);
+    label_but = uiItemL_(layout, heading_layout->heading, ICON_NONE);
   }
   /* After adding the heading label, we have to mark it somehow as added, so it's not added again
    * for other items in this layout. For now just clear it. */
   heading_layout->heading[0] = '\0';
 
   layout->alignment = prev_alignment;
+
+  return label_but;
 }
 
 /**
@@ -2103,6 +2138,10 @@ void uiItemFullR(uiLayout *layout,
   }
 
   uiBut *but = NULL;
+  /* Store the label to assign it to the button afterwards. This is the first
+   * label button if the item is an array and there are a series of buttons.
+   * Decorators are assigned as t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list