Nodes: add group node default width
This adds the ability to customize the default width of a group node that's created for a node group. This feature works towards the goal of unifying the features available to built-in nodes and node groups. We often customize the width of built-in nodes from them to looks slightly better (e.g. to avoid cut-off labels). Pull Request: https://projects.blender.org/blender/blender/pulls/126054
This commit is contained in:
@@ -52,6 +52,9 @@ def draw_node_group_add_menu(context, layout):
|
||||
ops = props.settings.add()
|
||||
ops.name = "node_tree"
|
||||
ops.value = "bpy.data.node_groups[{!r}]".format(group.name)
|
||||
ops = props.settings.add()
|
||||
ops.name = "width"
|
||||
ops.value = repr(group.default_group_node_width)
|
||||
|
||||
|
||||
def draw_assets_for_catalog(layout, catalog_path):
|
||||
|
||||
@@ -1020,6 +1020,7 @@ class NODE_PT_node_tree_properties(Panel):
|
||||
layout.prop(group, "description", text="Description")
|
||||
|
||||
layout.prop(group, "color_tag")
|
||||
layout.prop(group, "default_group_node_width", text="Node Width")
|
||||
|
||||
if group.bl_idname == "GeometryNodeTree":
|
||||
header, body = layout.panel("group_usage")
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 16
|
||||
#define BLENDER_FILE_SUBVERSION 17
|
||||
|
||||
/* Minimum Blender version that supports reading file written with the current
|
||||
* version. Older Blender versions will test this and cancel loading the file, showing a warning to
|
||||
|
||||
@@ -1794,3 +1794,8 @@ const bNodeZoneType *zone_type_by_node_type(const int node_type);
|
||||
{ \
|
||||
return *static_cast<const StorageT *>(node.storage); \
|
||||
}
|
||||
|
||||
constexpr int NODE_DEFAULT_MAX_WIDTH = 700;
|
||||
constexpr int GROUP_NODE_DEFAULT_WIDTH = 140;
|
||||
constexpr int GROUP_NODE_MAX_WIDTH = NODE_DEFAULT_MAX_WIDTH;
|
||||
constexpr int GROUP_NODE_MIN_WIDTH = 40;
|
||||
|
||||
@@ -103,8 +103,6 @@
|
||||
|
||||
#include "BLO_read_write.hh"
|
||||
|
||||
#define NODE_DEFAULT_MAX_WIDTH 700
|
||||
|
||||
using blender::Array;
|
||||
using blender::Map;
|
||||
using blender::MutableSpan;
|
||||
@@ -149,6 +147,7 @@ static void ntree_init_data(ID *id)
|
||||
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(id);
|
||||
ntree->tree_interface.init_data();
|
||||
ntree->runtime = MEM_new<bNodeTreeRuntime>(__func__);
|
||||
ntree->default_group_node_width = GROUP_NODE_DEFAULT_WIDTH;
|
||||
ntree_set_typeinfo(ntree, nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -4551,6 +4551,15 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
}
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 403, 17)) {
|
||||
FOREACH_NODETREE_BEGIN (bmain, tree, id) {
|
||||
if (tree->default_group_node_width == 0) {
|
||||
tree->default_group_node_width = GROUP_NODE_DEFAULT_WIDTH;
|
||||
}
|
||||
}
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bump subversion in BKE_blender_version.h when adding versioning
|
||||
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.
|
||||
|
||||
@@ -322,6 +322,7 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
|
||||
*/
|
||||
group_node->flag &= ~NODE_OPTIONS;
|
||||
}
|
||||
group_node->width = node_group->default_group_node_width;
|
||||
|
||||
group_node->id = &node_group->id;
|
||||
id_us_plus(group_node->id);
|
||||
@@ -424,6 +425,7 @@ static bool add_node_group_asset(const bContext &C,
|
||||
}
|
||||
/* By default, don't show the data-block selector since it's not usually necessary for assets. */
|
||||
group_node->flag &= ~NODE_OPTIONS;
|
||||
group_node->width = node_group->default_group_node_width;
|
||||
|
||||
group_node->id = &node_group->id;
|
||||
id_us_plus(group_node->id);
|
||||
|
||||
@@ -700,7 +700,12 @@ typedef struct bNodeTree {
|
||||
|
||||
/** #blender::bke::NodeGroupColorTag. */
|
||||
int color_tag;
|
||||
char _pad[4];
|
||||
|
||||
/**
|
||||
* Default width of a group node created for this group. May be zero, in which case this value
|
||||
* should be ignored.
|
||||
*/
|
||||
int default_group_node_width;
|
||||
|
||||
rctf viewer_border;
|
||||
|
||||
|
||||
@@ -10740,6 +10740,13 @@ static void rna_def_nodetree(BlenderRNA *brna)
|
||||
prop, "Color Tag", "Color tag of the node group which influences the header color");
|
||||
RNA_def_property_update(prop, NC_NODE, nullptr);
|
||||
|
||||
prop = RNA_def_property(srna, "default_group_node_width", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_default(prop, GROUP_NODE_DEFAULT_WIDTH);
|
||||
RNA_def_property_range(prop, GROUP_NODE_MIN_WIDTH, GROUP_NODE_MAX_WIDTH);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Default Group Node Width", "The width for newly created group nodes");
|
||||
RNA_def_property_update(prop, NC_NODE, nullptr);
|
||||
|
||||
prop = RNA_def_property(srna, "view_center", PROP_FLOAT, PROP_XYZ);
|
||||
RNA_def_property_array(prop, 2);
|
||||
RNA_def_property_float_sdna(prop, nullptr, "view_center");
|
||||
|
||||
@@ -30,7 +30,8 @@ static void register_node_type_geo_group()
|
||||
BLI_assert(ntype.rna_ext.srna != nullptr);
|
||||
RNA_struct_blender_type_set(ntype.rna_ext.srna, &ntype);
|
||||
|
||||
bke::node_type_size(&ntype, 140, 60, 400);
|
||||
bke::node_type_size(
|
||||
&ntype, GROUP_NODE_DEFAULT_WIDTH, GROUP_NODE_MIN_WIDTH, GROUP_NODE_MAX_WIDTH);
|
||||
ntype.labelfunc = node_group_label;
|
||||
ntype.declare = node_group_declare;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user