hoffstadt / hoffstadt/DearPyGui

Nodes with the first attribute "empty" expand infinitely in width

Open
#2,444 4 comments 1 reaction 0 assignees View on GitHub
state: pending type: bug
Dominant language
C++
Stars
15.6k
Forks
783
PR merge metrics
No merged PRs in 30d

Description

## Version of Dear PyGui

Version: 2.0.0
Operating System: Windows 11

## My Issue/Question

In DearPyGui 2.0, nodes exhibit unintended width expansion under the following conditions:

The node has an empty first attribute (either input/output/static) or the node contains an empty nested attribute (with no nested child, e.g., no text). This issue causes the node to expand slightly on each render.

This behavior is observed on DPG 2.0 but is not present in DPG 1.8.0, where nodes work as expected.

Bug occurs:
1. Node with an empty input and an empty output attribute.
2. Node with an empty input and a filled output attribute.

Works correctly:
1. Node with a filled input and a filled output attribute.
2. Node with a filled input and an empty output attribute.

The bug seems to come from the automatic sizing mechanism, which fails to determine the node's width correctly if the first child attribute is empty.

Adding a ```time.sleep(0.25)``` to slow the framerate confirms that the node extend progressively on each render instead of being created with an infinite width.

Adding an empty string to the first attribute can mitigate the issue, but this increases the node's height slightly.

## To Reproduce

Steps to reproduce the behavior:
1. Create a node_editor
6. Add an empty node with either
A. ```dpg.add_node()```
B. ```with dpg.node():
pass```
7. Or add a node with the FIRST attribute empty :
A. ```with dpg.node():
dpg.add_node_attribute(attribute_type=dpg.mvNode_Attr_Output)```
B. ```with dpg.node():
with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Output) :
pass```

## Expected behavior

The node should have a fixed width that scale to the size of the node label (if the node does not have children) or the largest attribute (if the node have one or more children).

## Screenshot

![BuggedNodeEditor](https://github.com/user-attachments/assets/b2700c90-fc9e-4f84-bc86-7b549448cd08)

## Standalone, minimal, complete and verifiable example

```python
import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(title="Expanding node bug", width=1280, height=720)

with dpg.window(label="Node Editor", width=1280, height=720):
with dpg.node_editor(tag="node_editor", minimap=True, minimap_location=dpg.mvNodeMiniMap_Location_BottomRight):

dpg.add_node(label="Bugged node 1", pos=[100, 0])

with dpg.node(label="Bugged node 2", pos=[100, 50]):
pass

with dpg.node(label="Bugged node 3", pos=[100, 100]):
dpg.add_node_attribute(label="Input", attribute_type=dpg.mvNode_Attr_Output)

with dpg.node(label="Bugged node 4", pos=[100, 150]):
with dpg.node_attribute(label="Test", attribute_type=dpg.mvNode_Attr_Output) :
pass

with dpg.node(label="Working node 1", pos=[100, 250]):
with dpg.node_attribute(label="Test", attribute_type=dpg.mvNode_Attr_Output) :
dpg.add_text("This is a working node if the attribute have a child")

with dpg.node(label="Bugged node fixed with empty string", pos=[100, 325]):
with dpg.node_attribute(label="Test", attribute_type=dpg.mvNode_Attr_Output) :
dpg.add_text("")

with dpg.node(label="Bugged node 5", pos=[100, 450]):
dpg.add_node_attribute(label="Input", attribute_type=dpg.mvNode_Attr_Input)

with dpg.node_attribute(label="Test", attribute_type=dpg.mvNode_Attr_Output) :
dpg.add_text("If the first attribute is empty the node will be bugged")

with dpg.node(label="Bugged node 5 fixed", pos=[100, 525]):
with dpg.node_attribute(label="Test", attribute_type=dpg.mvNode_Attr_Output) :
dpg.add_text("If the first attribute have a child the node will be working correctly")

dpg.add_node_attribute(label="Input", attribute_type=dpg.mvNode_Attr_Input)

dpg.setup_dearpygui()
dpg.show_viewport()

import time

while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
time.sleep(0.25)

dpg.destroy_context()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.