Blender V4.3
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
9#include "BLI_vector.hh"
10
11#include "RNA_access.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "RNA_prototypes.hh"
17
18namespace blender::ui {
19
21 StructRNA &rna_type,
22 void *ptr,
23 const BIFIconID icon_override)
24{
25 /* Add the null check here to make calling functions less verbose. */
26 if (!ptr) {
27 return;
28 }
29
30 PointerRNA rna_ptr = RNA_pointer_create(nullptr, &rna_type, ptr);
31 char name_buf[128], *name;
32 name = RNA_struct_name_get_alloc(&rna_ptr, name_buf, sizeof(name_buf), nullptr);
33
34 /* Use a blank icon by default to check whether to retrieve it automatically from the type. */
35 const BIFIconID icon = icon_override == ICON_NONE ? RNA_struct_ui_icon(rna_ptr.type) :
36 icon_override;
37
38 if (&rna_type == &RNA_NodeTree) {
39 ID *id = (ID *)ptr;
40 path.append({name, icon, ID_REAL_USERS(id)});
41 }
42 else {
43 path.append({name, icon, 1});
44 }
45 if (name != name_buf) {
46 MEM_freeN(name);
47 }
48}
49
50/* -------------------------------------------------------------------- */
55{
56 uiLayout *row = uiLayoutRow(&layout, true);
58
59 for (const int i : context_path.index_range()) {
60 uiLayout *sub_row = uiLayoutRow(row, true);
62
63 if (i > 0) {
64 uiItemL(sub_row, "", ICON_RIGHTARROW_THIN);
65 }
66 uiBut *but = uiItemL_ex(
67 sub_row, context_path[i].name.c_str(), context_path[i].icon, false, false);
68 UI_but_icon_indicator_number_set(but, context_path[i].icon_indicator_number);
69 }
70}
71
74} // namespace blender::ui
#define ID_REAL_USERS(id)
Definition DNA_ID.h:637
@ UI_LAYOUT_ALIGN_LEFT
void UI_but_icon_indicator_number_set(uiBut *but, const int indicator_number)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetAlignment(uiLayout *layout, char alignment)
uiBut * uiItemL_ex(uiLayout *layout, const char *name, int icon, bool highlight, bool redalert)
int BIFIconID
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
void append(const T &value)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
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)
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(ID *id, StructRNA *type, void *data)
Definition DNA_ID.h:413
StructRNA * type
Definition RNA_types.hh:41
PointerRNA * ptr
Definition wm_files.cc:4126