hoffstadt / hoffstadt/DearPyGui
user_data parameter for bind_item_handler_registry?
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
I am creating a lot of tree nodes dynamically, and binding the same item handler registry to each. I cannot figure out how to extract from within the callback function which tree node was clicked - the callback receives only the tag of the handler, no information about the item.
**Describe the solution you'd like**
It would be useful to be able to do e.g.
node_handlers = dpg.add_item_handler_registry()
dpg.add_item_clicked_handler(parent=node_handlers, callback=callback)
for i in range(5):
with dpg.tree_node(label=f"node {i}") as n:
dpg.bind_item_handler_registry(n, node_handlers, user_data=n)
and have the user_data given to the callbacks; or always add extra arguments indicating the clicked item to the callbacks calls.
**Describe alternatives you've considered**
- I see that add_item_clicked_handler accepts user_data; but I have failed to figure out a method of providing variable item tags there.
- Tried instead checking is_item_toggled_open for every tree node. This is only true for the last toggled-open node (which seems like a bug. Is that expected behaviour?), so it doesn't help me find out which node has been _closed_.
- Am I supposed to create a separate item handler registry for every one of my (potentially very numerous) tree nodes? I suppose that might work, but considering every tree node is supposed to react the same way to a click, that seems excessive.
- Edit: _Finally_ found a workaround: Put a group inside every tree node, check for visibility of the groups upon click on any tree node. But still, I remain confused as to how the item handlers are supposed to be used when applied to more than one item.
**Additional context**
For background: I'm trying to implement a file explorer, where directories are displayed as tree nodes. I managed to include an open or closed folder icon in the label by replacing two characters in my font file by those icons; now I just need to switch between them when a tree node is opened or closed... Which seemed like the easiest part but somehow is not.
Contributor guide
Assessment
This issue has not been assessed yet.