Fix #111966: Node group panels too small when using "both" type sockets #112013

Merged
Lukas Tönne merged 1 commits from LukasTonne/blender:fix-both-socket-panel-size into main 2023-09-06 13:29:55 +02:00
3 changed files with 34 additions and 8 deletions

View File

@ -495,8 +495,8 @@ static void node_update_basis_from_declaration(
* the stack. Each panel expects a number of items to be added, after which the panel is removed
* from the stack again. */
struct PanelUpdate {
/* How many items still to add. */
int remaining_items;
/* How many declarations still to add. */
int remaining_decls;
/* True if the panel or its parent is collapsed. */
bool is_collapsed;
/* Location data, needed to finalize the panel when all items have been added. */
@ -508,8 +508,8 @@ static void node_update_basis_from_declaration(
bool is_parent_collapsed = false;
if (PanelUpdate *parent_update = panel_updates.is_empty() ? nullptr : &panel_updates.peek()) {
/* Adding an item to the parent panel, will be popped when reaching 0. */
BLI_assert(parent_update->remaining_items > 0);
--parent_update->remaining_items;
BLI_assert(parent_update->remaining_decls > 0);
--parent_update->remaining_decls;
is_parent_collapsed = parent_update->is_collapsed;
}
@ -531,7 +531,7 @@ static void node_update_basis_from_declaration(
current_panel_state->flag, is_parent_collapsed, NODE_PANEL_PARENT_COLLAPSED);
/* New top panel is collapsed if self or parent is collapsed. */
const bool is_collapsed = is_parent_collapsed || current_panel_state->is_collapsed();
panel_updates.push({panel_decl->num_items, is_collapsed, current_panel_runtime});
panel_updates.push({panel_decl->num_child_decls, is_collapsed, current_panel_runtime});
/* Round the socket location to stop it from jiggling. */
current_panel_runtime->location_y = round(locy + NODE_DYS);
@ -578,7 +578,7 @@ static void node_update_basis_from_declaration(
/* Close parent panels that have all items added. */
while (!panel_updates.is_empty()) {
PanelUpdate &top_panel = panel_updates.peek();
if (top_panel.remaining_items > 0) {
if (top_panel.remaining_decls > 0) {
/* Incomplete panel, continue adding items. */
break;
}

View File

@ -497,7 +497,7 @@ class PanelDeclaration : public ItemDeclaration {
std::string description;
std::string translation_context;
bool default_collapsed = false;
int num_items = 0;
int num_child_decls = 0;
private:
friend NodeDeclarationBuilder;

View File

@ -315,6 +315,32 @@ static SocketDeclarationPtr declaration_for_interface_socket(
return dst;
}
/* Socket items can be both input and output, generating 2 declarations for 1 item. Count the
* actual declarations generated by panel content to get the true size for UI drawing. */
static int count_panel_declaration_children(const bNodeTreeInterfacePanel &io_panel)
{
int num_child_decls = 0;
io_panel.foreach_item([&](const bNodeTreeInterfaceItem &item) {
switch (item.item_type) {
case NODE_INTERFACE_PANEL:
num_child_decls++;
break;
case NODE_INTERFACE_SOCKET:
const bNodeTreeInterfaceSocket &socket =
reinterpret_cast<const bNodeTreeInterfaceSocket &>(item);
if (socket.flag & NODE_INTERFACE_SOCKET_INPUT) {
num_child_decls++;
}
if (socket.flag & NODE_INTERFACE_SOCKET_OUTPUT) {
num_child_decls++;
}
break;
}
return true;
});
return num_child_decls;
}
static PanelDeclarationPtr declaration_for_interface_panel(const bNodeTree & /*ntree*/,
const bNodeTreeInterfacePanel &io_panel)
{
@ -327,7 +353,7 @@ static PanelDeclarationPtr declaration_for_interface_panel(const bNodeTree & /*n
dst->name = io_panel.name ? io_panel.name : "";
dst->description = io_panel.description ? io_panel.description : "";
dst->default_collapsed = (io_panel.flag & NODE_INTERFACE_PANEL_DEFAULT_CLOSED);
dst->num_items = io_panel.items_num;
dst->num_child_decls = count_panel_declaration_children(io_panel);
return dst;
}