Blender  V3.3
interface_context_path.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_vector.hh"
9 
10 #include "BKE_screen.h"
11 
12 #include "RNA_access.h"
13 
14 #include "ED_screen.h"
15 
16 #include "UI_interface.h"
17 #include "UI_interface.hh"
18 #include "UI_resources.h"
19 
20 #include "WM_api.h"
21 
22 namespace blender::ui {
23 
25  StructRNA &rna_type,
26  void *ptr,
27  const BIFIconID icon_override)
28 {
29  /* Add the null check here to make calling functions less verbose. */
30  if (!ptr) {
31  return;
32  }
33 
34  PointerRNA rna_ptr;
35  RNA_pointer_create(nullptr, &rna_type, ptr, &rna_ptr);
36  char name[128];
37  RNA_struct_name_get_alloc(&rna_ptr, name, sizeof(name), nullptr);
38 
39  /* Use a blank icon by default to check whether to retrieve it automatically from the type. */
40  const BIFIconID icon = icon_override == ICON_NONE ?
41  static_cast<BIFIconID>(RNA_struct_ui_icon(rna_ptr.type)) :
42  icon_override;
43 
44  path.append({name, static_cast<int>(icon)});
45 }
46 
47 /* -------------------------------------------------------------------- */
52 {
53  uiLayout *row = uiLayoutRow(&layout, true);
55 
56  for (const int i : context_path.index_range()) {
57  uiLayout *sub_row = uiLayoutRow(row, true);
59 
60  if (i > 0) {
61  uiItemL(sub_row, "", ICON_RIGHTARROW_THIN);
62  }
63  uiItemL(sub_row, context_path[i].name.c_str(), context_path[i].icon);
64  }
65 }
66 
69 } // namespace blender::ui
@ UI_LAYOUT_ALIGN_LEFT
void uiItemL(uiLayout *layout, const char *name, int icon)
void uiLayoutSetAlignment(uiLayout *layout, char alignment)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
BIFIconID
Definition: UI_resources.h:18
constexpr IndexRange index_range() const
Definition: BLI_span.hh:401
void append(const T &value)
Definition: BLI_vector.hh:433
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)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:907
int RNA_struct_ui_icon(const StructRNA *type)
Definition: rna_access.c:601
struct StructRNA * type
Definition: RNA_types.h:37
PointerRNA * ptr
Definition: wm_files.c:3480