Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceAllowNullID doesn't lose tooltip when scrolling. (#143)

Reduced amount of self critical commentary since it'll appear like a hack for users but it isn't more a hack than many other things.
This commit is contained in:
ocornut 2021-11-10 19:17:01 +01:00
parent f8a806ad9f
commit 2c29e391dd
2 changed files with 6 additions and 4 deletions

View File

@ -67,6 +67,8 @@ Other Changes:
by the clipper to display. (#3841) by the clipper to display. (#3841)
- Clipper: fixed content height declaration slightly mismatching the value of when not using a clipper. - Clipper: fixed content height declaration slightly mismatching the value of when not using a clipper.
(an additional ItemSpacing.y was declared, affecting scrollbar range). (an additional ItemSpacing.y was declared, affecting scrollbar range).
- Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceAllowNullID doesn't lose
tooltip when scrolling. (#143)
- Backends: Vulkan: Call vkCmdSetScissor() at the end of render with a full-viewport to reduce - Backends: Vulkan: Call vkCmdSetScissor() at the end of render with a full-viewport to reduce
likehood of issues with people using VK_DYNAMIC_STATE_SCISSOR in their app without calling likehood of issues with people using VK_DYNAMIC_STATE_SCISSOR in their app without calling
vkCmdSetScissor() explicitly every frame. (#4644) vkCmdSetScissor() explicitly every frame. (#4644)

View File

@ -3121,7 +3121,7 @@ ImGuiID ImGuiWindow::GetIDNoKeepAlive(int n)
ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs) ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs)
{ {
ImGuiID seed = IDStack.back(); ImGuiID seed = IDStack.back();
const int r_rel[4] = { (int)(r_abs.Min.x - Pos.x), (int)(r_abs.Min.y - Pos.y), (int)(r_abs.Max.x - Pos.x), (int)(r_abs.Max.y - Pos.y) }; ImRect r_rel = ImGui::WindowRectAbsToRel(this, r_abs);
ImGuiID id = ImHashData(&r_rel, sizeof(r_rel), seed); ImGuiID id = ImHashData(&r_rel, sizeof(r_rel), seed);
ImGui::KeepAliveID(id); ImGui::KeepAliveID(id);
return id; return id;
@ -10276,16 +10276,16 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
return false; return false;
// If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to: // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
// A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag, C) Swallow your programmer pride. // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag.
if (!(flags & ImGuiDragDropFlags_SourceAllowNullID)) if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
{ {
IM_ASSERT(0); IM_ASSERT(0);
return false; return false;
} }
// Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image() // Magic fallback to handle items with no assigned ID, e.g. Text(), Image()
// We build a throwaway ID based on current ID stack + relative AABB of items in window. // We build a throwaway ID based on current ID stack + relative AABB of items in window.
// THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled. // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING/RESIZINGG OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
// We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive. // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
// Rely on keeping other window->LastItemXXX fields intact. // Rely on keeping other window->LastItemXXX fields intact.
source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect); source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect);