Blender V4.3
interface_template_asset_shelf_popover.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BKE_context.hh"
10#include "BKE_report.hh"
11#include "BKE_screen.hh"
12
13#include "RNA_access.hh"
14#include "RNA_define.hh"
15#include "RNA_prototypes.hh"
16
17#include "UI_interface.hh"
18#include "UI_interface_c.hh"
19#include "UI_resources.hh"
20#include "interface_intern.hh"
21
22#include "ED_asset_shelf.hh"
23
24#include "WM_api.hh"
25
26namespace blender::ui {
27
29 const bContext &C,
30 const StringRefNull asset_shelf_id,
31 const StringRefNull name,
32 const BIFIconID icon)
33{
34 AssetShelfType *shelf_type = ed::asset::shelf::type_find_from_idname(asset_shelf_id);
35 if (!shelf_type) {
36 RNA_warning("Asset shelf type not found: %s", asset_shelf_id.c_str());
37 return;
38 }
39
40 const ARegion *region = CTX_wm_region(&C);
41 uiBlock *block = uiLayoutGetBlock(&layout);
42
43 uiLayout *row = uiLayoutRow(&layout, true);
44 const bool use_big_size = !RGN_TYPE_IS_HEADER_ANY(region->regiontype);
45 const bool use_preview_icon = use_big_size;
46
47 uiLayoutSetContextString(row, "asset_shelf_idname", asset_shelf_id);
48 if (use_big_size) {
49 uiLayoutSetScaleX(row, 6);
50 uiLayoutSetScaleY(row, 6);
51 }
52 else {
53 uiLayoutSetUnitsX(row, name.is_empty() ? 1.6f : 7);
54 }
55
56 uiItemPopoverPanel(row, &C, "ASSETSHELF_PT_popover_panel", name.c_str(), icon);
57 uiBut *but = static_cast<uiBut *>(block->buttons.last);
58 if (use_preview_icon) {
60 }
61}
62
63bool asset_shelf_popover_invoke(bContext &C, StringRef asset_shelf_idname, ReportList &reports)
64{
65 AssetShelfType *shelf_type = ed::asset::shelf::type_find_from_idname(asset_shelf_idname);
66 if (ed::asset::shelf::type_poll_for_popup(C, shelf_type) == false) {
67 return false;
68 }
69
70 PanelType *pt = WM_paneltype_find("ASSETSHELF_PT_popover_panel", true);
71 if (pt == nullptr) {
72 BKE_reportf(&reports, RPT_ERROR, "Asset shelf popover panel type not found");
73 return false;
74 }
75
76 /* Skip panel poll check here. Should usually be done, but requires passing the asset shelf type
77 * name via some context-store, but there's nothing to provide that here. Asset shelf type is
78 * polled above, so it's okay. */
79
80 std::string asset_shelf_id_str = asset_shelf_idname;
82 &C,
83 nullptr,
84 nullptr,
85 [asset_shelf_id_str](bContext *C, uiLayout *layout, void *arg_pt) {
86 uiLayoutSetContextString(layout, "asset_shelf_idname", asset_shelf_id_str);
87 ui_item_paneltype_func(C, layout, arg_pt);
88 },
89 pt);
90
91 return true;
92}
93
94} // namespace blender::ui
95
96using namespace blender;
97
98std::optional<StringRefNull> UI_asset_shelf_idname_from_button_context(const uiBut *but)
99{
100 return UI_but_context_string_get(but, "asset_shelf_idname");
101}
ARegion * CTX_wm_region(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define RGN_TYPE_IS_HEADER_ANY(regiontype)
#define RNA_warning(format,...)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetScaleX(uiLayout *layout, float scale)
std::optional< blender::StringRefNull > UI_but_context_string_get(const uiBut *but, const char *name)
void uiLayoutSetUnitsX(uiLayout *layout, float unit)
void uiLayoutSetContextString(uiLayout *layout, const char *name, blender::StringRef value)
void uiItemPopoverPanel(uiLayout *layout, const bContext *C, const char *panel_type, const char *name, int icon)
@ UI_BUT_ICON_PREVIEW
int BIFIconID
constexpr const char * c_str() const
void ui_def_but_icon(uiBut *but, const int icon, const int flag)
void ui_item_paneltype_func(bContext *C, uiLayout *layout, void *arg_pt)
@ UI_HAS_ICON
uiPopupBlockHandle * ui_popover_panel_create(bContext *C, ARegion *butregion, uiBut *but, uiPopoverCreateFunc popover_func, const PanelType *panel_type)
std::optional< StringRefNull > UI_asset_shelf_idname_from_button_context(const uiBut *but)
AssetShelfType * type_find_from_idname(const StringRef idname)
bool type_poll_for_popup(const bContext &C, const AssetShelfType *shelf_type)
bool asset_shelf_popover_invoke(bContext &C, blender::StringRef asset_shelf_idname, ReportList &reports)
void template_asset_shelf_popover(uiLayout &layout, const bContext &C, StringRefNull asset_shelf_id, StringRefNull name, int icon)
void * last
ListBase buttons
PanelType * WM_paneltype_find(const char *idname, bool quiet)