Skip to content
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

Drag & Drop with other mouse button than LMB #3885

Closed
dgregorius opened this issue Mar 5, 2021 · 3 comments
Closed

Drag & Drop with other mouse button than LMB #3885

dgregorius opened this issue Mar 5, 2021 · 3 comments
Labels
drag drop drag and drop inputs

Comments

@dgregorius
Copy link

dgregorius commented Mar 5, 2021

Version/Branch of Dear ImGui:

Version: 1.82 WIP
Branch: Docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: VS 2019
Operating System: Windows 10

My Issue/Question:

I am implementing to move bones inside the hierarchy via drag & drop. In Maya this happens by dragging with the middle mouse button and I like to follow the established UI rules from there. I noticed that ImGui is hard coded to use the LMB. Can we make the desired mouse button optional?

@ocornut ocornut added the drag drop drag and drop label Mar 5, 2021
@rokups
Copy link
Contributor

rokups commented Mar 8, 2021

Since you may be waiting for a response, i will explain this a bit. I took a look at BeginDragDropSource() and it has a hint of attempt to support arbitrary buttons. However it is not that simple. Drag operation is started when BeginDragDropSource() call appears after active item, and items are activated by left mouse button only. Extending this functionality to other mouse buttons will definitely have other side effects and will not be trivial to implement. I also do not see any possible workaround. Unfortunately you will have to stick with left mouse button for foreseeable future.

@ocornut ocornut added the inputs label Mar 8, 2021
@ocornut
Copy link
Owner

ocornut commented Mar 8, 2021

As hinted above there's are two sides to this.

(A.1) The first is that BeginDragDropSource() relies on ActiveID and most existing widgets only react to LMB only. In 1.78 we started exposing flags to allow using InvisibleButton() as a building-block for multi-buttons widgets. However it would seem tedious if somehow every widgets would need to be modified with adhoc flags. I presume in your case you care about a TreeNode?

(A.2)
Here's come the magic, this appears to works.... (but haven't been thoroughly tested)

// Regular button
ImGui::Button("Button");

// Extend to react middle and right mouse buttons.
ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGui::ButtonBehavior(window->DC.LastItemRect, window->DC.LastItemId, NULL, NULL, 
 ImGuiButtonFlags_MouseButtonMiddle | ImGuiButtonFlags_MouseButtonRight);

(B)
But BeginDragDropSource() currently hard-coded for LMB.
The reasons the drag cares about mouse buttons at all are:

  • it needs to check on drag threshold of mouse movement (rather than just ActiveId)
  • the drag payload and associated interaction can live outside the scope and life expectancy of the drag source.

Since drag and drop was added, active buttons now record the mouse button that activated them so we should be able to link those two now...

ocornut added a commit that referenced this issue Mar 8, 2021
…mouse button (#1637, #3885)

As long as the item has an ID (for ID-less items will add new functionalities later.
Amend 2c3c512
@ocornut
Copy link
Owner

ocornut commented Mar 8, 2021

Pushed 954b06a which now works with it:

ImGui::Button("Button");
ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGui::ButtonBehavior(window->DC.LastItemRect, window->DC.LastItemId, NULL, NULL, ImGuiButtonFlags_MouseButtonMiddle | ImGuiButtonFlags_MouseButtonRight);

if (ImGui::BeginDragDropSource())
{
    ImGui::Text("dragged button");
    ImGui::EndDragDropSource();
}

I think down the line we will need to explicit mouse button choice/mask in ImGuiDragDropFlags but for items with ID we can detect it, so that should solve the issue.

(cc same issue #1637)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drag drop drag and drop inputs
Projects
None yet
Development

No branches or pull requests

3 participants