Blender V5.0
interface_context_path.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLF_api.hh"
10#include "BLI_vector.hh"
11
12#include "RNA_access.hh"
13
14#include "UI_interface.hh"
16#include "UI_resources.hh"
17
18#include "RNA_prototypes.hh"
19
20namespace blender::ui {
21
23 StructRNA &rna_type,
24 void *ptr,
25 const BIFIconID icon_override,
26 std::function<void(bContext &)> handle_func)
27{
28 /* Add the null check here to make calling functions less verbose. */
29 if (!ptr) {
30 return;
31 }
32
33 PointerRNA rna_ptr = RNA_pointer_create_discrete(nullptr, &rna_type, ptr);
34 char name_buf[128], *name;
35 name = RNA_struct_name_get_alloc(&rna_ptr, name_buf, sizeof(name_buf), nullptr);
36
37 /* Use a blank icon by default to check whether to retrieve it automatically from the type. */
38 const BIFIconID icon = icon_override == ICON_NONE ? RNA_struct_ui_icon(rna_ptr.type) :
39 icon_override;
40
41 if (&rna_type == &RNA_NodeTree) {
42 ID *id = (ID *)ptr;
43 path.append({name, icon, ID_REAL_USERS(id), handle_func});
44 }
45 else {
46 path.append({name, icon, 1, handle_func});
47 }
48 if (name != name_buf) {
50 }
51}
52
53/* -------------------------------------------------------------------- */
56
58{
59 uiLayout *row = &layout.row(true);
61
62 for (const int i : context_path.index_range()) {
63 uiLayout *sub_row = &row->row(true);
65
66 if (i > 0) {
67 sub_row->label("", ICON_RIGHTARROW_THIN);
68 }
69 uiBut *but;
70 int icon = context_path[i].icon;
71 std::string name = context_path[i].name;
72 if (context_path[i].handle_func) {
73 but = sub_row->button(name.c_str(), icon, context_path[i].handle_func);
74 }
75 else {
76 but = uiItemL_ex(sub_row, name.c_str(), icon, false, false);
77 }
78 UI_but_icon_indicator_number_set(but, context_path[i].icon_indicator_number);
79 }
80}
81
83
84} // namespace blender::ui
#define ID_REAL_USERS(id)
Definition DNA_ID.h:676
int BIFIconID
Definition ED_asset.hh:28
void UI_but_icon_indicator_number_set(uiBut *but, const int indicator_number)
uiBut * uiItemL_ex(uiLayout *layout, blender::StringRef name, int icon, bool highlight, bool redalert)
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
void append(const T &value)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void template_breadcrumbs(uiLayout &layout, Span< ContextPathItem > context_path)
void context_path_add_generic(Vector< ContextPathItem > &path, StructRNA &rna_type, void *ptr, const BIFIconID icon_override=ICON_NONE, std::function< void(bContext &)> handle_func=nullptr)
const char * name
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
int RNA_struct_ui_icon(const StructRNA *type)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
Definition DNA_ID.h:414
StructRNA * type
Definition RNA_types.hh:52
void alignment_set(blender::ui::LayoutAlign alignment)
void label(blender::StringRef name, int icon)
uiBut * button(blender::StringRef name, int icon, std::function< void(bContext &)> func, std::optional< blender::StringRef > tooltip=std::nullopt)
uiLayout & row(bool align)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238