-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How to notify dragdrop source event once in imgui loop ? #5910
Comments
It's not clear from your description what the issue is.
Please create a minimal repro that we can copy+paste into one of the example apps. |
SetDragDropPayload returns true whenever I drag up the source widget, So It will notify event many times, if I don't drop the source widget. I want to let it notify event once during the time I drag up the widget. The image below shows what problem I met when using event system : drag up many times and drop once. |
Oh, sorry. I misremembered some of the details of how I don't think there's a super clean way to do this without poking at internals, the easiest solution would be to keep track of some extra state to identify if the payload was accepted during the previous frame when static bool lastFrameWasAccepted = false; // You probably don't want to use a static local in your actual app, this is just an example.)
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None))
{
auto data = (u8)CastRef(this);
lastFrameWasAccepted = ImGui::SetDragDropPayload("imgui", &data, sizeof(data), ImGuiCond_None);
ImGui::Text(m_IconText.getValue().c_str());
ImGui::EndDragDropSource();
}
else if (lastFrameWasAccepted)
{
lastFrameWasAccepted = false;
onDragDroped(Event{ EventType::GUI_DRAG_UP, (u8)CastRef(this) });
} |
I'll try it later, thanks. |
It is unclear what you are trying to achieve with your GUI_DRAG_UP event. When it is supposed to be triggered, what is the purpose of it? What do you want to happen if you drag a payload over one destination, then move over another? Two notes:
So I suspect in your case this may be enough: if (ImGui::GetDragDropPayload() == NULL)
{
ImGui::SetDragDropPayload("imgui", &data, sizeof(data), ImGuiCond_Once);
onDragDroped(Event{ EventType::GUI_DRAG_UP, (u8)CastRef(this) });
} Note of this checks if the payload is being "accepted" but if you were to be interested in that information, your GUI_DRAG_UP/GUI_DRAG_DOWN protocol is not going to be enough. |
My interpretation is they want their event to fire once when the payload is dropped. IE: The payload was accepted, a call somewhere to I do agree though, it's not totally clear.
Maybe I'm missing something, but
My understanding is this condition can never be true within a |
Correct.
Also correct, but I think this constitute a bug of |
Pushed fix for |
I can't thank you too much, thanks every one. It runs well. (one drag up, one drop down) 20221124034606.mp4 |
…before payload is submitted. (ocornut#5910, ocornut#143) + Added test "widgets_dragdrop_new_payloads" in Test Suite.
Just a Question. I want to add dragdrop source event into my message system. But i can't do this, as imgui would loop many times.
The code as below. Can anyone help?
The text was updated successfully, but these errors were encountered: