[Bf-blender-cvs] [f673b9c8b1f] temp-outliner-library-override-hierarchy: Outliner: Display buttons for library overrides

Julian Eisel noreply at git.blender.org
Wed Mar 9 18:27:20 CET 2022


Commit: f673b9c8b1fee6a68a84761d5d33ca3e1f661e97
Author: Julian Eisel
Date:   Mon Mar 7 18:11:39 2022 +0100
Branches: temp-outliner-library-override-hierarchy
https://developer.blender.org/rBf673b9c8b1fee6a68a84761d5d33ca3e1f661e97

Outliner: Display buttons for library overrides

As proposed in T95802, this adds buttons to modify the override in the
library override display mode.
I decided to add the right column so that the left column can be
scrolled independently, like we do it for the restriction toggles in
other display modes.

Contains some cleanups that are to be committed separately.

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

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_utils.c
M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_intern.hh
M	source/blender/editors/space_outliner/outliner_select.cc
M	source/blender/editors/space_outliner/outliner_utils.cc
M	source/blender/editors/space_outliner/tree/tree_element_overrides.cc
M	source/blender/editors/space_outliner/tree/tree_element_overrides.hh

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 060c9dc33d6..a223eac3000 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1610,6 +1610,14 @@ uiBut *uiDefAutoButR(uiBlock *block,
                      int y,
                      int width,
                      int height);
+void uiDefAutoButsArrayR(uiBlock *block,
+                         PointerRNA *ptr,
+                         PropertyRNA *prop,
+                         const int icon,
+                         const int x,
+                         const int y,
+                         const int tot_width,
+                         const int height);
 /**
  * \a check_prop callback filters functions to avoid drawing certain properties,
  * in cases where PROP_HIDDEN flag can't be used for a property.
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 814bd956096..728d42a9353 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -320,6 +320,7 @@ uiBut *uiDefAutoButR(uiBlock *block,
                                    -1,
                                    -1,
                                    NULL);
+      ui_but_add_search(but, ptr, prop, NULL, NULL);
       break;
     }
     case PROP_COLLECTION: {
@@ -338,6 +339,29 @@ uiBut *uiDefAutoButR(uiBlock *block,
   return but;
 }
 
+void uiDefAutoButsArrayR(uiBlock *block,
+                         PointerRNA *ptr,
+                         PropertyRNA *prop,
+                         const int icon,
+                         const int x,
+                         const int y,
+                         const int tot_width,
+                         const int height)
+{
+  const int len = RNA_property_array_length(ptr, prop);
+  if (len == 0) {
+    return;
+  }
+
+  const int item_width = tot_width / len;
+
+  UI_block_align_begin(block);
+  for (int i = 0; i < len; i++) {
+    uiDefAutoButR(block, ptr, prop, i, "", icon, x + i * item_width, y, item_width, height);
+  }
+  UI_block_align_end(block);
+}
+
 eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout,
                                      PointerRNA *ptr,
                                      bool (*check_prop)(PointerRNA *ptr,
diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index 53de7d582b6..c308cef7cfd 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -1085,7 +1085,7 @@ static void outliner_draw_restrictbuts(uiBlock *block,
   }
 
   BLI_assert((restrict_column_offset * UI_UNIT_X + V2D_SCROLL_WIDTH) ==
-             outliner_restrict_columns_width(space_outliner));
+             outliner_right_columns_width(space_outliner));
 
   /* Create buttons. */
   uiBut *bt;
@@ -1721,7 +1721,7 @@ static void outliner_draw_userbuts(uiBlock *block,
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     TreeStoreElem *tselem = TREESTORE(te);
-    if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
+    if (outliner_is_element_in_view(te, &region->v2d)) {
       if (tselem->type == TSE_SOME_ID) {
         uiBut *bt;
         ID *id = tselem->id;
@@ -1782,18 +1782,71 @@ static void outliner_draw_userbuts(uiBlock *block,
   }
 }
 
-static bool outliner_draw_overrides_buts(uiBlock *block,
-                                         ARegion *region,
-                                         SpaceOutliner *space_outliner,
-                                         ListBase *lb,
-                                         const bool is_open)
+static void outliner_draw_overrides_rna_buts(uiBlock *block,
+                                             const ARegion *region,
+                                             const SpaceOutliner *space_outliner,
+                                             const ListBase *lb,
+                                             const int x)
+{
+  LISTBASE_FOREACH (const TreeElement *, te, lb) {
+    const TreeStoreElem *tselem = TREESTORE(te);
+    if (TSELEM_OPEN(tselem, space_outliner)) {
+      outliner_draw_overrides_rna_buts(block, region, space_outliner, &te->subtree, x);
+    }
+
+    if (!outliner_is_element_in_view(te, &region->v2d)) {
+      continue;
+    }
+    if (tselem->type != TSE_LIBRARY_OVERRIDE) {
+      continue;
+    }
+
+    TreeElementOverridesProperty &override_elem = *tree_element_cast<TreeElementOverridesProperty>(
+        te);
+
+    PointerRNA *ptr = &override_elem.override_rna_ptr;
+    PropertyRNA *prop = &override_elem.override_rna_prop;
+    const PropertyType prop_type = RNA_property_type(prop);
+
+    const float pad_x = 1 * UI_DPI_FAC;
+    const float max_width = OL_RNA_COL_SIZEX - 2 * pad_x;
+    const float height = UI_UNIT_Y - U.pixelsize;
+
+    uiBut *auto_but = uiDefAutoButR(block,
+                                    ptr,
+                                    prop,
+                                    -1,
+                                    (prop_type == PROP_ENUM) ? nullptr : "",
+                                    ICON_NONE,
+                                    x + pad_x,
+                                    te->ys,
+                                    max_width,
+                                    height);
+    /* Added the button successfully, nothing else to do. Otherwise, cases for multiple buttons
+     * need to be handled. */
+    if (auto_but) {
+      continue;
+    }
+
+    if (!auto_but) {
+      /* TODO what if the array is longer, and doesn't fit nicely? What about multi-dimension
+       * arrays? */
+      uiDefAutoButsArrayR(block, ptr, prop, ICON_NONE, x, te->ys, max_width, height);
+    }
+  }
+}
+
+static bool outliner_draw_overrides_warning_buts(uiBlock *block,
+                                                 ARegion *region,
+                                                 SpaceOutliner *space_outliner,
+                                                 ListBase *lb,
+                                                 const bool is_open)
 {
   bool any_item_has_warnings = false;
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     bool item_has_warnings = false;
-    const bool do_draw = (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin &&
-                          te->ys <= region->v2d.cur.ymax);
+    const bool do_draw = outliner_is_element_in_view(te, &region->v2d);
     int but_flag = UI_BUT_DRAG_LOCK;
     const char *tip = nullptr;
 
@@ -1833,7 +1886,7 @@ static bool outliner_draw_overrides_buts(uiBlock *block,
         break;
     }
 
-    const bool any_child_has_warnings = outliner_draw_overrides_buts(
+    const bool any_child_has_warnings = outliner_draw_overrides_warning_buts(
         block,
         region,
         space_outliner,
@@ -1867,28 +1920,20 @@ static bool outliner_draw_overrides_buts(uiBlock *block,
   return any_item_has_warnings;
 }
 
-static void outliner_draw_rnacols(ARegion *region, int sizex)
+static void outliner_draw_separator(ARegion *region, const int x)
 {
   View2D *v2d = &region->v2d;
 
-  float miny = v2d->cur.ymin;
-  if (miny < v2d->tot.ymin) {
-    miny = v2d->tot.ymin;
-  }
-
   GPU_line_width(1.0f);
 
   uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
   immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
   immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
 
-  immBegin(GPU_PRIM_LINES, 4);
-
-  immVertex2f(pos, sizex, v2d->cur.ymax);
-  immVertex2f(pos, sizex, miny);
+  immBegin(GPU_PRIM_LINES, 2);
 
-  immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, v2d->cur.ymax);
-  immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, miny);
+  immVertex2f(pos, x, v2d->cur.ymax);
+  immVertex2f(pos, x, v2d->cur.ymin);
 
   immEnd();
 
@@ -1903,7 +1948,7 @@ static void outliner_draw_rnabuts(
 
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     TreeStoreElem *tselem = TREESTORE(te);
-    if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
+    if (outliner_is_element_in_view(te, &region->v2d)) {
       if (TreeElementRNAProperty *te_rna_prop = tree_element_cast<TreeElementRNAProperty>(te)) {
         ptr = te_rna_prop->getPointerRNA();
         prop = te_rna_prop->getPropertyRNA();
@@ -3643,7 +3688,7 @@ static void outliner_draw_tree(bContext *C,
                                const TreeViewContext *tvc,
                                ARegion *region,
                                SpaceOutliner *space_outliner,
-                               const float restrict_column_width,
+                               const float right_column_width,
                                const bool use_mode_column,
                                const bool use_warning_column,
                                TreeElement **te_edit)
@@ -3678,8 +3723,8 @@ static void outliner_draw_tree(bContext *C,
 
   /* Set scissor so tree elements or lines can't overlap restriction icons. */
   int scissor[4] = {0};
-  if (restrict_column_width > 0.0f) {
-    int mask_x = BLI_rcti_size_x(&region->v2d.mask) - (int)restrict_column_width + 1;
+  if (right_column_width > 0.0f) {
+    int mask_x = BLI_rcti_size_x(&region->v2d.mask) - (int)right_column_width + 1;
     CLAMP_MIN(mask_x, 0);
 
     GPU_scissor_get(scissor);
@@ -3705,11 +3750,11 @@ static void outliner_draw_tree(bContext *C,
                                (te->flag & TE_DRAGGING) != 0,
                                startx,
                                &starty,
-                               restrict_column_width,
+                               right_column_width,
                                te_edit);
   }
 
-  if (restrict_column_width > 0.0f) {
+  if (right_column_width > 0.0f) {
     /* Reset scissor. */
     GPU_scissor(UNPACK4(scissor));
   }
@@ -3760,21 +3805,21 @@ static int outliner_data_api_buttons_start_x(int max_tree_width)
 
 static int outliner_width(SpaceOutliner *space_outliner,
                           int max_tree_width,
-                          float restrict_column_width)
+          

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list