[Bf-blender-cvs] [6324721d7a0] temp-asset-template-extra-options: Asset Template: Extra UI options
Dalai Felinto
noreply at git.blender.org
Mon Sep 13 18:42:40 CEST 2021
Commit: 6324721d7a09f027e5055ae0e64de8fe34667070
Author: Dalai Felinto
Date: Mon Sep 13 18:40:21 2021 +0200
Branches: temp-asset-template-extra-options
https://developer.blender.org/rB6324721d7a09f027e5055ae0e64de8fe34667070
Asset Template: Extra UI options
This allow users to show/hide:
* Library name / refresh.
* Assets names.
* Filter.
===================================================================
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/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..68fd8fff39a 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2209,6 +2209,8 @@ 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),
+ UI_TEMPLATE_LIST_NO_FILTER_OPTIONS = (1 << 3),
+ UI_TEMPLATE_LIST_NO_NAMES = (1 << 4),
UI_TEMPLATE_LIST_FLAGS_LAST
};
@@ -2289,6 +2291,12 @@ int uiTemplateRecentFiles(struct uiLayout *layout, int rows);
void uiTemplateFileSelectPath(uiLayout *layout,
struct bContext *C,
struct FileSelectParams *params);
+
+enum {
+ UI_TEMPLATE_ASSET_DRAW_NAMES = (1 << 0),
+ UI_TEMPLATE_ASSET_DRAW_FILTER = (1 << 1),
+ UI_TEMPLATE_ASSET_DRAW_LIBRARY = (1 << 2),
+};
void uiTemplateAssetView(struct uiLayout *layout,
struct bContext *C,
const char *list_id,
@@ -2299,6 +2307,7 @@ void uiTemplateAssetView(struct uiLayout *layout,
struct PointerRNA *active_dataptr,
const char *active_propname,
const struct AssetFilterSettings *filter_settings,
+ const int draw_settings,
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..b90eceee67a 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,
@@ -98,15 +99,16 @@ static void asset_view_draw_item(uiList *ui_list,
/* 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 bool show_names = list_data->show_names;
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,
- size_y,
+ show_names ? size_y : size_y - UI_UNIT_Y,
nullptr,
0,
0,
@@ -202,6 +204,7 @@ void uiTemplateAssetView(uiLayout *layout,
PointerRNA *active_dataptr,
const char *active_propname,
const AssetFilterSettings *filter_settings,
+ const int draw_settings,
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 (draw_settings & UI_TEMPLATE_ASSET_DRAW_LIBRARY) {
+ 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 = (draw_settings & UI_TEMPLATE_ASSET_DRAW_NAMES) != 0;
+
+ uiTemplateListFlags template_list_flags = UI_TEMPLATE_LIST_NO_GRIP;
+ if ((draw_settings & UI_TEMPLATE_ASSET_DRAW_NAMES) == 0) {
+ template_list_flags |= UI_TEMPLATE_LIST_NO_NAMES;
+ }
+ if ((draw_settings & UI_TEMPLATE_ASSET_DRAW_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/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index e06cc39a88b..6c6de3cb8b2 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -622,6 +622,9 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
PointerRNA *active_dataptr,
const char *active_propname,
int filter_id_types,
+ const bool show_names,
+ const bool show_filters,
+ const bool show_library_selector,
const char *activate_opname,
PointerRNA *r_activate_op_properties,
const char *drag_opname,
@@ -630,6 +633,11 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
AssetFilterSettings filter_settings = {
.id_types = filter_id_types ? filter_id_types : FILTER_ID_ALL,
};
+
+ int draw_settings = (show_names ? UI_TEMPLATE_ASSET_DRAW_NAMES : 0) |
+ (show_filters ? UI_TEMPLATE_ASSET_DRAW_FILTER : 0) |
+ (show_library_selector ? UI_TEMPLATE_ASSET_DRAW_LIBRARY : 0);
+
uiTemplateAssetView(layout,
C,
list_id,
@@ -640,6 +648,7 @@ static void rna_uiTemplateAssetView(uiLayout *layout,
active_dataptr,
active_propname,
&filter_settings,
+ draw_settings,
activate_opname,
r_activate_op_properties,
drag_opname,
@@ -1839,6 +1848,14 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_property_enum_items(parm, DummyRNA_NULL_items);
RNA_def_property_enum_funcs(parm, NULL, NULL, "rna_uiTemplateAssetView_filter_id_types_itemf");
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+
+ /* Drawing options. */
+ RNA_def_boolean(func, "show_names", true, "Show Names", "Show the name of the assets");
+ RNA_def_boolean(func, "show_filters", true, "Show Filters", "Show the filter options");
+ RNA_def_boolean(
+ func, "show_library_selector", true, "Show Library Selector", "Show the library selector");
+
+ /* Return options. */
RNA_def_string(func,
"activate_operator",
NULL,
More information about the Bf-blender-cvs
mailing list