36#include "RNA_prototypes.hh"
47 std::optional<AssetWeakReference> active_asset_;
48 std::optional<asset_system::AssetCatalogFilter> catalog_filter_ = std::nullopt;
59 void set_catalog_filter(
const std::optional<asset_system::AssetCatalogFilter> &catalog_filter);
64 bool allow_asset_drag_ =
true;
85 std::optional<eWM_DragDataType>
get_drag_type()
const override;
91 : library_ref_(library_ref), shelf_(
shelf)
93 if (
shelf.type->get_active_asset) {
94 if (const AssetWeakReference *weak_ref = shelf.type->get_active_asset(shelf.type)) {
95 active_asset_ = *weak_ref;
98 active_asset_.reset();
117 if (catalog_filter_ && !catalog_filter_->contains(asset_data.
catalog_id)) {
132 if (!shelf_.type->drag_operator.empty()) {
144 !
asset.is_online_only())
166 const std::optional<asset_system::AssetCatalogFilter> &catalog_filter)
168 if (catalog_filter) {
169 catalog_filter_.emplace(*catalog_filter);
172 catalog_filter_ = std::nullopt;
185 if (!active_catalog) {
189 return library.catalog_service().create_catalog_filter(active_catalog->
catalog_id);
203 allow_asset_drag_ =
false;
232 button_context_ptr_set(
241 button_operator_set(item_but, activate_op->
optype, activate_op->opcontext, activate_op->opptr);
242 button_operator_set_never_call(item_but);
244 MEM_delete(activate_op->opptr);
249 button_view_item_draw_size_set(
252 button_func_tooltip_custom_set(
265 asset_.ensure_previewable(
C);
267 const int preview_id = [&]() ->
int {
273 return ICON_PREVIEW_LOADING;
289 if (asset_.is_online_only()) {
290 ui::Button *online_icon = uiItemL_ex(&overlay_row,
"", ICON_INTERNET,
false,
false);
291 button_label_alpha_factor_set(online_icon, 0.6f);
292 button_label_draw_icon_border_set(online_icon,
true);
294 else if (asset_.needs_download()) {
296 &overlay_row,
"", ICON_STATUS_WARNING_FILLED,
false,
false);
297 button_label_alpha_factor_set(needs_download_icon, 0.6f);
298 button_label_draw_icon_border_set(needs_download_icon,
true);
302 if (
is_hovered() && asset_.needs_download()) {
325 std::max(0.0f, (preview_height - overlay_height +
U.pixelsize) * 0.5f),
333 "ASSET_OT_asset_download",
365 if (!asset_view.active_asset_) {
369 const bool matches = *asset_view.active_asset_ == weak_ref;
380 if (asset_.is_online_only()) {
388 &
C, activate_op->optype, activate_op->opcontext, activate_op->opptr,
nullptr);
390 MEM_delete(activate_op->opptr);
397 return fnmatch(filter_string.
c_str(), asset_name.
c_str(), FNM_CASEFOLD) == 0;
405 if (!allow_asset_drag_ && shelf_type.
drag_operator.empty()) {
408 return std::make_unique<AssetDragController>(this->
get_view(), asset_);
419 return search_string;
439 std::unique_ptr asset_view = std::make_unique<AssetView>(library_ref,
shelf);
445 *block,
"asset shelf asset view", std::move(asset_view));
453 std::optional<StringRef> empty_list_hint;
455 const bool has_active_catalog =
shelf.settings.active_catalog_path &&
456 shelf.settings.active_catalog_path[0];
458 empty_list_hint = has_active_catalog ?
RPT_(
"No assets in this catalog.") :
459 RPT_(
"No assets found.");
462 empty_list_hint = has_active_catalog ?
RPT_(
"No search results in this catalog.") :
463 RPT_(
"No results found.");
466 if (empty_list_hint) {
474 column.
label(*empty_list_hint, ICON_STATUS_INFO);
476 std::optional<StringRef> access_filter_hint;
478 access_filter_hint =
RPT_(
"\"Online Only\" filter is enabled.");
481 access_filter_hint =
RPT_(
"\"Offline Only\" filter is enabled.");
484 if (access_filter_hint) {
485 column.
label(*access_filter_hint, ICON_BLANK1);
522 MEM_delete(drag_op->opptr);
536 ID *local_id = asset_.local_id();
538 return static_cast<void *
>(local_id);
547 import_settings.
method = import_method;
Main runtime representation of an asset.
#define ICON_DEFAULT_WIDTH_SCALE
#define ICON_DEFAULT_HEIGHT_SCALE
constexpr const char * c_str() const
const CatalogID catalog_id
constexpr bool is_empty() const
std::optional< eWM_DragDataType > get_drag_type() const override
AssetDragController(ui::AbstractGridView &view, asset_system::AssetRepresentation &asset)
void * create_drag_data() const override
void on_drag_start(bContext &C, ui::AbstractViewItem &item) override
void build_context_menu(bContext &C, ui::Layout &column) const override
bool should_be_filtered_visible(StringRefNull filter_string) const override
void build_grid_tile(const bContext &C, ui::Layout &layout) const override
void on_activate(bContext &C) override
void disable_asset_drag()
AssetViewItem(asset_system::AssetRepresentation &asset_, StringRef identifier, StringRef label)
std::unique_ptr< ui::AbstractViewItemDragController > create_drag_controller() const override
std::optional< bool > should_be_active() const override
friend class AssetDragController
bool begin_filtering(const bContext &C) const override
AssetView(const AssetLibraryReference &library_ref, const AssetShelf &shelf)
void set_catalog_filter(const std::optional< asset_system::AssetCatalogFilter > &catalog_filter)
void build_items() override
friend class AssetViewItem
AbstractGridView & get_view() const
bool matches(const AbstractViewItem &other) const override
ItemT & add_item(Args &&...args)
int get_item_count() const
int get_item_count_filtered() const
const GridViewStyle & get_style() const
ViewType & get_view() const
AbstractViewItemDragController(AbstractView &view)
virtual bool set_state_active()
void always_reactivate_on_click()
ui::ButtonViewItem * view_item_button() const
ui::ButtonViewItem * view_item_but_
void select_on_click_set()
void activate_for_context_menu_set()
void set_context_menu_title(const std::string &title)
void build_grid_view(const bContext &C, AbstractGridView &grid_view, Layout &layout, std::optional< StringRef > search_string={})
PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id)
void build_grid_tile_button(Layout &layout, BIFIconID override_preview_icon_id=ICON_NONE) const
void storage_fetch(const AssetLibraryReference *library_reference, const bContext *C)
void iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn)
asset_system::AssetLibrary * library_get_once_available(const AssetLibraryReference &library_reference)
bool is_loaded(const AssetLibraryReference *library_reference)
static std::optional< asset_system::AssetCatalogFilter > catalog_filter_from_shelf_settings(const AssetShelfSettings &shelf_settings, const asset_system::AssetLibrary &library)
int tile_height(const AssetShelfSettings &settings)
int tile_width(const AssetShelfSettings &settings)
void build_asset_view(ui::Layout &layout, const AssetLibraryReference &library_ref, const AssetShelf &shelf, const bContext &C)
static std::string filter_string_get(const AssetShelf &shelf)
static std::optional< wmOperatorCallParams > create_asset_operator_params(const StringRefNull op_name, const asset_system::AssetRepresentation &asset)
bool type_asset_poll(const AssetShelfType &shelf_type, const asset_system::AssetRepresentation &asset)
void asset_tooltip(const asset_system::AssetRepresentation &asset, ui::TooltipData &tip, const bool include_name)
void operator_asset_reference_props_set(const asset_system::AssetRepresentation &asset, PointerRNA &ptr)
BIFIconID asset_preview_or_icon(const asset_system::AssetRepresentation &asset)
bool textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
PointerRNA * button_operator_ptr_ensure(Button *but)
void button_icon_scale_set(Button *but, float scale)
Button * uiDefBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
void button_pushbutton_draw_as_overlay_set(Button *but, bool value)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
wmDragAsset * WM_drag_create_asset_data(const asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
void WM_operator_properties_free(PointerRNA *ptr)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
char char * BLI_strncpy_ensure_pad(char *__restrict dst, const char *__restrict src, char pad, size_t dst_maxncpy) ATTR_NONNULL(1
@ ASSET_IMPORT_APPEND_REUSE
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
@ ASSET_SHELF_TYPE_FLAG_ACTIVATE_FOR_CONTEXT_MENU
@ ASSET_SHELF_TYPE_FLAG_NO_ASSET_DRAG
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool use_instance_collections
eAssetImportMethod method
const char * active_catalog_path
AssetShelfSettings_DisplayFlag display_flag
std::string drag_operator
std::string activate_operator
const AssetWeakReference *(*) get_active_asset(const AssetShelfType *shelf_type)
void(*) draw_context_menu(const bContext *C, const AssetShelfType *shelf_type, const asset_system::AssetRepresentation *asset, ui::Layout &layout)
struct AssetShelfType * type
AssetShelfSettings settings
ListBaseT< ARegion > regionbase
void alignment_set(LayoutAlign alignment)
void label(StringRef name, int icon)
void ui_units_x_set(float width)
void ui_units_y_set(float height)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)