UI: Remove based asset-view template

This UI list based template to show assets in panels was initially
introduced for the new pose library in Blender 3.0. It enabled showing
pose assets in a grid with big previews in the 3D View Sidebar. Since
then this UI element has been superseded by the asset shelf. The
template was planned for removal since then, see #110461.

Note that the asset shelf is only available in a few editors so far,
while the template was available in all editors. So it's possible that
some add-ons still rely on this template. However, I haven't found any
add-on using this template. I think it's been broken a few times and we
didn't get reports about it either. So removal seems fine.
This commit is contained in:
Julian Eisel 2025-06-10 18:44:51 +02:00 committed by Julian Eisel
parent f673acb6de
commit ae9ca35e3b
6 changed files with 0 additions and 510 deletions

View File

@ -2614,27 +2614,6 @@ void uiTemplateColormanagedViewSettings(uiLayout *layout,
int uiTemplateRecentFiles(uiLayout *layout, int rows);
void uiTemplateFileSelectPath(uiLayout *layout, bContext *C, 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(uiLayout *layout,
const bContext *C,
const char *list_id,
PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
PointerRNA *assets_dataptr,
const char *assets_propname,
PointerRNA *active_dataptr,
const char *active_propname,
const blender::ed::asset::AssetFilterSettings *filter_settings,
int display_flags,
const char *activate_opname,
PointerRNA *r_activate_op_properties,
const char *drag_opname,
PointerRNA *r_drag_op_properties);
namespace blender::ui {
void template_asset_shelf_popover(

View File

@ -55,7 +55,6 @@ set(SRC
interface_string_search.cc
interface_style.cc
templates/interface_template_asset_shelf_popover.cc
templates/interface_template_asset_view.cc
templates/interface_template_attribute_search.cc
templates/interface_template_bone_collection_tree.cc
templates/interface_template_cache_file.cc

View File

@ -1610,10 +1610,6 @@ void UI_OT_eyedropper_grease_pencil_color(wmOperatorType *ot);
/* `templates/interface_template_asset_shelf_popover.cc` */
std::optional<blender::StringRefNull> UI_asset_shelf_idname_from_button_context(const uiBut *but);
/* `templates/interface_template_asset_view.cc` */
uiListType *UI_UL_asset_view();
/**
* For use with #ui_rna_collection_search_update_fn.
*/

View File

@ -1,317 +0,0 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edinterface
*/
#include "AS_asset_representation.hh"
#include "DNA_space_types.h"
#include "BKE_screen.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "ED_asset.hh"
#include "ED_screen.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
#include "UI_interface.hh"
#include "WM_types.hh"
#include "interface_intern.hh"
using namespace blender;
using namespace blender::ed;
struct AssetViewListData {
AssetLibraryReference asset_library_ref;
asset::AssetFilterSettings filter_settings;
bScreen *screen;
bool show_names;
};
static void asset_view_item_but_drag_set(uiBut *but, AssetHandle *asset_handle)
{
blender::asset_system::AssetRepresentation *asset = asset::handle_get_representation(
asset_handle);
UI_but_dragflag_enable(but, UI_BUT_DRAG_FULL_BUT);
ID *id = asset->local_id();
if (id != nullptr) {
UI_but_drag_set_id(but, id);
return;
}
const eAssetImportMethod import_method = asset->get_import_method().value_or(
ASSET_IMPORT_APPEND_REUSE);
AssetImportSettings import_settings{};
import_settings.method = import_method;
import_settings.use_instance_collections = false;
UI_but_drag_set_asset(but,
asset,
import_settings,
asset::asset_preview_or_icon(*asset),
asset::asset_preview_icon_id(*asset));
}
static void asset_view_draw_item(uiList *ui_list,
const bContext * /*C*/,
uiLayout *layout,
PointerRNA * /*dataptr*/,
PointerRNA * /*itemptr*/,
int /*icon*/,
PointerRNA * /*active_dataptr*/,
const char * /*active_propname*/,
int index,
int /*flt_flag*/)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
AssetHandle asset_handle = asset::list::asset_handle_get_by_index(&list_data->asset_library_ref,
index);
asset_system::AssetRepresentation *asset = asset::handle_get_representation(&asset_handle);
PointerRNA file_ptr = RNA_pointer_create_discrete(
&list_data->screen->id,
&RNA_FileSelectEntry,
const_cast<FileDirEntry *>(asset_handle.file_data));
uiLayoutSetContextPointer(layout, "active_file", &file_ptr);
asset->ensure_previewable();
uiBlock *block = uiLayoutGetBlock(layout);
const bool show_names = list_data->show_names;
const float size_x = UI_preview_tile_size_x();
const float size_y = show_names ? UI_preview_tile_size_y() : UI_preview_tile_size_y_no_label();
uiBut *but = uiDefIconTextBut(block,
UI_BTYPE_PREVIEW_TILE,
0,
asset::asset_preview_icon_id(*asset),
show_names ? asset->get_name().c_str() : "",
0,
0,
size_x,
size_y,
nullptr,
0,
0,
"");
ui_def_but_icon(but,
asset::asset_preview_icon_id(*asset),
/* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
but->emboss = blender::ui::EmbossType::None;
if (!ui_list->dyn_data->custom_drag_optype) {
asset_view_item_but_drag_set(but, &asset_handle);
}
}
static void asset_view_filter_items(uiList *ui_list,
const bContext *C,
PointerRNA *dataptr,
const char *propname)
{
AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata;
asset::AssetFilterSettings &filter_settings = list_data->filter_settings;
uiListNameFilter name_filter(*ui_list);
UI_list_filter_and_sort_items(
ui_list,
C,
[&name_filter, list_data, &filter_settings](
const PointerRNA &itemptr, blender::StringRefNull name, int index) {
asset_system::AssetRepresentation *asset = asset::list::asset_get_by_index(
list_data->asset_library_ref, index);
if (!asset::filter_matches_asset(&filter_settings, *asset)) {
return UI_LIST_ITEM_NEVER_SHOW;
}
return name_filter(itemptr, name, index);
},
dataptr,
propname,
[list_data](const PointerRNA & /*itemptr*/, int index) -> std::string {
asset_system::AssetRepresentation *asset = asset::list::asset_get_by_index(
list_data->asset_library_ref, index);
return asset->get_name();
});
}
static void asset_view_listener(uiList * /*ui_list*/, wmRegionListenerParams *params)
{
const wmNotifier *notifier = params->notifier;
switch (notifier->category) {
case NC_ID: {
if (ELEM(notifier->action, NA_RENAME)) {
asset::list::storage_tag_main_data_dirty();
}
break;
}
}
if (asset::list::listen(params->notifier)) {
ED_region_tag_redraw(params->region);
}
}
uiListType *UI_UL_asset_view()
{
uiListType *list_type = (uiListType *)MEM_callocN(sizeof(*list_type), __func__);
STRNCPY(list_type->idname, "UI_UL_asset_view");
list_type->draw_item = asset_view_draw_item;
list_type->filter_items = asset_view_filter_items;
list_type->listener = asset_view_listener;
return list_type;
}
static void populate_asset_collection(const AssetLibraryReference &asset_library_ref,
PointerRNA &assets_dataptr,
const char *assets_propname)
{
PropertyRNA *assets_prop = RNA_struct_find_property(&assets_dataptr, assets_propname);
if (!assets_prop) {
RNA_warning("Asset collection not found");
return;
}
if (RNA_property_type(assets_prop) != PROP_COLLECTION) {
RNA_warning("Expected a collection property");
return;
}
if (!RNA_struct_is_a(RNA_property_pointer_type(&assets_dataptr, assets_prop), &RNA_AssetHandle))
{
RNA_warning("Expected a collection property for AssetHandle items");
return;
}
RNA_property_collection_clear(&assets_dataptr, assets_prop);
asset::list::iterate(asset_library_ref, [&](asset_system::AssetRepresentation & /*asset*/) {
/* XXX creating a dummy #RNA_AssetHandle collection item. It's #file_data will be null. This is
* because the #FileDirEntry may be freed while iterating, there's a cache for them with a
* maximum size. Further code will query as needed it using the collection index. */
PointerRNA itemptr;
RNA_property_collection_add(&assets_dataptr, assets_prop, &itemptr);
PointerRNA fileptr = RNA_pointer_create_discrete(nullptr, &RNA_FileSelectEntry, nullptr);
RNA_pointer_set(&itemptr, "file_data", fileptr);
return true;
});
}
void uiTemplateAssetView(uiLayout *layout,
const bContext *C,
const char *list_id,
PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
PointerRNA *assets_dataptr,
const char *assets_propname,
PointerRNA *active_dataptr,
const char *active_propname,
const asset::AssetFilterSettings *filter_settings,
const int display_flags,
const char *activate_opname,
PointerRNA *r_activate_op_properties,
const char *drag_opname,
PointerRNA *r_drag_op_properties)
{
if (!list_id || !list_id[0]) {
RNA_warning("Asset view needs a valid identifier");
return;
}
uiLayout *col = &layout->column(false);
PropertyRNA *asset_library_prop = RNA_struct_find_property(asset_library_dataptr,
asset_library_propname);
AssetLibraryReference asset_library_ref = asset::library_reference_from_enum_value(
RNA_property_enum_get(asset_library_dataptr, asset_library_prop));
uiLayout *row = &col->row(true);
if ((display_flags & UI_TEMPLATE_ASSET_DRAW_NO_LIBRARY) == 0) {
row->prop(
asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, UI_ITEM_NONE, "", ICON_NONE);
if (asset_library_ref.type != ASSET_LIBRARY_LOCAL) {
row->op("ASSET_OT_library_refresh", "", ICON_FILE_REFRESH);
}
}
asset::list::storage_fetch(&asset_library_ref, C);
const int tot_items = asset::list::size(&asset_library_ref);
populate_asset_collection(asset_library_ref, *assets_dataptr, assets_propname);
AssetViewListData *list_data = (AssetViewListData *)MEM_mallocN(sizeof(*list_data),
"AssetViewListData");
list_data->asset_library_ref = asset_library_ref;
list_data->filter_settings = *filter_settings;
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;
}
uiLayout *subcol = &col->column(false);
subcol->scale_x_set(0.8f);
subcol->scale_y_set(0.8f);
/* TODO can we have some kind of model-view API to handle referencing, filtering and lazy loading
* (of previews) of the items? */
uiList *list = uiTemplateList_ex(subcol,
C,
"UI_UL_asset_view",
list_id,
assets_dataptr,
assets_propname,
active_dataptr,
active_propname,
nullptr,
tot_items,
0,
UILST_LAYOUT_BIG_PREVIEW_GRID,
0,
template_list_flags,
list_data);
if (!list) {
/* List creation failed. */
MEM_freeN(list_data);
return;
}
if (activate_opname) {
PointerRNA *ptr = UI_list_custom_activate_operator_set(
list, activate_opname, r_activate_op_properties != nullptr);
if (r_activate_op_properties && ptr) {
*r_activate_op_properties = *ptr;
}
}
if (drag_opname) {
PointerRNA *ptr = UI_list_custom_drag_operator_set(
list, drag_opname, r_drag_op_properties != nullptr);
if (r_drag_op_properties && ptr) {
*r_drag_op_properties = *ptr;
}
}
}

View File

@ -1347,7 +1347,6 @@ PointerRNA *UI_list_custom_drag_operator_set(uiList *ui_list,
void ED_uilisttypes_ui()
{
WM_uilisttype_add(UI_UL_asset_view());
WM_uilisttype_add(UI_UL_cache_file_layers());
}

View File

@ -799,71 +799,6 @@ static void rna_uiTemplateEventFromKeymapItem(
uiTemplateEventFromKeymapItem(layout, text.value_or(""), kmi, true);
}
static void rna_uiTemplateAssetView(uiLayout *layout,
bContext *C,
const char *list_id,
PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
PointerRNA *assets_dataptr,
const char *assets_propname,
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,
PointerRNA *r_drag_op_properties)
{
blender::ed::asset::AssetFilterSettings filter_settings{};
filter_settings.id_types = filter_id_types ? filter_id_types : FILTER_ID_ALL;
uiTemplateAssetView(layout,
C,
list_id,
asset_library_dataptr,
asset_library_propname,
assets_dataptr,
assets_propname,
active_dataptr,
active_propname,
&filter_settings,
display_flags,
activate_opname,
r_activate_op_properties,
drag_opname,
r_drag_op_properties);
}
/**
* XXX Remove filter items that require more than 32 bits for storage. RNA enums don't support
* that currently.
*/
static const EnumPropertyItem *rna_uiTemplateAssetView_filter_id_types_itemf(
bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free)
{
EnumPropertyItem *items = nullptr;
int totitem = 0;
for (int i = 0; rna_enum_id_type_filter_items[i].identifier; i++) {
if (rna_enum_id_type_filter_items[i].flag > (1ULL << 31)) {
continue;
}
EnumPropertyItem tmp = {0, "", 0, "", ""};
tmp.value = rna_enum_id_type_filter_items[i].flag;
tmp.identifier = rna_enum_id_type_filter_items[i].identifier;
tmp.icon = rna_enum_id_type_filter_items[i].icon;
tmp.name = rna_enum_id_type_filter_items[i].name;
tmp.description = rna_enum_id_type_filter_items[i].description;
RNA_enum_item_add(&items, &totitem, &tmp);
}
RNA_enum_item_end(&items, &totitem);
*r_free = true;
return items;
}
static uiLayout *rna_uiLayoutBox(uiLayout *layout)
{
return &layout->box();
@ -1239,25 +1174,6 @@ void RNA_api_ui_layout(StructRNA *srna)
{0, nullptr, 0, nullptr, nullptr},
};
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, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem rna_enum_separator_type_items[] = {
{int(LayoutSeparatorType::Auto),
"AUTO",
@ -2300,88 +2216,6 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
api_ui_item_common_text(func);
func = RNA_def_function(srna, "template_asset_view", "rna_uiTemplateAssetView");
RNA_def_function_ui_description(func, "Item. A scrollable list of assets in a grid view");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
parm = RNA_def_string(func,
"list_id",
nullptr,
0,
"",
"Identifier of this asset view. Necessary to tell apart different asset "
"views and to identify an asset view read from a .blend");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func,
"asset_library_dataptr",
"AnyType",
"",
"Data from which to take the active asset library property");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
parm = RNA_def_string(
func, "asset_library_propname", nullptr, 0, "", "Identifier of the asset library property");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(
func, "assets_dataptr", "AnyType", "", "Data from which to take the asset list property");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
parm = RNA_def_string(
func, "assets_propname", nullptr, 0, "", "Identifier of the asset list property");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func,
"active_dataptr",
"AnyType",
"",
"Data from which to take the integer property, index of the active item");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
parm = RNA_def_string(
func,
"active_propname",
nullptr,
0,
"",
"Identifier of the integer property in active_data, index of the active item");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_property(func, "filter_id_types", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(parm, rna_enum_dummy_NULL_items);
RNA_def_property_enum_funcs(
parm, nullptr, nullptr, "rna_uiTemplateAssetView_filter_id_types_itemf");
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
RNA_def_enum_flag(func,
"display_options",
asset_view_template_options,
0,
"",
"Displaying options for the asset view");
RNA_def_string(func,
"activate_operator",
nullptr,
0,
"",
"Name of a custom operator to invoke when activating an item");
parm = RNA_def_pointer(
func,
"activate_operator_properties",
"OperatorProperties",
"",
"Operator properties to fill in for the custom activate operator passed to the template");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_RNAPTR);
RNA_def_function_output(func, parm);
RNA_def_string(func,
"drag_operator",
nullptr,
0,
"",
"Name of a custom operator to invoke when starting to drag an item. Never "
"invoked together with the ``active_operator`` (if set), it's either the drag or "
"the activate one");
parm = RNA_def_pointer(
func,
"drag_operator_properties",
"OperatorProperties",
"",
"Operator properties to fill in for the custom drag operator passed to the template");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_RNAPTR);
RNA_def_function_output(func, parm);
func = RNA_def_function(
srna, "template_light_linking_collection", "uiTemplateLightLinkingCollection");
RNA_def_function_ui_description(func,