2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2021 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-10-26 11:05:01 -05:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup edinterface
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2021-10-26 11:05:01 -05:00
|
|
|
|
|
|
|
|
#include "UI_interface.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
2021-10-26 11:05:01 -05:00
|
|
|
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2022-10-20 16:37:07 +02:00
|
|
|
|
2021-10-26 11:05:01 -05:00
|
|
|
namespace blender::ui {
|
|
|
|
|
|
|
|
|
|
void context_path_add_generic(Vector<ContextPathItem> &path,
|
|
|
|
|
StructRNA &rna_type,
|
|
|
|
|
void *ptr,
|
|
|
|
|
const BIFIconID icon_override)
|
|
|
|
|
{
|
|
|
|
|
/* Add the null check here to make calling functions less verbose. */
|
|
|
|
|
if (!ptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA rna_ptr = RNA_pointer_create_discrete(nullptr, &rna_type, ptr);
|
2024-04-17 11:36:32 +10:00
|
|
|
char name_buf[128], *name;
|
|
|
|
|
name = RNA_struct_name_get_alloc(&rna_ptr, name_buf, sizeof(name_buf), nullptr);
|
2021-10-26 11:05:01 -05:00
|
|
|
|
|
|
|
|
/* Use a blank icon by default to check whether to retrieve it automatically from the type. */
|
2023-08-14 12:06:35 +02:00
|
|
|
const BIFIconID icon = icon_override == ICON_NONE ? RNA_struct_ui_icon(rna_ptr.type) :
|
|
|
|
|
icon_override;
|
2021-10-26 11:05:01 -05:00
|
|
|
|
2022-10-20 16:37:07 +02:00
|
|
|
if (&rna_type == &RNA_NodeTree) {
|
|
|
|
|
ID *id = (ID *)ptr;
|
2023-08-14 12:06:35 +02:00
|
|
|
path.append({name, icon, ID_REAL_USERS(id)});
|
2022-10-20 16:37:07 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2023-08-14 12:06:35 +02:00
|
|
|
path.append({name, icon, 1});
|
2022-10-20 16:37:07 +02:00
|
|
|
}
|
2024-04-17 11:36:32 +10:00
|
|
|
if (name != name_buf) {
|
|
|
|
|
MEM_freeN(name);
|
|
|
|
|
}
|
2021-10-26 11:05:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Breadcrumb Template
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
void template_breadcrumbs(uiLayout &layout, Span<ContextPathItem> context_path)
|
|
|
|
|
{
|
2025-04-25 19:45:25 +02:00
|
|
|
uiLayout *row = &layout.row(true);
|
2021-10-26 11:05:01 -05:00
|
|
|
uiLayoutSetAlignment(&layout, UI_LAYOUT_ALIGN_LEFT);
|
|
|
|
|
|
|
|
|
|
for (const int i : context_path.index_range()) {
|
2025-04-25 19:45:25 +02:00
|
|
|
uiLayout *sub_row = &row->row(true);
|
2021-10-26 11:05:01 -05:00
|
|
|
uiLayoutSetAlignment(sub_row, UI_LAYOUT_ALIGN_LEFT);
|
|
|
|
|
|
|
|
|
|
if (i > 0) {
|
2025-05-08 17:21:08 +02:00
|
|
|
sub_row->label("", ICON_RIGHTARROW_THIN);
|
2021-10-26 11:05:01 -05:00
|
|
|
}
|
2022-10-20 16:37:07 +02:00
|
|
|
uiBut *but = uiItemL_ex(
|
|
|
|
|
sub_row, context_path[i].name.c_str(), context_path[i].icon, false, false);
|
|
|
|
|
UI_but_icon_indicator_number_set(but, context_path[i].icon_indicator_number);
|
2021-10-26 11:05:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 00:56:17 +11:00
|
|
|
/** \} */
|
2021-12-14 15:49:31 +11:00
|
|
|
|
|
|
|
|
} // namespace blender::ui
|