Blender V5.0
NOD_socket_items_ui.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "DNA_node_types.h"
8
9#include "WM_api.hh"
10
11#include "UI_interface.hh"
13
14#include "RNA_access.hh"
15#include "RNA_prototypes.hh"
16
17#include "BLI_function_ref.hh"
18#include "BLI_string_utf8.h"
19
20#include "BKE_screen.hh"
21
22#include "NOD_socket_items.hh"
23
25
26template<typename Accessor>
27static void draw_item_in_list(uiList * /*ui_list*/,
28 const bContext *C,
29 uiLayout *layout,
30 PointerRNA * /*idataptr*/,
31 PointerRNA *itemptr,
32 int /*icon*/,
33 PointerRNA * /*active_dataptr*/,
34 const char * /*active_propname*/,
35 int /*index*/,
36 int /*flt_flag*/)
37{
38 uiLayout *row = &layout->row(true);
39 if constexpr (Accessor::has_type) {
41 RNA_float_get_array(itemptr, "color", color);
42 uiTemplateNodeSocket(row, const_cast<bContext *>(C), color);
43 }
45 row->prop(itemptr, "name", UI_ITEM_NONE, "", ICON_NONE);
46}
47
52template<typename Accessor>
54 uiLayout *layout,
55 const bNodeTree &tree,
56 const bNode &node)
57{
58 BLI_assert(Accessor::node_idname == node.idname);
60 const_cast<ID *>(&tree.id), &RNA_Node, const_cast<bNode *>(&node));
61
62 static const uiListType *items_list = []() {
63 uiListType *list = MEM_callocN<uiListType>(Accessor::ui_idnames::list.c_str());
64 STRNCPY_UTF8(list->idname, Accessor::ui_idnames::list.c_str());
67 return list;
68 }();
69
70 uiLayout *row = &layout->row(false);
72 C,
73 items_list->idname,
74 "",
75 &node_ptr,
76 Accessor::rna_names::items,
77 &node_ptr,
78 Accessor::rna_names::active_index.c_str(),
79 nullptr,
80 3,
81 5,
83 0,
85
86 uiLayout *ops_col = &row->column(false);
87 {
88 uiLayout *add_remove_col = &ops_col->column(true);
89 add_remove_col->op(Accessor::operator_idnames::add_item, "", ICON_ADD);
90 add_remove_col->op(Accessor::operator_idnames::remove_item, "", ICON_REMOVE);
91 }
92 {
93 uiLayout *up_down_col = &ops_col->column(true);
94 PointerRNA op_ptr = up_down_col->op(Accessor::operator_idnames::move_item, "", ICON_TRIA_UP);
95 RNA_enum_set(&op_ptr, "direction", 0);
96 op_ptr = up_down_col->op(Accessor::operator_idnames::move_item, "", ICON_TRIA_DOWN);
97 RNA_enum_set(&op_ptr, "direction", 1);
98 }
99}
100
102template<typename Accessor>
104 const bNode &node,
105 const FunctionRef<void(PointerRNA *item_ptr)> draw_item)
106{
107 using ItemT = typename Accessor::ItemT;
108 BLI_assert(Accessor::node_idname == node.idname);
109
110 SocketItemsRef<ItemT> ref = Accessor::get_items_from_node(const_cast<bNode &>(node));
111 if (*ref.active_index < 0) {
112 return;
113 }
114 if (*ref.active_index >= *ref.items_num) {
115 return;
116 }
117
118 ItemT &item = (*ref.items)[*ref.active_index];
120 const_cast<ID *>(&tree.id), Accessor::item_srna, &item);
121 draw_item(&item_ptr);
122}
123
124} // namespace blender::nodes::socket_items::ui
#define BLI_assert(a)
Definition BLI_assert.h:46
#define STRNCPY_UTF8(dst, src)
@ UILST_LAYOUT_DEFAULT
#define C
Definition RandGen.cpp:29
void uiTemplateNodeSocket(uiLayout *layout, bContext *C, const float color[4])
void uiTemplateList(uiLayout *layout, const bContext *C, const char *listtype_name, const char *list_id, PointerRNA *dataptr, blender::StringRefNull propname, PointerRNA *active_dataptr, const char *active_propname, const char *item_dyntip_propname, int rows, int maxrows, int layout_type, int columns, enum uiTemplateListFlags flags)
@ UI_TEMPLATE_LIST_FLAG_NONE
#define UI_ITEM_NONE
KDTree_3d * tree
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
static void draw_items_list_with_operators(const bContext *C, uiLayout *layout, const bNodeTree &tree, const bNode &node)
static void draw_active_item_props(const bNodeTree &tree, const bNode &node, const FunctionRef< void(PointerRNA *item_ptr)> draw_item)
static void draw_item_in_list(uiList *, const bContext *C, uiLayout *layout, PointerRNA *, PointerRNA *itemptr, int, PointerRNA *, const char *, int, int)
VecBase< float, 4 > float4
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
Definition DNA_ID.h:414
char idname[64]
uiLayout & column(bool align)
uiLayout & row(bool align)
void emboss_set(blender::ui::EmbossType emboss)
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, blender::wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
char idname[BKE_ST_MAXNAME]
uiListDrawItemFunc draw_item
bool WM_uilisttype_add(uiListType *ult)