Nodes: support optional labels for group inputs
Built-in nodes already used the functionality to hide the input labels in a few situations. However, this functionality was not exposed for node groups before. It required some refactoring to get the semantics of the flag right. The tricky aspect is that "Hide Label" would be an incorrect name, because the label is still shown under various circumstances. Instead, the flag merely indicates that drawing code may skip drawing the label. This adds a new "Optional Label" input for node group inputs. Other names are possible like "Requires Label" which would be the inverse. Overall the implementation is pretty straight forward after1f489ea31a,469a70dba9andf79896f5b9. Pull Request: https://projects.blender.org/blender/blender/pulls/146939
This commit is contained in:
@@ -1156,6 +1156,7 @@ bNodeTreeInterfaceSocket *add_interface_socket_from_node(bNodeTree &ntree,
|
||||
if (!decl->description.empty()) {
|
||||
description = decl->description;
|
||||
}
|
||||
SET_FLAG_FROM_TEST(flag, decl->optional_label, NODE_INTERFACE_SOCKET_OPTIONAL_LABEL);
|
||||
}
|
||||
|
||||
iosock = ntree.tree_interface.add_socket(name, description, socket_type, flag, nullptr);
|
||||
|
||||
@@ -1420,6 +1420,9 @@ static void std_node_socket_interface_draw(ID *id,
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_socket->flag & NODE_INTERFACE_SOCKET_INPUT) {
|
||||
col->prop(&ptr, "optional_label", DEFAULT_FLAGS, std::nullopt, ICON_NONE);
|
||||
}
|
||||
{
|
||||
uiLayout *sub = &col->column(false);
|
||||
sub->active_set(interface_socket->default_input == NODE_DEFAULT_INPUT_VALUE);
|
||||
|
||||
@@ -70,8 +70,13 @@ typedef enum NodeTreeInterfaceSocketFlag {
|
||||
NODE_INTERFACE_SOCKET_PANEL_TOGGLE = 1 << 8,
|
||||
/* Menu socket should be drawn expanded instead of as drop-down menu. */
|
||||
NODE_INTERFACE_SOCKET_MENU_EXPANDED = 1 << 9,
|
||||
/**
|
||||
* Indicates that drawing code may decide not to draw the label if that would result in a
|
||||
* cleaner UI.
|
||||
*/
|
||||
NODE_INTERFACE_SOCKET_OPTIONAL_LABEL = 1 << 10,
|
||||
} NodeTreeInterfaceSocketFlag;
|
||||
ENUM_OPERATORS(NodeTreeInterfaceSocketFlag, NODE_INTERFACE_SOCKET_MENU_EXPANDED);
|
||||
ENUM_OPERATORS(NodeTreeInterfaceSocketFlag, NODE_INTERFACE_SOCKET_OPTIONAL_LABEL);
|
||||
|
||||
typedef enum NodeSocketInterfaceStructureType {
|
||||
NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_AUTO = 0,
|
||||
|
||||
@@ -1205,6 +1205,16 @@ static void rna_def_node_interface_socket(BlenderRNA *brna)
|
||||
prop, "Menu Expanded", "Draw the menu socket as an expanded drop-down menu");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeTreeInterfaceItem_update");
|
||||
|
||||
prop = RNA_def_property(srna, "optional_label", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, nullptr, "flag", NODE_INTERFACE_SOCKET_OPTIONAL_LABEL);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Optional Label",
|
||||
"Indicate that the label of this socket is not necessary to understand its meaning. This "
|
||||
"may result in the label being skipped in some cases");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeTreeInterfaceItem_update");
|
||||
|
||||
prop = RNA_def_property(srna, "attribute_domain", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items);
|
||||
RNA_def_property_enum_funcs(
|
||||
|
||||
@@ -393,6 +393,7 @@ static BaseSocketDeclarationBuilder &build_interface_socket_declaration(
|
||||
decl->hide_value(io_socket.flag & NODE_INTERFACE_SOCKET_HIDE_VALUE);
|
||||
decl->compact(io_socket.flag & NODE_INTERFACE_SOCKET_COMPACT);
|
||||
decl->panel_toggle(io_socket.flag & NODE_INTERFACE_SOCKET_PANEL_TOGGLE);
|
||||
decl->optional_label(io_socket.flag & NODE_INTERFACE_SOCKET_OPTIONAL_LABEL);
|
||||
decl->default_input_type(NodeDefaultInputType(io_socket.default_input));
|
||||
if (structure_type) {
|
||||
decl->structure_type(*structure_type);
|
||||
|
||||
Reference in New Issue
Block a user