[Bf-blender-cvs] [3ff60bcad8c] master: Asset Template: Extra UI options

Dalai Felinto noreply at git.blender.org
Mon Sep 13 19:52:40 CEST 2021


Commit: 3ff60bcad8cccd6c2f82ea44527f4e6ef619f0be
Author: Dalai Felinto
Date:   Mon Sep 13 18:40:21 2021 +0200
Branches: master
https://developer.blender.org/rB3ff60bcad8cccd6c2f82ea44527f4e6ef619f0be

Asset Template: Extra UI options

This allow users to show/hide:
* Library name / refresh.
* Assets names.
* Filter.

To set them in Python use:
display_options={'NO_NAMES', 'NO_FILTER', 'NO_LIBRARY'}

With contributions by Julian Eisel.

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

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/editors/interface/interface_template_list.cc
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 7211cf9f893..916105b0f8e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2209,6 +2209,11 @@ enum uiTemplateListFlags {
   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),
+  /** Do not show filtering options, not even the button to expand/collapse them. Also hides the
+   * grip button. */
+  UI_TEMPLATE_LIST_NO_FILTER_OPTIONS = (1 << 3),
+  /** For #UILST_LAYOUT_BIG_PREVIEW_GRID, don't reserve space for the name label. */
+  UI_TEMPLATE_LIST_NO_NAMES = (1 << 4),
 
   UI_TEMPLATE_LIST_FLAGS_LAST
 };
@@ -2289,6 +2294,12 @@ int uiTemplateRecentFiles(struct uiLayout *layout, int rows);
 void uiTemplateFileSelectPath(uiLayout *layout,
                               struct bContext *C,
                               struct FileSelectParams *params);
+
+enum {
+  UI_TEMPLATE_ASSET_DRAW_NO_NAMES = (1 << 0),
+  UI_TEMPLATE_ASSET_DRAW_NO_FILTER = (1 << 1),
+  UI_TEMPLATE_ASSET_DRAW_NO_LIBRARY = (1 << 2),
+};
 void uiTemplateAssetView(struct uiLayout *layout,
                          struct bContext *C,
                          const char *list_id,
@@ -2299,6 +2310,7 @@ void uiTemplateAssetView(struct uiLayout *layout,
                          struct PointerRNA *active_dataptr,
                          const char *active_propname,
                          const struct AssetFilterSettings *filter_settings,
+                         const int display_flags,
                          const char *activate_opname,
                          struct PointerRNA *r_activate_op_properties,
                          const char *drag_opname,
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 9b601727e29..f27b37a27de 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -46,6 +46,7 @@
 struct AssetViewListData {
   AssetLibraryReference asset_library_ref;
   bScreen *screen;
+  bool show_names;
 };
 
 static void asset_view_item_but_drag_set(uiBut *but,
@@ -95,14 +96,15 @@ static void asset_view_draw_item(uiList *ui_list,
   uiLayoutSetContextPointer(layout, "asset_handle", itemptr);
 
   uiBlock *block = uiLayoutGetBlock(layout);
+  const bool show_names = list_data->show_names;
   /* TODO ED_fileselect_init_layout(). Share somehow? */
   const float size_x = (96.0f / 20.0f) * UI_UNIT_X;
-  const float size_y = (96.0f / 20.0f) * UI_UNIT_Y;
+  const float size_y = (96.0f / 20.0f) * UI_UNIT_Y - (show_names ? 0 : UI_UNIT_Y);
   uiBut *but = uiDefIconTextBut(block,
                                 UI_BTYPE_PREVIEW_TILE,
                                 0,
                                 ED_asset_handle_get_preview_icon_id(asset_handle),
-                                ED_asset_handle_get_name(asset_handle),
+                                show_names ? ED_asset_handle_get_name(asset_handle) : "",
                                 0,
                                 0,
                                 size_x,
@@ -202,6 +204,7 @@ void uiTemplateAssetView(uiLayout *layout,
                          PointerRNA *active_dataptr,
                          const char *active_propname,
                          const AssetFilterSettings *filter_settings,
+                         const int display_flags,
                          const char *activate_opname,
                          PointerRNA *r_activate_op_properties,
                          const char *drag_opname,
@@ -220,9 +223,11 @@ void uiTemplateAssetView(uiLayout *layout,
       RNA_property_enum_get(asset_library_dataptr, asset_library_prop));
 
   uiLayout *row = uiLayoutRow(col, true);
-  uiItemFullR(row, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
-  if (asset_library_ref.type != ASSET_LIBRARY_LOCAL) {
-    uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_list_refresh");
+  if ((display_flags & UI_TEMPLATE_ASSET_DRAW_NO_LIBRARY) == 0) {
+    uiItemFullR(row, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
+    if (asset_library_ref.type != ASSET_LIBRARY_LOCAL) {
+      uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_list_refresh");
+    }
   }
 
   ED_assetlist_storage_fetch(&asset_library_ref, C);
@@ -236,6 +241,15 @@ void uiTemplateAssetView(uiLayout *layout,
                                                                   "AssetViewListData");
   list_data->asset_library_ref = asset_library_ref;
   list_data->screen = CTX_wm_screen(C);
+  list_data->show_names = (display_flags & UI_TEMPLATE_ASSET_DRAW_NO_NAMES) == 0;
+
+  uiTemplateListFlags template_list_flags = UI_TEMPLATE_LIST_NO_GRIP;
+  if ((display_flags & UI_TEMPLATE_ASSET_DRAW_NO_NAMES) != 0) {
+    template_list_flags |= UI_TEMPLATE_LIST_NO_NAMES;
+  }
+  if ((display_flags & UI_TEMPLATE_ASSET_DRAW_NO_FILTER) != 0) {
+    template_list_flags |= UI_TEMPLATE_LIST_NO_FILTER_OPTIONS;
+  }
 
   /* TODO can we have some kind of model-view API to handle referencing, filtering and lazy loading
    * (of previews) of the items? */
@@ -252,7 +266,7 @@ void uiTemplateAssetView(uiLayout *layout,
                                    0,
                                    UILST_LAYOUT_BIG_PREVIEW_GRID,
                                    0,
-                                   UI_TEMPLATE_LIST_NO_GRIP,
+                                   template_list_flags,
                                    list_data);
   if (!list) {
     /* List creation failed. */
diff --git a/source/blender/editors/interface/interface_template_list.cc b/source/blender/editors/interface/interface_template_list.cc
index 0ab45ea0f81..8246759ad36 100644
--- a/source/blender/editors/interface/interface_template_list.cc
+++ b/source/blender/editors/interface/interface_template_list.cc
@@ -944,10 +944,16 @@ static void ui_template_list_layout_draw(bContext *C,
       /* For scrollbar. */
       row = uiLayoutRow(glob, false);
 
+      const bool show_names = (flags & UI_TEMPLATE_LIST_NO_NAMES) == 0;
+
       /* TODO ED_fileselect_init_layout(). Share somehow? */
       float size_x = (96.0f / 20.0f) * UI_UNIT_X;
       float size_y = (96.0f / 20.0f) * UI_UNIT_Y;
 
+      if (!show_names) {
+        size_y -= UI_UNIT_Y;
+      }
+
       const int cols_per_row = MAX2((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x, 1);
       uiLayout *grid = uiLayoutGridFlow(row, true, cols_per_row, true, true, true);
 
@@ -1033,7 +1039,8 @@ static void ui_template_list_layout_draw(bContext *C,
       break;
   }
 
-  if (glob) {
+  const bool add_filters_but = (flags & UI_TEMPLATE_LIST_NO_FILTER_OPTIONS) == 0;
+  if (glob && add_filters_but) {
     const bool add_grip_but = (flags & UI_TEMPLATE_LIST_NO_GRIP) == 0;
 
     /* About #UI_BTYPE_GRIP drag-resize:
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index a2b86ccd947..0dc7c2d3f9a 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -5443,13 +5443,20 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
   rcti trect = *rect;
   const float text_size = UI_UNIT_Y;
   float font_dims[2] = {0.0f, 0.0f};
+  const bool has_text = name && name[0];
 
-  /* draw icon in rect above the space reserved for the label */
-  rect->ymin += text_size;
+  if (has_text) {
+    /* draw icon in rect above the space reserved for the label */
+    rect->ymin += text_size;
+  }
   GPU_blend(GPU_BLEND_ALPHA);
   widget_draw_preview(iconid, 1.0f, rect);
   GPU_blend(GPU_BLEND_NONE);
 
+  if (!has_text) {
+    return;
+  }
+
   BLF_width_and_height(
       fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
 
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index e06cc39a88b..f96b3fc5eee 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -622,6 +622,7 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
                                     PointerRNA *active_dataptr,
                                     const char *active_propname,
                                     int filter_id_types,
+                                    int display_flags,
                                     const char *activate_opname,
                                     PointerRNA *r_activate_op_properties,
                                     const char *drag_opname,
@@ -630,6 +631,7 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
   AssetFilterSettings filter_settings = {
       .id_types = filter_id_types ? filter_id_types : FILTER_ID_ALL,
   };
+
   uiTemplateAssetView(layout,
                       C,
                       list_id,
@@ -640,6 +642,7 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
                       active_dataptr,
                       active_propname,
                       &filter_settings,
+                      display_flags,
                       activate_opname,
                       r_activate_op_properties,
                       drag_opname,
@@ -878,6 +881,25 @@ void RNA_api_ui_layout(StructRNA *srna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem asset_view_template_options[] = {
+      {UI_TEMPLATE_ASSET_DRAW_NO_NAMES,
+       "NO_NAMES",
+       0,
+       "",
+       "Do not display the name of each asset underneath preview images"},
+      {UI_TEMPLATE_ASSET_DRAW_NO_FILTER,
+       "NO_FILTER",
+       0,
+       "",
+       "Do not display buttons for filtering the available assets"},
+      {UI_TEMPLATE_ASSET_DRAW_NO_LIBRARY,
+       "NO_LIBRARY",
+       0,
+       "",
+       "Do not display buttons to choose or refresh an asset library"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   static float node_socket_color_default[] = {0.0f, 0.0f, 0.0f, 1.0f};
 
   /* simple layout specifiers */
@@ -1839

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list