-
-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What should I do if I want a certain drag-and-drop object to be compatible with multiple types #2433
Comments
For drop callback to work, Even droppable, you can accept/discard data depend on your
|
import dearpygui.dearpygui as dpg
dpg.create_context()
def drag_cb(sender, app_data, user_data):
# sender is btn_drag
# app_data is btn_drag (value from drag_data)
# do some configure(drawing_item), animation
print(sender, app_data, user_data)
...
def drop_cb(sender, app_data, user_data):
# sender is group, app_data is btn_drag
dpg.move_item(app_data, parent=sender)
print(sender, app_data, user_data)
# user_data seem None all the time
# but this solve the None above:
target_drop_user_data = dpg.get_item_user_data(sender)
# Slot 3: mvDragPayload - drag_payload(parent=btn_drag...)
a_drag_payload_id = dpg.get_item_children(app_data, slot=3)[0]
print(target_drop_user_data, dpg.get_item_user_data(a_drag_payload_id))
with dpg.window():
with dpg.group(horizontal=True):
with dpg.group(width=300, drop_callback=drop_cb, payload_type="int", user_data="dropped group"):
dpg.add_text("Group left")
dpg.add_button(label="not drag this")
with dpg.child_window(width=300, height=300, drop_callback=drop_cb, payload_type="int", user_data="dropped child"):
dpg.add_text("Child right")
dpg.add_button(label="not drag this")
btn_drag = dpg.add_button(label="drag me to another group then drop", drag_callback=drag_cb)
with dpg.drag_payload(parent=btn_drag, drag_data=btn_drag, payload_type="int", user_data={btn_drag: "dragging/drop"}):
dpg.add_text("dragging a button")
# parent=btn_drag --> this playload will appear if dragged from the btn_drag
# drag_data=btn_drag --> btn_drag will be app_data in the above drag_cb and drop_cb
# payload_type="int" --> btn_drag is an int, specified in this playload and drop target - two group above
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.destroy_context() |
Thank you for your reply , I know that you can pass multiple types through user _ data and then judge them in a callback, But I don't think it's elegant, The same payload _ type for multiple items will have a yellow border that tells you it is draggable, The different payload _ type does not display at all |
Yes, judge |
OK, I see, thank you very much for your reply |
CODE
import dearpygui.dearpygui as dpg
import numpy as np
dpg.create_context()
dpg.create_viewport(title='DD', width=800, height=500)
with dpg.window(label='Drag&Drop Window', width=-1, height=-1):
with dpg.group(horizontal=True):
with dpg.group():
dpg.add_text(default_value='sources:')
dpg.add_input_int(label='freq', width=80, default_value=1, tag='freq')
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
What should I do if I want a certain drag-and-drop object to be compatible with multiple types?
There is also how to add drop_callback to drawlist, window, etc.
The text was updated successfully, but these errors were encountered: