UI: Include asset description in asset shelf tooltip
Tooltips for assets in the asset shelf now don't only display the name, but also the description saved in the asset's metadata. This is what we usually do when assets are displayed, for example in the asset browser or in add menus. Here it was just a small bit of polish that was never done.
This commit is contained in:
@@ -39,6 +39,7 @@ set(SRC
|
||||
intern/asset_shelf_settings.cc
|
||||
intern/asset_temp_id_consumer.cc
|
||||
intern/asset_type.cc
|
||||
intern/asset_ui_utils.cc
|
||||
|
||||
ED_asset_catalog.hh
|
||||
ED_asset_filter.hh
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
struct Main;
|
||||
|
||||
namespace blender::ed::asset {
|
||||
|
||||
void catalogs_save_from_main_path(asset_system::AssetLibrary *library, const Main *bmain);
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
#include "DNA_asset_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
#include "ED_asset_handle.hh"
|
||||
#include "ED_asset_list.hh"
|
||||
#include "ED_asset.hh"
|
||||
#include "ED_asset_menu_utils.hh"
|
||||
#include "ED_asset_shelf.hh"
|
||||
|
||||
@@ -221,6 +220,7 @@ void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
||||
{
|
||||
const AssetView &asset_view = reinterpret_cast<const AssetView &>(this->get_view());
|
||||
const AssetShelfType &shelf_type = *asset_view.shelf_.type;
|
||||
const asset_system::AssetRepresentation *asset = handle_get_representation(&asset_);
|
||||
|
||||
PointerRNA file_ptr = RNA_pointer_create(
|
||||
nullptr,
|
||||
@@ -234,7 +234,7 @@ void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
||||
|
||||
uiBut *item_but = reinterpret_cast<uiBut *>(this->view_item_button());
|
||||
if (std::optional<wmOperatorCallParams> activate_op = create_activate_operator_params(
|
||||
shelf_type.activate_operator, *handle_get_representation(&asset_)))
|
||||
shelf_type.activate_operator, *asset))
|
||||
{
|
||||
/* Attach the operator, but don't call it through the button. We call it using
|
||||
* #on_activate(). */
|
||||
@@ -249,6 +249,16 @@ void AssetViewItem::build_grid_tile(uiLayout &layout) const
|
||||
UI_but_view_item_draw_size_set(
|
||||
item_but, style.tile_width + 2 * U.pixelsize, style.tile_height + 2 * U.pixelsize);
|
||||
|
||||
UI_but_func_tooltip_set(
|
||||
item_but,
|
||||
[](bContext * /*C*/, void *argN, const char * /*tip*/) {
|
||||
const asset_system::AssetRepresentation *asset =
|
||||
static_cast<const asset_system::AssetRepresentation *>(argN);
|
||||
return asset_tooltip(*asset, /*include_name=*/false);
|
||||
},
|
||||
const_cast<asset_system::AssetRepresentation *>(asset),
|
||||
nullptr);
|
||||
|
||||
ui::PreviewGridItem::build_grid_tile_button(layout);
|
||||
}
|
||||
|
||||
|
||||
33
source/blender/editors/asset/intern/asset_ui_utils.cc
Normal file
33
source/blender/editors/asset/intern/asset_ui_utils.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup edasset
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "AS_asset_representation.hh"
|
||||
|
||||
#include "ED_asset.hh"
|
||||
|
||||
namespace blender::ed::asset {
|
||||
|
||||
std::string asset_tooltip(const asset_system::AssetRepresentation &asset, const bool include_name)
|
||||
{
|
||||
std::string complete_string;
|
||||
|
||||
if (include_name) {
|
||||
complete_string += asset.get_name();
|
||||
}
|
||||
|
||||
const AssetMetaData &meta_data = asset.get_metadata();
|
||||
if (meta_data.description) {
|
||||
complete_string += '\n';
|
||||
complete_string += meta_data.description;
|
||||
}
|
||||
return complete_string;
|
||||
}
|
||||
|
||||
} // namespace blender::ed::asset
|
||||
@@ -29,6 +29,9 @@
|
||||
|
||||
namespace blender::ed::asset {
|
||||
|
||||
std::string asset_tooltip(const asset_system::AssetRepresentation &asset,
|
||||
bool include_name = true);
|
||||
|
||||
void operatortypes_asset();
|
||||
|
||||
}
|
||||
} // namespace blender::ed::asset
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_prototypes.hh"
|
||||
|
||||
#include "ED_asset.hh"
|
||||
#include "ED_fileselect.hh"
|
||||
#include "ED_screen.hh"
|
||||
|
||||
@@ -334,13 +335,7 @@ static void file_draw_tooltip_custom_func(bContext & /*C*/, uiTooltipData &tip,
|
||||
static std::string file_draw_asset_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/)
|
||||
{
|
||||
const auto *asset = static_cast<blender::asset_system::AssetRepresentation *>(argN);
|
||||
std::string complete_string = asset->get_name();
|
||||
const AssetMetaData &meta_data = asset->get_metadata();
|
||||
if (meta_data.description) {
|
||||
complete_string += '\n';
|
||||
complete_string += meta_data.description;
|
||||
}
|
||||
return complete_string;
|
||||
return blender::ed::asset::asset_tooltip(*asset);
|
||||
}
|
||||
|
||||
static void draw_tile_background(const rcti *draw_rect, int colorid, int shade)
|
||||
|
||||
Reference in New Issue
Block a user