[Bf-blender-cvs] [8b8fdcc6d5f] asset-browser-poselib: Asset View: Always show all poses, avoid double-scrollbar

Julian Eisel noreply at git.blender.org
Tue Apr 13 19:01:07 CEST 2021


Commit: 8b8fdcc6d5fb55dbeec7ac1eff722fd906ee9d7e
Author: Julian Eisel
Date:   Tue Apr 13 18:18:59 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rB8b8fdcc6d5fb55dbeec7ac1eff722fd906ee9d7e

Asset View: Always show all poses, avoid double-scrollbar

The asset view so far showed up to 5 items by default. If there were
more assets to be shown than that, it the list would become scrollable.
This would cause a scrollable box inside a scrollable region, which is
not nice for interaction. We can just expand the list so all assets are
in the layout, and the user can scroll the region rather than scrolling
the list.

Also hide the "grip" button so the list can't be resized. If needed we
could allow making the list smaller still, even if that causes double
scrolling again. For now keeping it simple.
Had to add a "no grip" option for that, so I changed the signature a bit
to avoid too many boolean arguments.

And another also: Adds missing return after error check.

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

M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/include/ED_asset.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_buttons.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index b7e1d34e948..5cf150001f4 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -172,6 +172,7 @@ class AssetList : NonCopyable {
   bool needsRefetch() const;
   void iterate(AssetListIterFn fn) const;
   bool listen(const wmNotifier &notifier) const;
+  int size() const;
   void tagMainDataDirty() const;
   void remapID(ID *id_old, ID *id_new) const;
   StringRef filepath() const;
@@ -322,6 +323,14 @@ bool AssetList::listen(const wmNotifier &notifier) const
   return false;
 }
 
+/**
+ * \return The number of assets in the list.
+ */
+int AssetList::size() const
+{
+  return filelist_files_ensure(filelist_);
+}
+
 void AssetList::tagMainDataDirty() const
 {
   if (filelist_needs_reset_on_main_changes(filelist_)) {
@@ -578,6 +587,19 @@ bool ED_assetlist_listen(const AssetLibraryReference *library_reference,
   return false;
 }
 
+/**
+ * \return The number of assets stored in the asset list for \a library_reference, or -1 if there
+ *         is no list fetched for it.
+ */
+int ED_assetlist_size(const AssetLibraryReference *library_reference)
+{
+  AssetList *list = AssetListStorage::lookup_list(*library_reference);
+  if (list) {
+    return list->size();
+  }
+  return -1;
+}
+
 /**
  * Tag all asset lists in the storage that show main data as needing an update (refetch).
  *
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index 08994f859f3..49e28407f0f 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -76,6 +76,7 @@ const char *ED_assetlist_library_path(const struct AssetLibraryReference *librar
 
 bool ED_assetlist_listen(const struct AssetLibraryReference *library_reference,
                          const struct wmNotifier *notifier);
+int ED_assetlist_size(const struct AssetLibraryReference *library_reference);
 
 void ED_operatortypes_asset(void);
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 99f53a81636..247a8bdc5ad 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2150,6 +2150,13 @@ void uiTemplateCacheFile(uiLayout *layout,
 
 /* Default UIList class name, keep in sync with its declaration in bl_ui/__init__.py */
 #define UI_UL_DEFAULT_CLASS_NAME "UI_UL_list"
+enum uiTemplateListFlags {
+  UI_TEMPLATE_LIST_FLAG_NONE = 0,
+  UI_TEMPLATE_LIST_SORT_REVERSE = (1 << 0),
+  UI_TEMPLATE_LIST_SORT_LOCK = (1 << 1),
+  /* Don't allow resizing the list, i.e. don't add the grip button. */
+  UI_TEMPLATE_LIST_NO_GRIP = (1 << 2),
+};
 void uiTemplateList(uiLayout *layout,
                     struct bContext *C,
                     const char *listtype_name,
@@ -2163,8 +2170,7 @@ void uiTemplateList(uiLayout *layout,
                     int maxrows,
                     int layout_type,
                     int columns,
-                    bool sort_reverse,
-                    bool sort_lock);
+                    enum uiTemplateListFlags flags);
 struct uiList *uiTemplateList_ex(uiLayout *layout,
                                  struct bContext *C,
                                  const char *listtype_name,
@@ -2178,8 +2184,7 @@ struct uiList *uiTemplateList_ex(uiLayout *layout,
                                  int maxrows,
                                  int layout_type,
                                  int columns,
-                                 bool sort_reverse,
-                                 bool sort_lock,
+                                 enum uiTemplateListFlags flags,
                                  void *customdata);
 void uiTemplateNodeLink(uiLayout *layout,
                         struct bContext *C,
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 8eff15fe765..1f2702abeb0 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -217,6 +217,7 @@ void uiTemplateAssetView(uiLayout *layout,
 
   ED_assetlist_storage_fetch(&asset_library, filter_settings, C);
   ED_assetlist_ensure_previews_job(&asset_library, C);
+  const int tot_items = ED_assetlist_size(&asset_library);
 
   asset_view_template_refresh_asset_collection(asset_library, *assets_dataptr, assets_propname);
 
@@ -236,16 +237,16 @@ void uiTemplateAssetView(uiLayout *layout,
                                    active_dataptr,
                                    active_propname,
                                    nullptr,
-                                   0,
+                                   tot_items,
                                    0,
                                    UILST_LAYOUT_BIG_PREVIEW_GRID,
                                    0,
-                                   false,
-                                   false,
+                                   UI_TEMPLATE_LIST_NO_GRIP,
                                    list_data);
   if (!list) {
     /* List creation failed. */
     MEM_freeN(list_data);
+    return;
   }
 
   if (activate_opname) {
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 783122912b8..cd60ec5d006 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -6266,7 +6266,8 @@ static void ui_template_list_layout_draw(bContext *C,
                                          uiLayout *layout,
                                          TemplateListInputData *input_data,
                                          TemplateListItems *items,
-                                         const TemplateListLayoutDrawData *layout_data)
+                                         const TemplateListLayoutDrawData *layout_data,
+                                         const enum uiTemplateListFlags flags)
 {
   uiListDyn *dyn_data = ui_list->dyn_data;
   const char *active_propname = RNA_property_identifier(input_data->activeprop);
@@ -6637,6 +6638,8 @@ static void ui_template_list_layout_draw(bContext *C,
   }
 
   if (glob) {
+    const bool add_grip_but = (flags & UI_TEMPLATE_LIST_NO_GRIP) == 0;
+
     /* About #UI_BTYPE_GRIP drag-resize:
      * We can't directly use results from a grip button, since we have a
      * rather complex behavior here (sizing by discrete steps and, overall, auto-size feature).
@@ -6675,21 +6678,23 @@ static void ui_template_list_layout_draw(bContext *C,
                              TIP_("Hide filtering options"));
       UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
 
-      but = uiDefIconButI(subblock,
-                          UI_BTYPE_GRIP,
-                          0,
-                          ICON_GRIP,
-                          0,
-                          0,
-                          UI_UNIT_X * 10.0f,
-                          UI_UNIT_Y * 0.5f,
-                          &dyn_data->resize,
-                          0.0,
-                          0.0,
-                          0,
-                          0,
-                          "");
-      UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
+      if (add_grip_but) {
+        but = uiDefIconButI(subblock,
+                            UI_BTYPE_GRIP,
+                            0,
+                            ICON_GRIP,
+                            0,
+                            0,
+                            UI_UNIT_X * 10.0f,
+                            UI_UNIT_Y * 0.5f,
+                            &dyn_data->resize,
+                            0.0,
+                            0.0,
+                            0,
+                            0,
+                            "");
+        UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
+      }
 
       UI_block_emboss_set(subblock, UI_EMBOSS);
 
@@ -6730,21 +6735,23 @@ static void ui_template_list_layout_draw(bContext *C,
                              TIP_("Show filtering options"));
       UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
 
-      but = uiDefIconButI(subblock,
-                          UI_BTYPE_GRIP,
-                          0,
-                          ICON_GRIP,
-                          0,
-                          0,
-                          UI_UNIT_X * 10.0f,
-                          UI_UNIT_Y * 0.5f,
-                          &dyn_data->resize,
-                          0.0,
-                          0.0,
-                          0,
-                          0,
-                          "");
-      UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
+      if (add_grip_but) {
+        but = uiDefIconButI(subblock,
+                            UI_BTYPE_GRIP,
+                            0,
+                            ICON_GRIP,
+                            0,
+                            0,
+                            UI_UNIT_X * 10.0f,
+                            UI_UNIT_Y * 0.5f,
+                            &dyn_data->resize,
+                            0.0,
+                            0.0,
+                            0,
+                            0,
+                            "");
+        UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
+      }
 
       UI_block_emboss_set(subblock, UI_EMBOSS);
     }
@@ -6764,8 +6771,7 @@ uiList *uiTemplateList_ex(uiLayout *layout,
                           int maxrows,
                           int layout_type,
                           int columns,
-                          bool sort_reverse,
-                          bool sort_lock,
+                          enum uiTemplateListFlags flags,
                           void *customdata)
 {
   TemplateListInputData input_data = {0};
@@ -6789,7 +6795,12 @@ uiList *uiTemplateList_ex(uiLayout *layout,
   uiListFilterItemsFunc filter_items = ui_list_type->filter_items ? ui_list_type->filter_items :
    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list