[Bf-blender-cvs] [96543946b2d] ui-asset-view-template: Use custom .py property for active asset index, stored in the workspace
Julian Eisel
noreply at git.blender.org
Tue Mar 16 15:44:30 CET 2021
Commit: 96543946b2d7c3c911442cbd2c83d42e492f8ee5
Author: Julian Eisel
Date: Tue Mar 16 15:32:46 2021 +0100
Branches: ui-asset-view-template
https://developer.blender.org/rB96543946b2d7c3c911442cbd2c83d42e492f8ee5
Use custom .py property for active asset index, stored in the workspace
Previously I just used the active color index of the first palette to
get things to work.
I would've preferred if the asset view template could register own
properties and store them in the `UIList` it creates. That way you could
have multiple asset views with entirely independent data. But since this
isn't possible, we need a different way to store such data, I think the
workspace makes sense. It should still be possible to store different
data for different use-cases, e.g. to show a pose asset list in pose
mode and a material asset list in object mode. So idea is to let
scripts/add-ons register custom properties for their specific use case
(e.g. "Active Pose Asset" for the pose libraries).
===================================================================
M release/scripts/startup/bl_ui/__init__.py
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_template_asset_view.cc
M source/blender/makesrna/intern/rna_ui_api.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index b3131e64df7..2fd7eac79e1 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -116,13 +116,14 @@ def register():
for cls in mod.classes:
register_class(cls)
- # space_userprefs.py
from bpy.props import (
EnumProperty,
+ IntProperty,
StringProperty,
)
- from bpy.types import WindowManager
+ from bpy.types import WorkSpace, WindowManager
+ # space_userprefs.py
def addon_filter_items(_self, _context):
import addon_utils
@@ -164,6 +165,14 @@ def register():
)
# done...
+ # space_view3d.py
+ WorkSpace.active_pose_asset_index = IntProperty(
+ name="Active Pose Asset",
+ # TODO explain which list the index belongs to, or how it can be used to get the pose.
+ description="Per workspace index of the active pose asset"
+ )
+ # done...
+
def unregister():
from bpy.utils import unregister_class
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 800e20b251a..95c6a59ea7c 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -7017,7 +7017,7 @@ class VIEW3D_PT_asset_testing(Panel):
workspace = context.workspace
- layout.template_asset_view(workspace, "active_asset_library")
+ layout.template_asset_view(workspace, "active_asset_library", workspace, "active_pose_asset_index")
# Grease Pencil Object - Multiframe falloff tools
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 6566d90fe84..e44dd762977 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2235,8 +2235,10 @@ void uiTemplateFileSelectPath(uiLayout *layout,
struct FileSelectParams *params);
void uiTemplateAssetView(struct uiLayout *layout,
struct bContext *C,
- struct PointerRNA *ptr,
+ struct PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
+ struct PointerRNA *active_dataptr,
+ const char *active_propname,
const struct AssetFilterSettings *filter_settings);
/* items */
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 9256f49930e..8470a6904e2 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -21,6 +21,8 @@
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
+#include "BKE_screen.h"
+
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
@@ -32,19 +34,14 @@
#include "MEM_guardedalloc.h"
+#include "RNA_access.h"
+
#include "UI_interface.h"
#include "WM_api.h"
#include "interface_intern.h"
-/* TODO temporary includes for palettes. */
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_screen.h"
-#include "DNA_brush_types.h"
-#include "RNA_access.h"
-
struct AssetViewListData {
AssetLibraryReference asset_library;
bScreen *screen;
@@ -160,19 +157,20 @@ static void asset_view_template_list_item_iter_fn(PointerRNA *UNUSED(dataptr),
void uiTemplateAssetView(uiLayout *layout,
bContext *C,
- PointerRNA *ptr,
+ PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
+ PointerRNA *active_dataptr,
+ const char *active_propname,
const AssetFilterSettings *filter_settings)
{
- Palette *palette = (Palette *)CTX_data_main(C)->palettes.first;
-
uiLayout *col = uiLayoutColumn(layout, false);
- PropertyRNA *asset_library_prop = RNA_struct_find_property(ptr, asset_library_propname);
- uiItemFullR(col, ptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
+ PropertyRNA *asset_library_prop = RNA_struct_find_property(asset_library_dataptr,
+ asset_library_propname);
+ uiItemFullR(col, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
AssetLibraryReference asset_library = ED_asset_library_reference_from_enum_value(
- RNA_property_enum_get(ptr, asset_library_prop));
+ RNA_property_enum_get(asset_library_dataptr, asset_library_prop));
ED_assetlist_fetch(&asset_library, filter_settings, C);
ED_assetlist_ensure_previews_job(&asset_library, C);
@@ -181,11 +179,6 @@ void uiTemplateAssetView(uiLayout *layout,
list_data->asset_library = asset_library;
list_data->screen = CTX_wm_screen(C);
- /* TODO can we store more properties in the UIList? Asset specific filtering, */
- /* TODO how can this be refreshed on updates? Maybe a notifier listener callback for the
- * uiListType? */
- PointerRNA colors_poin;
- RNA_pointer_create(&palette->id, &RNA_PaletteColors, palette, &colors_poin);
PointerRNA rna_nullptr = PointerRNA_NULL;
/* TODO can we have some kind of model-view API to handle referencing, filtering and lazy loading
* (of previews) of the items? */
@@ -196,8 +189,8 @@ void uiTemplateAssetView(uiLayout *layout,
"asset_view",
&rna_nullptr,
"",
- &colors_poin,
- "active_index",
+ active_dataptr,
+ active_propname,
nullptr,
0,
0,
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 720600e7502..21588b523f7 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -572,14 +572,22 @@ static void rna_uiTemplateEventFromKeymapItem(
static void rna_uiTemplateAssetView(uiLayout *layout,
bContext *C,
- PointerRNA *ptr,
+ PointerRNA *asset_library_dataptr,
const char *asset_library_propname,
+ PointerRNA *active_dataptr,
+ const char *active_propname,
int filter_id_types)
{
AssetFilterSettings filter_settings = {
.id_types = filter_id_types ? filter_id_types : FILTER_ID_ALL,
};
- uiTemplateAssetView(layout, C, ptr, asset_library_propname, &filter_settings);
+ uiTemplateAssetView(layout,
+ C,
+ asset_library_dataptr,
+ asset_library_propname,
+ active_dataptr,
+ active_propname,
+ &filter_settings);
}
/**
@@ -1724,12 +1732,29 @@ void RNA_api_ui_layout(StructRNA *srna)
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_pointer(
- func, "data", "AnyType", "", "Data from which to take the active asset library property");
+ 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_property", NULL, 0, "", "Identifier of the asset library");
RNA_def_parameter_flags(parm, 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",
+ NULL,
+ 0,
+ "",
+ "Identifier of the integer property in active_data, index of the active item");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_property(func, "filter_id_types", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(parm, DummyRNA_NULL_items);
RNA_def_property_enum_funcs(parm, NULL, NULL, "rna_uiTemplateAssetView_filter_id_types_itemf");
More information about the Bf-blender-cvs
mailing list