Skip to content

Commit

Permalink
Add a simple item reordering demo based on ocornut#143 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
rokups committed Oct 2, 2019
1 parent 24790c7 commit f0630b8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,32 @@ static void ShowDemoWindowWidgets()
}

{
ImGui::BulletText("Drag and drop to reorder items");
ImGui::BulletText("Drag to reorder items (simple)");
ImGui::Indent();

// Simple reordering
static const char* item_names[] = {"Item One", "Item Two", "Item Three", "Item Four", "Item Five"};
for (int n = 0; n < IM_ARRAYSIZE(item_names); n++)
{
const char* item = item_names[n];
ImGui::Selectable(item);

if (ImGui::IsItemActive() && !ImGui::IsItemHovered())
{
int n_next = n + (ImGui::GetMouseDragDelta(0).y < 0.f ? -1 : 1);
if (n_next >= 0 && n_next < IM_ARRAYSIZE(item_names))
{
item_names[n] = item_names[n_next];
item_names[n_next] = item;
ImGui::ResetMouseDragDelta();
}
}
}
ImGui::Unindent();
}

{
ImGui::BulletText("Drag to reorder items (complex)");
ImGui::Indent();

static bool horizontalList = false;
Expand Down

0 comments on commit f0630b8

Please sign in to comment.