27 if (
node !=
nullptr) {
29 b.add_input(data_type,
"Value"_ustr);
31 auto &decimals =
b.add_input<
decl::Int>(
"Decimals"_ustr).
min(0);
38 .description(
"Numeric base for the output string (e.g. 2 for binary, 16 for hexadecimal)")
44 .description(
"Minimum number of characters in the output, zero-padded if shorter")
53 static auto float_to_str_fn = mf::build::SI2_SO<float, int, std::string>(
54 "Value To String", [](
float a,
int b) {
55 std::stringstream stream;
56 stream << std::fixed << std::setprecision(std::max(0,
b)) << a;
60 static auto int_to_str_fn = mf::build::SI3_SO<int, int, int, std::string>(
61 "Value To String", [](
int value,
int base,
int padding) -> std::string {
62 if (base < 2 || base > 36) {
68 auto [ptr, ec] = std::to_chars(buf, buf +
sizeof(buf), value, base);
69 std::string
result(buf, ptr);
72 const size_t insert_pos = (!
result.empty() &&
result[0] ==
'-') ? 1 : 0;
73 result.insert(insert_pos, needed,
'0');
80 return &float_to_str_fn;
82 return &int_to_str_fn;
143 {
SOCK_FLOAT,
"FLOAT", ICON_NODE_SOCKET_FLOAT,
"Float",
"Floating-point value"},
144 {
SOCK_INT,
"INT", ICON_NODE_SOCKET_INT,
"Integer",
"32-bit integer"},
145 {0,
nullptr, 0,
nullptr,
nullptr},
162 ntype.
ui_name =
"Value to String";
163 ntype.
ui_description =
"Generate a string representation of the given input value";
#define NODE_CLASS_CONVERTER
#define FN_NODE_VALUE_TO_STRING
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define BLI_assert_unreachable()
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_rna(StructRNA *srna)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static const mf::MultiFunction * get_multi_function(const bNode &bnode)
static void node_init(bNodeTree *, bNode *node)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
uint padding(uint offset, uint alignment)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)