|
|
|
@ -1506,24 +1506,21 @@ static void ShowDemoWindowWidgets()
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("Drag and Drop"))
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::TreeNode("Drag and drop in standard widgets"))
|
|
|
|
|
{
|
|
|
|
|
// ColorEdit widgets automatically act as drag source and drag target.
|
|
|
|
|
// They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets
|
|
|
|
|
// to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo.
|
|
|
|
|
ImGui::BulletText("Drag and drop in standard widgets");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
HelpMarker("You can drag from the colored squares.");
|
|
|
|
|
ImGui::Indent();
|
|
|
|
|
static float col1[3] = { 1.0f, 0.0f, 0.2f };
|
|
|
|
|
static float col2[4] = { 0.4f, 0.7f, 0.0f, 0.5f };
|
|
|
|
|
ImGui::ColorEdit3("color 1", col1);
|
|
|
|
|
ImGui::ColorEdit4("color 2", col2);
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("Drag and drop to copy/swap items"))
|
|
|
|
|
{
|
|
|
|
|
ImGui::BulletText("Drag and drop to copy/swap items");
|
|
|
|
|
ImGui::Indent();
|
|
|
|
|
enum Mode
|
|
|
|
|
{
|
|
|
|
|
Mode_Copy,
|
|
|
|
@ -1577,7 +1574,31 @@ static void ShowDemoWindowWidgets()
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("Drag to reorder items (simple)"))
|
|
|
|
|
{
|
|
|
|
|
// Simple reordering
|
|
|
|
|
HelpMarker("We don't use the drag and drop api at all here! Instead we query when the item is held but not hovered, and order items accordingly.");
|
|
|
|
|
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::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|