MCPcopy Create free account
hub / github.com/RenderKit/embree / BeginDragDropSource

Method BeginDragDropSource

tutorials/common/imgui/imgui.cpp:11751–11861  ·  view source on GitHub ↗

When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource() If the item has an identifier: - This assume/require the item to be activated (typically via ButtonBehavior). - Therefore if you want to use this with a mouse button other than left mouse button, it is up to the item itself to activate with an

Source from the content-addressed store, hash-verified

11749// If the item has no identifier:
11750// - Currently always assume left mouse button.
11751bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
11752{
11753 ImGuiContext& g = *GImGui;
11754 ImGuiWindow* window = g.CurrentWindow;
11755
11756 // FIXME-DRAGDROP: While in the common-most "drag from non-zero active id" case we can tell the mouse button,
11757 // in both SourceExtern and id==0 cases we may requires something else (explicit flags or some heuristic).
11758 ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
11759
11760 bool source_drag_active = false;
11761 ImGuiID source_id = 0;
11762 ImGuiID source_parent_id = 0;
11763 if (!(flags & ImGuiDragDropFlags_SourceExtern))
11764 {
11765 source_id = g.LastItemData.ID;
11766 if (source_id != 0)
11767 {
11768 // Common path: items with ID
11769 if (g.ActiveId != source_id)
11770 return false;
11771 if (g.ActiveIdMouseButton != -1)
11772 mouse_button = g.ActiveIdMouseButton;
11773 if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
11774 return false;
11775 g.ActiveIdAllowOverlap = false;
11776 }
11777 else
11778 {
11779 // Uncommon path: items without ID
11780 if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
11781 return false;
11782 if ((g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
11783 return false;
11784
11785 // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
11786 // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag.
11787 if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
11788 {
11789 IM_ASSERT(0);
11790 return false;
11791 }
11792
11793 // Magic fallback to handle items with no assigned ID, e.g. Text(), Image()
11794 // We build a throwaway ID based on current ID stack + relative AABB of items in window.
11795 // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING/RESIZINGG OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
11796 // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
11797 // Rely on keeping other window->LastItemXXX fields intact.
11798 source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect);
11799 KeepAliveID(source_id);
11800 bool is_hovered = ItemHoverable(g.LastItemData.Rect, source_id);
11801 if (is_hovered && g.IO.MouseClicked[mouse_button])
11802 {
11803 SetActiveID(source_id, window);
11804 FocusWindow(window);
11805 }
11806 if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker.
11807 g.ActiveIdAllowOverlap = is_hovered;
11808 }

Callers

nothing calls this directly

Calls 2

ImHashStrFunction · 0.85
GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected