MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / BeginDragDropSource

Method BeginDragDropSource

KBotExt/imgui/imgui.cpp:12320–12429  ·  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

12318// If the item has no identifier:
12319// - Currently always assume left mouse button.
12320bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
12321{
12322 ImGuiContext& g = *GImGui;
12323 ImGuiWindow* window = g.CurrentWindow;
12324
12325 // FIXME-DRAGDROP: While in the common-most "drag from non-zero active id" case we can tell the mouse button,
12326 // in both SourceExtern and id==0 cases we may requires something else (explicit flags or some heuristic).
12327 ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
12328
12329 bool source_drag_active = false;
12330 ImGuiID source_id = 0;
12331 ImGuiID source_parent_id = 0;
12332 if (!(flags & ImGuiDragDropFlags_SourceExtern))
12333 {
12334 source_id = g.LastItemData.ID;
12335 if (source_id != 0)
12336 {
12337 // Common path: items with ID
12338 if (g.ActiveId != source_id)
12339 return false;
12340 if (g.ActiveIdMouseButton != -1)
12341 mouse_button = g.ActiveIdMouseButton;
12342 if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
12343 return false;
12344 g.ActiveIdAllowOverlap = false;
12345 }
12346 else
12347 {
12348 // Uncommon path: items without ID
12349 if (g.IO.MouseDown[mouse_button] == false || window->SkipItems)
12350 return false;
12351 if ((g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
12352 return false;
12353
12354 // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
12355 // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag.
12356 if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
12357 {
12358 IM_ASSERT(0);
12359 return false;
12360 }
12361
12362 // Magic fallback to handle items with no assigned ID, e.g. Text(), Image()
12363 // We build a throwaway ID based on current ID stack + relative AABB of items in window.
12364 // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING/RESIZINGG OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
12365 // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
12366 // Rely on keeping other window->LastItemXXX fields intact.
12367 source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect);
12368 KeepAliveID(source_id);
12369 bool is_hovered = ItemHoverable(g.LastItemData.Rect, source_id, g.LastItemData.InFlags);
12370 if (is_hovered && g.IO.MouseClicked[mouse_button])
12371 {
12372 SetActiveID(source_id, window);
12373 FocusWindow(window);
12374 }
12375 if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker.
12376 g.ActiveIdAllowOverlap = is_hovered;
12377 }

Callers

nothing calls this directly

Calls 2

ImHashStrFunction · 0.85
GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected