1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-12 00:14:20 +00:00

Drag and Drop: implement simple item reordering API.

This commit is contained in:
Rokas Kupstys 2021-10-11 15:52:01 +03:00
parent d768b8c812
commit 713adaa4e2
4 changed files with 111 additions and 0 deletions

View file

@ -11259,6 +11259,55 @@ void ImGui::EndDragDropTarget()
g.DragDropWithinTarget = false;
}
//-----------------------------------------------------------------------------
// [SECTION] REORDERING
//-----------------------------------------------------------------------------
int ImGui::ItemReorder(ImGuiID id, bool vertical)
{
ImGuiContext& g = *GImGui;
if (!g.IO.MouseDown[0] && g.LastItemData.ID == g.ActiveIdPreviousFrame)
{
g.ReorderScopeId = 0;
g.ReorderResult = 0;
}
else if (g.ActiveId && g.ActiveId == g.LastItemData.ID)
{
g.ActiveIdAllowOverlap = true; // Enable IsItemHovered() while current item is active
g.ReorderScopeId = id;
g.ReorderItemRect = g.LastItemData.Rect;
if (g.ReorderResult != 0)
{
int result = g.ReorderResult;
g.ReorderScopeId = 0;
g.ReorderResult = 0;
return result;
}
}
else if (g.IO.MouseDown[0] && IsItemHovered() && g.ReorderScopeId == id)
{
ImGuiAxis axis = (ImGuiAxis)vertical;
if (g.IO.MousePos[axis] > g.ReorderItemRect.Max[axis])
g.ReorderResult = +1;
else if (g.IO.MousePos[axis] < g.ReorderItemRect.Min[axis])
g.ReorderResult = -1;
}
return 0;
}
int ImGui::ItemReorder(const char* id, bool vertical)
{
ImGuiContext& g = *GImGui;
return ItemReorder(g.CurrentWindow->GetID(id), vertical);
}
int ImGui::ItemReorder(bool vertical)
{
ImGuiContext& g = *GImGui;
return ItemReorder(g.CurrentWindow->IDStack.back(), vertical);
}
//-----------------------------------------------------------------------------
// [SECTION] LOGGING/CAPTURING
//-----------------------------------------------------------------------------