Blender V4.5
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"
12
13#include "RNA_access.hh"
14#include "RNA_prototypes.hh"
15
16#include "BLI_function_ref.hh"
17
18#include "BKE_screen.hh"
19
20#include "NOD_socket_items.hh"
21
23
24template<typename Accessor>
25static void draw_item_in_list(uiList * /*ui_list*/,
26 const bContext *C,
27 uiLayout *layout,
28 PointerRNA * /*idataptr*/,
29 PointerRNA *itemptr,
30 int /*icon*/,
31 PointerRNA * /*active_dataptr*/,
32 const char * /*active_propname*/,
33 int /*index*/,
34 int /*flt_flag*/)
35{
36 uiLayout *row = &layout->row(true);
37 if constexpr (Accessor::has_type) {
39 RNA_float_get_array(itemptr, "color", color);
40 uiTemplateNodeSocket(row, const_cast<bContext *>(C), color);
41 }
43 row->prop(itemptr, "name", UI_ITEM_NONE, "", ICON_NONE);
44}
45
50template<typename Accessor>
52 uiLayout *layout,
53 const bNodeTree &tree,
54 const bNode &node)
55{
56 BLI_assert(Accessor::node_idname == node.idname);
58 const_cast<ID *>(&tree.id), &RNA_Node, const_cast<bNode *>(&node));
59
60 static const uiListType *items_list = []() {
61 uiListType *list = MEM_callocN<uiListType>(Accessor::ui_idnames::list.c_str());
62 STRNCPY(list->idname, Accessor::ui_idnames::list.c_str());
65 return list;
66 }();
67
68 uiLayout *row = &layout->row(false);
70 C,
71 items_list->idname,
72 "",
73 &node_ptr,
74 Accessor::rna_names::items,
75 &node_ptr,
76 Accessor::rna_names::active_index.c_str(),
77 nullptr,
78 3,
79 5,
81 0,
83
84 uiLayout *ops_col = &row->column(false);
85 {
86 uiLayout *add_remove_col = &ops_col->column(true);
87 add_remove_col->op(Accessor::operator_idnames::add_item, "", ICON_ADD);
88 add_remove_col->op(Accessor::operator_idnames::remove_item, "", ICON_REMOVE);
89 }
90 {
91 uiLayout *up_down_col = &ops_col->column(true);
93 up_down_col, Accessor::operator_idnames::move_item, "", ICON_TRIA_UP, "direction", 0);
95 up_down_col, Accessor::operator_idnames::move_item, "", ICON_TRIA_DOWN, "direction", 1);
96 }
97}
98
100template<typename Accessor>
102 const bNode &node,
103 const FunctionRef<void(PointerRNA *item_ptr)> draw_item)
104{
105 using ItemT = typename Accessor::ItemT;
106 BLI_assert(Accessor::node_idname == node.idname);
107
108 SocketItemsRef<ItemT> ref = Accessor::get_items_from_node(const_cast<bNode &>(node));
109 if (*ref.active_index < 0) {
110 return;
111 }
112 if (*ref.active_index >= *ref.items_num) {
113 return;
114 }
115
116 ItemT &item = (*ref.items)[*ref.active_index];
118 const_cast<ID *>(&tree.id), Accessor::item_srna, &item);
119 draw_item(&item_ptr);
120}
121
122} // namespace blender::nodes::socket_items::ui
#define BLI_assert(a)
Definition BLI_assert.h:46
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
@ 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
void uiItemEnumO(uiLayout *layout, blender::StringRefNull opname, std::optional< blender::StringRef > name, int icon, blender::StringRefNull propname, int value)
#define UI_ITEM_NONE
void uiLayoutSetEmboss(uiLayout *layout, blender::ui::EmbossType emboss)
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)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
Definition DNA_ID.h:404
char idname[64]
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, wmOperatorCallContext context, eUI_Item_Flag flag)
uiLayout & column(bool align)
uiLayout & row(bool align)
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)