Best way to implement draggable nodes. #3848
techmindful
announced in
Old/Archived discussions
Replies: 1 comment
-
Try something like this: static ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetCursorPos(pos);
ImGui::Button("Draggable button");
if (ImGui::IsItemActive())
pos += ImGui::GetIO().MouseDelta; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Dear ImGui through a Haskell binding library. I need to draw small groups of widgets, or nodes. A node can be dragged around to any position with mouse. A node can have any kinds of widgets inside, like texts, images, combos, and so on.
I found a handful of node editor libraries for Dear ImGui. Since I'm using Haskell bindings, I can't use these libraries. But seeing many people writing their own libraries for this seems to tell me that it isn't too hard a task. I do want to implement my nodes with the proper Dear ImGui way.
For the border of a node, should I just draw a custom rectangle that surrounds the widgets, or is there a Dear ImGui function for drawing a border around something?
For the dragging behavior, should I just listen for mouse press event, calculate if the cursor was inside the rectangular bound of a node, and if that's true then make that node follow the cursor, until mouse release? Or are there Dear ImGui functions for dragging something? Note that this is different from dragging something and dropping to a target.
Beta Was this translation helpful? Give feedback.
All reactions