[Bf-blender-cvs] [01df48a9839] master: Refactor: Port spreadsheet data set to UI tree view

Hans Goudey noreply at git.blender.org
Fri Nov 19 23:36:21 CET 2021


Commit: 01df48a983944ab3f8a6f3be926f825ac83bbc14
Author: Hans Goudey
Date:   Fri Nov 19 17:36:11 2021 -0500
Branches: master
https://developer.blender.org/rB01df48a983944ab3f8a6f3be926f825ac83bbc14

Refactor: Port spreadsheet data set to UI tree view

This patch removes a bunch of specific code for drawing the spreadsheet
data set region, which was an overly specific solution for a generic UI.
Nowadays, the UI tree view API used for asset browser catalogs is a much
better way to implement this behavior.

To make this possible, the tree view API is extended in a few ways.
Collapsibility can now be turned off, and whether an item should
be active is moved to a separate virtual function.

The only visual change is that the items are now drawn in a box,
just like the asset catalog.

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

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_query.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/tree_view.cc
M	source/blender/editors/space_file/asset_catalog_tree_view.cc
M	source/blender/editors/space_spreadsheet/CMakeLists.txt
M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_dataset_draw.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_dataset_draw.hh
D	source/blender/editors/space_spreadsheet/spreadsheet_dataset_layout.cc
D	source/blender/editors/space_spreadsheet/spreadsheet_dataset_layout.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_intern.hh
A	source/blender/editors/space_spreadsheet/spreadsheet_panels.cc

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index aa0dc222614..f0f267a3cb4 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -400,9 +400,8 @@ typedef enum {
   /** Resize handle (resize uilist). */
   UI_BTYPE_GRIP = 57 << 9,
   UI_BTYPE_DECORATOR = 58 << 9,
-  UI_BTYPE_DATASETROW = 59 << 9,
   /* An item in a tree view. Parent items may be collapsible. */
-  UI_BTYPE_TREEROW = 60 << 9,
+  UI_BTYPE_TREEROW = 59 << 9,
 } eButType;
 
 #define BUTTYPE (63 << 9)
@@ -1676,11 +1675,7 @@ int UI_searchbox_size_x(void);
 int UI_search_items_find_index(uiSearchItems *items, const char *name);
 
 void UI_but_hint_drawstr_set(uiBut *but, const char *string);
-void UI_but_datasetrow_indentation_set(uiBut *but, int indentation);
-void UI_but_datasetrow_component_set(uiBut *but, uint8_t geometry_component_type);
-void UI_but_datasetrow_domain_set(uiBut *but, uint8_t attribute_domain);
-uint8_t UI_but_datasetrow_component_get(uiBut *but);
-uint8_t UI_but_datasetrow_domain_get(uiBut *but);
+
 void UI_but_treerow_indentation_set(uiBut *but, int indentation);
 
 void UI_but_node_link_set(uiBut *but, struct bNodeSocket *socket, const float draw_color[4]);
diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh
index 0d18eedeac9..8caf17741a7 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -217,15 +217,11 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
   friend class TreeViewLayoutBuilder;
 
  public:
-  using IsActiveFn = std::function<bool()>;
-
  private:
   bool is_open_ = false;
   bool is_active_ = false;
   bool is_renaming_ = false;
 
-  IsActiveFn is_active_fn_;
-
  protected:
   /** This label is used for identifying an item (together with its parent's labels). */
   std::string label_{};
@@ -239,11 +235,6 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
   virtual void build_context_menu(bContext &C, uiLayout &column) const;
 
   virtual void on_activate();
-  /**
-   * Set a custom callback to check if this item should be active. There's a version without
-   * arguments for checking if the item is currently in an active state.
-   */
-  virtual void is_active(IsActiveFn is_active_fn);
 
   /**
    * Queries if the tree-view item supports renaming in principle. Renaming may still fail, e.g. if
@@ -329,6 +320,17 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
    */
   void activate();
 
+  /**
+   * If the result is not empty, it controls whether the item should be active or not,
+   * usually depending on the data that the view represents.
+   */
+  virtual std::optional<bool> should_be_active() const;
+
+  /**
+   * Return whether the item can be collapsed. Used to disable collapsing for items with children.
+   */
+  virtual bool supports_collapsing() const;
+
  private:
   static void rename_button_fn(bContext *, void *, char *);
   static AbstractTreeViewItem *find_tree_item_from_rename_button(const uiBut &but);
@@ -416,6 +418,7 @@ class AbstractTreeViewItemDropController {
  */
 class BasicTreeViewItem : public AbstractTreeViewItem {
  public:
+  using IsActiveFn = std::function<bool()>;
   using ActivateFn = std::function<void(BasicTreeViewItem &new_active)>;
   BIFIconID icon;
 
@@ -423,7 +426,11 @@ class BasicTreeViewItem : public AbstractTreeViewItem {
 
   void build_row(uiLayout &row) override;
   void add_label(uiLayout &layout, StringRefNull label_override = "");
-  void on_activate(ActivateFn fn);
+  void set_on_activate_fn(ActivateFn fn);
+  /**
+   * Set a custom callback to check if this item should be active.
+   */
+  void set_is_active_fn(IsActiveFn fn);
 
  protected:
   /**
@@ -433,9 +440,12 @@ class BasicTreeViewItem : public AbstractTreeViewItem {
    */
   ActivateFn activate_fn_;
 
+  IsActiveFn is_active_fn_;
+
  private:
   static void tree_row_click_fn(struct bContext *C, void *arg1, void *arg2);
 
+  std::optional<bool> should_be_active() const override;
   void on_activate() override;
 };
 
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c59c2d5d517..c753c06b791 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3977,10 +3977,6 @@ static void ui_but_alloc_info(const eButType type,
       alloc_size = sizeof(uiButCurveProfile);
       alloc_str = "uiButCurveProfile";
       break;
-    case UI_BTYPE_DATASETROW:
-      alloc_size = sizeof(uiButDatasetRow);
-      alloc_str = "uiButDatasetRow";
-      break;
     case UI_BTYPE_TREEROW:
       alloc_size = sizeof(uiButTreeRow);
       alloc_str = "uiButTreeRow";
@@ -4183,7 +4179,6 @@ static uiBut *ui_def_but(uiBlock *block,
                 UI_BTYPE_BLOCK,
                 UI_BTYPE_BUT_MENU,
                 UI_BTYPE_SEARCH_MENU,
-                UI_BTYPE_DATASETROW,
                 UI_BTYPE_TREEROW,
                 UI_BTYPE_POPOVER)) {
     but->drawflag |= (UI_BUT_TEXT_LEFT | UI_BUT_ICON_LEFT);
@@ -6924,15 +6919,6 @@ uiBut *uiDefSearchButO_ptr(uiBlock *block,
   return but;
 }
 
-void UI_but_datasetrow_indentation_set(uiBut *but, int indentation)
-{
-  uiButDatasetRow *but_dataset = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-
-  but_dataset->indentation = indentation;
-  BLI_assert(indentation >= 0);
-}
-
 void UI_but_treerow_indentation_set(uiBut *but, int indentation)
 {
   uiButTreeRow *but_row = (uiButTreeRow *)but;
@@ -6950,38 +6936,6 @@ void UI_but_hint_drawstr_set(uiBut *but, const char *string)
   ui_but_add_shortcut(but, string, false);
 }
 
-void UI_but_datasetrow_component_set(uiBut *but, uint8_t geometry_component_type)
-{
-  uiButDatasetRow *but_dataset_row = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-
-  but_dataset_row->geometry_component_type = geometry_component_type;
-}
-
-void UI_but_datasetrow_domain_set(uiBut *but, uint8_t attribute_domain)
-{
-  uiButDatasetRow *but_dataset_row = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-
-  but_dataset_row->attribute_domain = attribute_domain;
-}
-
-uint8_t UI_but_datasetrow_component_get(uiBut *but)
-{
-  uiButDatasetRow *but_dataset_row = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-
-  return but_dataset_row->geometry_component_type;
-}
-
-uint8_t UI_but_datasetrow_domain_get(uiBut *but)
-{
-  uiButDatasetRow *but_dataset_row = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-
-  return but_dataset_row->attribute_domain;
-}
-
 void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_color[4])
 {
   but->flag |= UI_BUT_NODE_LINK;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 8a744a1edbe..555b699872b 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -2334,9 +2334,6 @@ static void ui_apply_but(
     case UI_BTYPE_LISTROW:
       ui_apply_but_LISTROW(C, block, but, data);
       break;
-    case UI_BTYPE_DATASETROW:
-      ui_apply_but_ROW(C, block, but, data);
-      break;
     case UI_BTYPE_TAB:
       ui_apply_but_TAB(C, but, data);
       break;
@@ -8012,7 +8009,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
     case UI_BTYPE_CHECKBOX:
     case UI_BTYPE_CHECKBOX_N:
     case UI_BTYPE_ROW:
-    case UI_BTYPE_DATASETROW:
       retval = ui_do_but_TOG(C, but, data, event);
       break;
     case UI_BTYPE_TREEROW:
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 8c33e2d1cc9..e0686c1ff7a 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -351,14 +351,6 @@ typedef struct uiButProgressbar {
   float progress;
 } uiButProgressbar;
 
-/** Derived struct for #UI_BTYPE_DATASETROW. */
-typedef struct uiButDatasetRow {
-  uiBut but;
-
-  uint8_t geometry_component_type;
-  uint8_t attribute_domain;
-  int indentation;
-} uiButDatasetRow;
 
 /** Derived struct for #UI_BTYPE_TREEROW. */
 typedef struct uiButTreeRow {
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index bdf93d7c82e..a07222854d2 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -69,7 +69,6 @@ bool ui_but_is_toggle(const uiBut *but)
               UI_BTYPE_CHECKBOX,
               UI_BTYPE_CHECKBOX_N,
               UI_BTYPE_ROW,
-              UI_BTYPE_DATASETROW,
               UI_BTYPE_TREEROW);
 }
 
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 7d1b7b80ccd..784f87d36c1 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -114,7 +114,6 @@ typedef enum {
   UI_WTYPE_LISTITEM,
   UI_WTYPE_PROGRESSBAR,
   UI_WTYPE_NODESOCKET,
-  UI_WTYPE_DATASETROW,
   UI_WTYPE_TREEROW,
 } uiWidgetTypeEnum;
 
@@ -3675,13 +3674,7 @@ static void widget_treerow(
   widget_treerow_exec(wcol, rect, state, roundboxalign, tree_row->indentation);
 }
 
-static void widget_datasetrow(
-    uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
-{
-  uiButDatasetRow *dataset_row = (uiButDatasetRow *)but;
-  BLI_assert(but->type == UI_BTYPE_DATASETROW);
-  widget_treerow_exec(wcol, rect, state, roundboxalign, dataset_row->indentation);
-}
+
 
 static void widget_nodesocket(
     uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
@@ -4476,9 +4469,6 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
       wt.custom = widget_progressbar;
       break;
 
-    case UI_WTYPE_DATASETROW:
-      wt.custom = widget_datasetrow;
-      break;
 
     case UI_WTYPE_TREEROW:
       wt.custom = widget_treerow;
@@ -4811,1

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list